[ASP.NET] Struct泛型集合筆記

將今天做的Binding欄位程式做一下筆記,主要使用Struct + List來實作

將今天做的Binding欄位程式做一下筆記,主要使用Struct + List<T>來實作,範例如下:

    /// Binding欄位資訊
    public struct BindingFieldInfo
    {
        public Control Obj;
        public string FieldName;
        public string DataType;
        public string Property;
    };

    /// 繼承泛型 增加客製化Method
    public class BindDataFieldList : List< BindingFieldInfo>
    {
        BindingFieldInfo BFI;
        public void Add(Control Obj, string FieldName, string DataType, string Property)
        {
            BFI = new BindingFieldInfo();
            BFI.Obj = Obj; BFI.FieldName = FieldName; BFI.DataType = DataType; BFI.Property = Property;
            this.Add(BFI);
        }
    }

設定Binding欄位範例:

            BindDataFieldList BDFList = new BindDataFieldList();
            BDFList.Add(TextBox1, "F1", "S", "Text");
            BDFList.Add(TextBox2, "F2", "S", "Text");
            BDFList.Add(TextBox2, "F3", "I", "Text");