惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Cloudflare Blog
U
Unit 42
F
Fortinet All Blogs
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
Y
Y Combinator Blog
罗磊的独立博客
V
Visual Studio Blog
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
爱范儿
爱范儿
B
Blog RSS Feed
aimingoo的专栏
aimingoo的专栏
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
I
InfoQ
博客园 - 叶小钗
博客园 - 聂微东
Last Week in AI
Last Week in AI

博客园 - shcity

Troubleshooting on TransactionScope Parse string to JSON object Parse date in js blockUI doesn't close when download file in asp.net define namespace in JS Dense_Rank(), Row_Number(), Rank() in sql server reading and writing variable through lock in SSIS script task Fix the issue that cannot open SSIS in BIDS three ways creating custom helpers to show RadioButtonList in MVC using JavaScriptSerializer to serialize object to json using ISerializable to control serialization and deserialization ViewStateAutoManager ReportingService formatting split a string into an array through comma div with separated html template - shcity 正则表达式替换日期 半透明的div对话框 foreach 的自动转化类型 在Ajax1.0中调用页面CS文件中的方法
Build my own DataTable
shcity · 2011-03-30 · via 博客园 - shcity

public class MyTable : List<MyRow>, ITypedList
    {
        
public MyTable()
        {
            
for (int i = 0; i < 5; i++)
            {
                MyRow ht 
= new MyRow();
                ht.Table 
= this;
                ht.Add(
"Name""name" + i);
                ht.Add(
"Age", i + 10);
                ht.Add(
"Address""add:" + i);
                
this.Add(ht);
            }
        }
#region ITypedList Memberspublic PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            List
<MyPropertyDescriptor> list = new List<MyPropertyDescriptor>();
            list.Add(
new MyPropertyDescriptor("Name"typeof(string)));
            list.Add(
new MyPropertyDescriptor("Age"typeof(int)));
            list.Add(
new MyPropertyDescriptor("Address"typeof(string)));
            
return new PropertyDescriptorCollection(list.ToArray());
        }
public string GetListName(PropertyDescriptor[] listAccessors)
        {
            
return string.Empty;
        }
#endregion
    }
public class MyRow : Hashtable, ICustomTypeDescriptor
    {
        
public MyTable Table { getset; }#region ICustomTypeDescriptor Memberspublic System.ComponentModel.AttributeCollection GetAttributes()
        {
            
return new System.ComponentModel.AttributeCollection(null);
        }
public string GetClassName()
        {
            
return null;
        }
public string GetComponentName()
        {
            
return null;
        }
public TypeConverter GetConverter()
        {
            
return null;
        }
public EventDescriptor GetDefaultEvent()
        {
            
return null;
        }
public PropertyDescriptor GetDefaultProperty()
        {
            
return null;
        }
public object GetEditor(Type editorBaseType)
        {
            
return null;
        }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
        {
            
return new EventDescriptorCollection(null);
        }
public EventDescriptorCollection GetEvents()
        {
            
return new EventDescriptorCollection(null);
        }
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            
return this.Table.GetItemProperties(null);
        }
public PropertyDescriptorCollection GetProperties()
        {
            
return ((ICustomTypeDescriptor)this).GetProperties(null);
        }
public object GetPropertyOwner(PropertyDescriptor pd)
        {
            
return this;
        }
#endregion
    }
public class MyPropertyDescriptor : PropertyDescriptor
    {
        
private string _field;
        
private Type _propertyType;public MyPropertyDescriptor(string name, Type propertyType)
            : 
base(name, null)
        {
            _field 
= name;
            _propertyType 
= propertyType;
        }
public override bool CanResetValue(object component)
        {
            
return false;
        }
public override bool Equals(object other)
        {
            
if (other is MyPropertyDescriptor)
            {
                MyPropertyDescriptor descriptor 
= (MyPropertyDescriptor)other;
                
return (descriptor._field == this._field);
            }
            
return false;
        }
public override int GetHashCode()
        {
            
return _field.GetHashCode();
        }
public override object GetValue(object component)
        {
            MyRow view 
= (MyRow)component;
            
return view[_field];
        }
public override void ResetValue(object component)
        {
            ((MyRow)component)[_field] 
= null;
        }
public override void SetValue(object component, object value)
        {
            ((MyRow)component)[_field] 
= value;
            
this.OnValueChanged(component, EventArgs.Empty);
        }
public override bool ShouldSerializeValue(object component)
        {
            
return false;
        }
public override Type ComponentType
        {
            
get
            {
                
return typeof(MyRow);
            }
        }
public override bool IsBrowsable
        {
            
get
            {
                
return base.IsBrowsable;
            }
        }
public override bool IsReadOnly
        {
            
get
            {
                
return true;
            }
        }
public override Type PropertyType
        {
            
get
            {
                
return _propertyType;
            }
        }
    }

posted on 2011-03-30 13:24  shcity  阅读(217)  评论()    收藏  举报