0

asp.net で利用可能なすべての一般的なスタイル タイプのデータ ソースを検索していました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;
                }

aへのList<string>入力は、次のように行われます。

List<string> testLstStr = EnumToStrLst<htmlTextWriterStyle>()

ここでの全体の問題は、その値へのアクセスですが、列挙型のようにエレガントな方法ではありません。

testLstStr.elementAt(index) 

とは対照的に

enumName.valueName
4

2 に答える 2

1

これはテストされていませんが、次のようなラッパークラスを作成するのはどうでしょうか。

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



}

このようにして、このラッパークラスを操作することができます

于 2012-10-07T00:01:40.837 に答える
0

アクセスの容易さをあきらめずにそれを行うことができる唯一の方法は、seald クラスと const 文字列を使用して、要約を使用して enum メタデータからコピーすることです (1 つの型宣言のみでうまくレイアウトされています)。

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";
    }
}
于 2012-10-07T14:37:44.387 に答える