C# Enum htmlTextWriterStyle已修改,然后存储在另一个类似容器中
我正在搜索asp.net中所有可用的常用样式类型的数据源 而且C# Enum htmlTextWriterStyle已修改,然后存储在另一个类似容器中,c#,asp.net,list,class,enums,C#,Asp.net,List,Class,Enums,我正在搜索asp.net中所有可用的常用样式类型的数据源 而且htmlTextWriterStyle似乎已经满足了我的所有要求 如果有其他来源我可以使用,我很高兴知道 我试图实现的是将其值复制到任何其他类型的数据“容器” 这与enum不同,它更灵活,尽管它的值仍然可以通过 var test = name.value ; 喜欢 string MyElmWidth = htmlTextWriterStyle.width.ToString(); 可以像列表一样分配,这样我就可以通过foreach循
htmlTextWriterStyle
似乎已经满足了我的所有要求
如果有其他来源我可以使用,我很高兴知道
我试图实现的是将其值复制到任何其他类型的数据“容器”
这与enum不同,它更灵活,尽管它的值仍然可以通过
var test = name.value ;
喜欢
string MyElmWidth = htmlTextWriterStyle.width.ToString();
可以像列表一样分配,这样我就可以通过foreach循环动态填充它
(不必硬编码变量和值)
集合或类似以下代码中的列表:
public static List<string> EnumToStrLst<T>()
{
Array values = Enum.GetValues(typeof(T));
T[] result = (T[])values;
List<string> strlst = new List<string>();
foreach (var item in result)
{
string e = item.ToString();
strlst.Add(e);
}
return strlst;
}
反对
enumName.valueName
这没有经过测试,但是创建这样的包装器类怎么样:
public class HtmlTextWrapper {
//private members
private HtmlTextWriterStyle _htmlTextWriterStyle;
//public props same as the wrapped htmltextwriterstyle
public string BackgroundColor {
get
{
if (_htmlTextWriterStyle != null)
{
return _htmlTextWriterStyle.BackgroundColor;
}
}
set
{
if (_htmlTextWriterStyle != null)
{
this._htmlTextWriterStyle.BackgroundColor = value;
}
}
}
public string BackgroundImage {get;set; }
//....
//....
//construcor
public HtmlTextWrapper(HtmlTextWriterStyle other)
{
_htmlTextWriterStyle = other;
}
}
这样,您就可以使用这个包装类了,这是我在不放弃易访问性的情况下实现它的唯一方法 具有seald类和const字符串 从带有摘要的枚举元数据中复制它(仅使用一个类型声明进行了很好的布局)
你考虑过一个扩展方法吗?@AlexPeta没有真正体验过Ext方法。我很乐意采用任何优雅的方法,这将产生一个可以访问的数据,正如前面提到的,如果在错误的路径上,HtmlTextWriterStyle是一个枚举。我可以做其他的事情,但您的示例包括一种涉及到硬编码名称和值的方法,而不是像列表中那样直接生成它(至少填充是以编程方式完成的)虽然没有访问它的值/数据,但我能想到的最接近的方法是
字典
字典不会这样做,我想我只需要通过Seald类中的const string使它成为我自己的硬(编码)方式。
enumName.valueName
public class HtmlTextWrapper {
//private members
private HtmlTextWriterStyle _htmlTextWriterStyle;
//public props same as the wrapped htmltextwriterstyle
public string BackgroundColor {
get
{
if (_htmlTextWriterStyle != null)
{
return _htmlTextWriterStyle.BackgroundColor;
}
}
set
{
if (_htmlTextWriterStyle != null)
{
this._htmlTextWriterStyle.BackgroundColor = value;
}
}
}
public string BackgroundImage {get;set; }
//....
//....
//construcor
public HtmlTextWrapper(HtmlTextWriterStyle other)
{
_htmlTextWriterStyle = other;
}
}
namespace Style
{
public sealed class StlProps
{
// Summary:
// Specifies the HTML backgroundcolor style.
public const string BgColor = "BackgroundColor",
//
// Summary:
// Specifies the HTML backgroundimage style.
BackgroundImage = "BackgroundImage",
//
// Summary:
// Specifies the HTML bordercollapse style.
BorderCollapse = "BorderCollapse",
//
// Summary:
// Specifies the HTML bordercolor style.
BorderColor = "BorderColor",
//
// Summary:
// Specifies the HTML borderstyle style.
BorderStyle = "BorderStyle",
//
// Summary:
// Specifies the HTML borderwidth style.
BorderWidth = "BorderWidth",
//
// Summary:
// Specifies the HTML color style.
Color = "Color",
//
// Summary:
// Specifies the HTML fontfamily style.
FontFamily = "FontFamily",
//
// Summary:
// Specifies the HTML fontsize style.
FontSize = "FontSize",
//
// Summary:
// Specifies the HTML fontstyle style.
FontStyle = "FontStyle",
//
// Summary:
// Specifies the HTML fontheight style.
FontWeight = "FontWeight",
//
// Summary:
// Specifies the HTML height style.
Height = "Height",
//
// Summary:
// Specifies the HTML textdecoration style.
TextDecoration = "TextDecoration",
//
// Summary:
// Specifies the HTML width style.
Width = "Width",
//
// Summary:
// Specifies the HTML liststyleimage style.
ListStyleImage = "ListStyleImage",
//
// Summary:
// Specifies the HTML liststyletype style.
ListStyleType = "ListStyleType",
//
// Summary:
// Specifies the HTML cursor style.
Cursor = "Cursor",
//
// Summary:
// Specifies the HTML direction style.
Direction = "Direction",
//
// Summary:
// Specifies the HTML display style.
Display = "Display",
//
// Summary:
// Specifies the HTML filter style.
Filter = "Filter",
//
// Summary:
// Specifies the HTML fontvariant style.
FontVariant = "FontVariant",
//
// Summary:
// Specifies the HTML left style.
Left = "Left",
//
// Summary:
// Specifies the HTML margin style.
Margin = "Margin",
//
// Summary:
// Specifies the HTML marginbottom style.
MarginBottom = "MarginBottom",
//
// Summary:
// Specifies the HTML marginleft style.
MarginLeft = "MarginLeft",
//
// Summary:
// Specifies the HTML marginright style.
MarginRight = "MarginRight",
//
// Summary:
// Specifies the HTML margintop style.
MarginTop = "MarginTop",
//
// Summary:
// Specifies the HTML overflow style.
Overflow = "Overflow",
//
// Summary:
// Specifies the HTML overflowx style.
OverflowX = "OverflowX",
//
// Summary:
// Specifies the HTML overflowy style.
OverflowY = "OverflowY",
//
// Summary:
// Specifies the HTML padding style.
Padding = "Padding",
//
// Summary:
// Specifies the HTML paddingbottom style.
PaddingBottom = "PaddingBottom",
//
// Summary:
// Specifies the HTML paddingleft style.
PaddingLeft = "PaddingLeft",
//
// Summary:
// Specifies the HTML paddingright style.
PaddingRight = "PaddingRight",
//
// Summary:
// Specifies the HTML paddingtop style.
PaddingTop = "PaddingTop",
//
// Summary:
// Specifies the HTML position style.
Position = "Position",
//
// Summary:
// Specifies the HTML textalign style.
TextAlign = "TextAlign",
//
// Summary:
// Specifies the HTML verticalalign style.
VerticalAlign = "VerticalAlign",
//
// Summary:
// Specifies the HTML textoverflow style.
TextOverflow = "TextOverflow",
//
// Summary:
// Specifies the HTML top style.
Top = "Top",
//
// Summary:
// Specifies the HTML visibility style.
Visibility = "Visibility",
//
// Summary:
// Specifies the HTML whitespace style.
WhiteSpace = "WhiteSpace",
//
// Summary:
// Specifies the HTML zindex style.
ZIndex = "ZIndex";
}
}