Setting defaultvalue of a property

R

RR

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??
 
C

Chris R. Timmons

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; }
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top