PC Review


Reply
Thread Tools Rate Thread

How can I have [DefaultValue(Environment.NewLine)] in C#?

 
 
Leon_Amirreza
Guest
Posts: n/a
 
      29th Dec 2009
hi
How can I have this in c# (or any equivalent code that does the same thing):

[DefaultValue(Environment.NewLine)]

or

[DefaultValue(f())]

f() is a function that returns a value.

 
Reply With Quote
 
 
 
 
Jesse Houwing
Guest
Posts: n/a
 
      29th Dec 2009
* Leon_Amirreza wrote, On 29-12-2009 20:24:
> hi
> How can I have this in c# (or any equivalent code that does the same
> thing):
>
> [DefaultValue(Environment.NewLine)]
>
> or
>
> [DefaultValue(f())]
>
> f() is a function that returns a value.


You cannot.

--
Jesse Houwing
jesse.houwing at sogeti.nl
 
Reply With Quote
 
 
 
 
Family Tree Mike
Guest
Posts: n/a
 
      29th Dec 2009
On 12/29/2009 2:24 PM, Leon_Amirreza wrote:
> hi
> How can I have this in c# (or any equivalent code that does the same
> thing):
>
> [DefaultValue(Environment.NewLine)]
>
> or
>
> [DefaultValue(f())]
>
> f() is a function that returns a value.


You can set those values for the properties in the constructor.

--
Mike
 
Reply With Quote
 
Mick Doherty
Guest
Posts: n/a
 
      31st Dec 2009
The DefaultValueAttribute basically just determines a value which does not
need to be serialized and which will be set upon a reset command. It does
not set the initial value, this needs to be done by yourself.

To do this with a non fixed value you should define ShouldSerialize* and
Reset* methods instead, where * is the property name.

i.e.
-- 8< --------------------------------------------------

private string someProperty = Environment.NewLine;
public string SomeProperty
{
get{ return someProperty; }
set{ someProperty = value; }
}
private bool ShouldSerializeSomeProperty()
{
return !SomeProperty.Equals(Environment.NewLine);
}
private void ResetSomeProperty()
{
SomeProperty = Environment.NewLine;
}

-- 8< --------------------------------------------------

--
Mick Doherty
http://dotnetrix.co.uk/nothing.htm

"Leon_Amirreza" <(E-Mail Removed)> wrote in message
news:24DA2D74-4053-4774-B7A0-(E-Mail Removed)...
> hi
> How can I have this in c# (or any equivalent code that does the same
> thing):
>
> [DefaultValue(Environment.NewLine)]
>
> or
>
> [DefaultValue(f())]
>
> f() is a function that returns a value.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If you have come to this website then you have made a right decesion.I have a plan for everyone to earn 300$ extra per month. Rakesh Aitla Microsoft C# .NET 0 29th Oct 2009 06:49 AM
Can 2 columns of a DataGrid have a single heading OR can I have two controls in 1 column? mark4asp Microsoft ASP .NET 2 11th Nov 2006 03:13 AM
Re: i deleted Symantec shared folder and stuff doesn't work duh! do i have to reinstall xp to fix this; since my XP is an upgrade from ME, do i have to reinstall ME then upgrade again? i admit to being a computer dope, can you help me? Darryl Windows XP Help 0 12th Feb 2004 06:31 PM
Do have have to have Win XP or above to see video with Windows Messenger 5.0? John Jordan Windows XP Messenger 0 16th Sep 2003 03:22 PM
I have the same problem that you have. I have no clue. steve Microsoft Outlook 0 26th Aug 2003 10:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:35 AM.