Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting defaultvalue of a property

0 views
Skip to first unread message

RR

unread,
Nov 5, 2005, 1:04:23 PM11/5/05
to
Hi,

I want to set the defaultvalue of a property in a class.

I know this is possible by the DefaultValue Attribute like this:

public class Test
{
public Test(){}

private string myProperty;

[DefaultValue("TestProperty")]
public string MyProperty
{
get{ return myProperty; }
set{ myProperty = value; }
}
}

I search for a possibility to set the default value for several
languages.

(the defaultvalueattribute class is sealed!!).

How can I implement this functionality??

Chris R. Timmons

unread,
Nov 5, 2005, 6:34:52 PM11/5/05
to
"RR" <robert....@freenet.de> wrote in
news:1131213863....@f14g2000cwb.googlegroups.com:

Robert,

Is this what you mean by "possibility to set the default value for
several languages"?

using System.Globalization;

...

private string myProperty = null;
public string MyProperty
{
get
{
// If myProperty has already been set to a value,
// return that value.
if (myProperty != null)
return myProperty;

// Otherwise, return a language-specific default value.
if (CultureInfo.CurrentUICulture.Name == "de-DE")
return "German text";
else if (CultureInfo.CurrentUICulture.Name == "en-EN")
return "English text";
else if (CultureInfo.CurrentUICulture.Name == "jp-JP")
return "Japanese text";
else
return "German text";
}

set { myProperty = value; }
}


--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

0 new messages