473,395 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Localizing attributes in properties

I have placed text within a resouce file.

The class has a reference to a Resource Manager LocRM created in the
constructor. I want to reference the text within the resource file when
declaring a property. See below.

[Description(this.LocRM.GetText("strTestCategoryID" )),
Category(TestCaseStrings.strLabelDescription),
DefaultValueAttribute(TestingCategories.TestingCat egory.Miscellaneous)]
public virtual TestingCategories.TestingCategory TestCategory
{
get { return category; }
set { category = value; }
}

Obviously the compiler generates an error because it is expecting a constant
string where I'd like the this.LocRM("....").

How do I reference text within a resource file and place it in an attribute
above?

--
Steve
Nov 17 '05 #1
2 5240
Steve,
I don't have a link to an example handy of overriding it, my understanding
is you need to derive a new class from DescriptionAttribute & override the
Description Property, saving its value in the DescriptionValue property...

http://msdn.microsoft.com/library/de...valuetopic.asp

Hope this helps
Jay

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
|I have placed text within a resouce file.
|
| The class has a reference to a Resource Manager LocRM created in the
| constructor. I want to reference the text within the resource file when
| declaring a property. See below.
|
| [Description(this.LocRM.GetText("strTestCategoryID" )),
| Category(TestCaseStrings.strLabelDescription),
| DefaultValueAttribute(TestingCategories.TestingCat egory.Miscellaneous)]
| public virtual TestingCategories.TestingCategory TestCategory
| {
| get { return category; }
| set { category = value; }
| }
|
| Obviously the compiler generates an error because it is expecting a
constant
| string where I'd like the this.LocRM("....").
|
| How do I reference text within a resource file and place it in an
attribute
| above?
|
| --
| Steve
Nov 17 '05 #2
Jay,

I derived the class. See below. By calling MyDesciption in the property
it now correctly gets the string. Thanks so much.

/// <summary>
/// Overrides the DescriptionAttribute class in order to allow for
localization.
/// </summary>
public class MyDescriptionAttribute :
System.ComponentModel.DescriptionAttribute
{
public MyDescriptionAttribute(string attribute)
{
this.attribute = attribute;
}
#region Fields
protected CheckItResources LocRS = new CheckItResources();
protected string attribute;
#endregion // Fields

/// <summary>
/// Returns the localized string for the attribute.
/// </summary>
public override string Description
{
get
{
return this.DescriptionValue =
LocRS.GetText(this.attribute);
}
}
}

"Jay B. Harlow [MVP - Outlook]" wrote:
Steve,
I don't have a link to an example handy of overriding it, my understanding
is you need to derive a new class from DescriptionAttribute & override the
Description Property, saving its value in the DescriptionValue property...

http://msdn.microsoft.com/library/de...valuetopic.asp

Hope this helps
Jay

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
|I have placed text within a resouce file.
|
| The class has a reference to a Resource Manager LocRM created in the
| constructor. I want to reference the text within the resource file when
| declaring a property. See below.
|
| [Description(this.LocRM.GetText("strTestCategoryID" )),
| Category(TestCaseStrings.strLabelDescription),
| DefaultValueAttribute(TestingCategories.TestingCat egory.Miscellaneous)]
| public virtual TestingCategories.TestingCategory TestCategory
| {
| get { return category; }
| set { category = value; }
| }
|
| Obviously the compiler generates an error because it is expecting a
constant
| string where I'd like the this.LocRM("....").
|
| How do I reference text within a resource file and place it in an
attribute
| above?
|
| --
| Steve

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: beliavsky | last post by:
I have started using classes with Python and have a question about their use. In Python, 'attributes are all "public" and "virtual" in C++ terms; they're all accessible everywhere and all looked...
12
by: Pol Bawin | last post by:
Hi All, Did somebody already define attributes for numerical properties to define value : minima, maxima, a number of decimal, ...? This information would be useful to unify syntax Polo
2
by: S.Sigal | last post by:
Hello: I've seen code in some books for databinding that handles attaching Attributes to Properties during runtime...which is very close (but no cigar) to what I am looking for... The code...
13
by: Patrick * | last post by:
Reading a book on .ASP .NET I am getting a bit mixed up as to the difference between "property" and "attribute" as the terms don't seem to be used consistently in the book I am reading. Can anyone...
24
by: Nak | last post by:
Hi there, I have some inherited forms that I wish to make "localizable", unfortunately none of the items I wish to be "localizable" are actually being "localized". For example, I have a few of...
3
by: vivekian | last post by:
Hi , I am moving on from C++ to C# . Though have understood how attributes work , still dont understand what need do the fullfil ? Where should they be used ? What are their advantages ? some...
3
by: WT | last post by:
Hello, Using english version of vs 2005 to develop, my setup dialogs are all displayed in english, is there some way to have it displayed according the current culture using resources as we do for...
2
by: P4trykx | last post by:
Hello I'm want to add some custom attributes to WebControls using WebControl.Attributes.Add("abc","234"); So the html output will look like this, <input type="hidden" abc="123" /etc. I know...
3
by: Beorne | last post by:
In the classes I develop my attributes are always private and are exposed using properties. directly or to access the attributes using the properties? Does "wrapper" setter/getter properties...
0
by: =?Utf-8?B?U3VzaGlTZWFu?= | last post by:
I have question about pages localizability. So for example I have 3 pages on my site ================== main.aspx users.aspx products.aspx ================== I want make Localizing for them....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.