Home > Net >  Help: attribute items more language support (stuct)
Help: attribute items more language support (stuct)

Time:10-06

This is part of the code snippet

Public struct ItemSize
{
Public int Width {get; The set; }
Public int Height {get; The set; }

Public override string ToString ()
{
Return the Width. The ToString () + Height. The ToString ();
}
}
[GlobalizedCategory (" Basic "), PropertyOrder (3)]
[TypeConverter (typeof (ExpandableObjectConverter)))
Public ItemSize Size {get; The set; }

Such as images, according to the size of parent can now multilingual support, child, width, height can't, I don't know how to do?

CodePudding user response:

Could you give ItemSize GlobalizedCategoryAttribute properties listed, like:
 public struct ItemSize 
{
[GlobalizedCategory ("... ")]//support and specific name, would you like to read GlobalizedCategoryAttribute class,
Public int Width {get; The set; }

[GlobalizedCategory ("... ")]
Public int Height {get; The set; }
}

CodePudding user response:

If writing is dead, can write like this:
Public struct ItemSize
{
[Description (" width ")]
Public int Width {get; The set; }

[Description (" height ")]
Public int Height {get; The set; }
}

DescriptionAttribute likely GlobalizedCategoryAttribute inheritance, and to provide localized service category name,
Maybe you can also find whether have similar Globalized display Attribute, and inherit the DescriptionAttribute class,

CodePudding user response:

correction:

If writing is dead, can write like this:
Public struct ItemSize
{
[ DisplayName (" width ")]
Public int Width {get; The set; }

[DisplayName (" height ")]
Public int Height {get; The set; }
}

Probably GlobalizedCategoryAttribute inheritance DisplayName Attribute, and localization service for the category name,
Maybe you can also find whether have similar Globalized display Attribute, and inherit DisplayNameAttribute class,

CodePudding user response:

Is added on, don't know why:

Public struct ItemSize
{
[GlobalizedCategory (" Width ")]
Public int Width {get; The set; }
[GlobalizedCategory (" Height ")]
Public int Height {get; The set; }

Public override string ToString ()
{
Return the Width. The ToString () + Height. The ToString ();
}
}
[GlobalizedCategory (" Basic "), PropertyOrder (3)]
[TypeConverter (typeof (ExpandableObjectConverter)))
Public ItemSize Size {get; The set; }

CodePudding user response:

Ok, many thanks!

Now it is

Public struct ItemSize
{
[LocalizedStructAttribute (" Width ")]
Public int Width {get; The set; }
[LocalizedStructAttribute (" Height ")]
Public int Height {get; The set; }

Public override string ToString ()
{
Return the Width. The ToString () + Height. The ToString ();
}
}
[GlobalizedCategory (" Basic "), PropertyOrder (3)]
[TypeConverter (typeof (ExpandableObjectConverter)))
Public ItemSize Size {get; The set; }

CodePudding user response:

The class LocalizedStructAttribute: DisplayNameAttribute
{
Readonly ResourceManager ResourceManager;
Readonly string ResourceKey;

Public LocalizedStructAttribute (string resourceKey)
{
ResourceKey=ResourceKey;
}
Public override string DisplayName
{
The get
{
Return MainFormLanguageResource. The ResourceManager. Get string (ResourceKey);
}
}
}
  •  Tags:  
  • C#
  • Related