"RR" <ro************@freenet.de> wrote in
news:11*********************@f14g2000cwb.googlegro ups.com:
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??
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/