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

推荐订阅源

博客园_首页
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Engineering at Meta
Engineering at Meta
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
M
MIT News - Artificial intelligence
IT之家
IT之家
博客园 - 【当耐特】
U
Unit 42
云风的 BLOG
云风的 BLOG
L
LangChain Blog
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
宝玉的分享
宝玉的分享
N
Netflix TechBlog - Medium

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