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

推荐订阅源

The GitHub Blog
The GitHub Blog
Martin Fowler
Martin Fowler
Vercel News
Vercel News
U
Unit 42
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
爱范儿
爱范儿
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog RSS Feed
N
Netflix TechBlog - Medium
GbyAI
GbyAI
F
Fortinet All Blogs
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
M
MIT News - Artificial intelligence
D
Docker
IT之家
IT之家
Stack Overflow Blog
Stack Overflow Blog

博客园 - 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)  评论()    收藏  举报