C# TypeDescriptor初了解

本文介绍了组件特性,包括属性、事件等,并详细解释了TypeDescriptor类如何获取组件属性集合,及其实现动态扩展的方式。

说明
Provides information about the characteristics for a component, such as its attributes, properties, and events. This class cannot be inherited.
提供了一些关于组件特征的一些信息,例如:属性(attributes),属性(properties),事件,该类不能被集成。

GetProperties(Object)
Returns the collection of properties for a specified component. 针对某一特定组件,返回该组件的所有属性集合。

TypeDescriptor is an extensible inspection mechanism for components: those classes that implement the IComponent interface. Unlike reflection, it does not inspect for methods. TypeDescriptor can be dynamically extended by several services available through the target component's Site. The following table shows these services.

得到特定属性(Attribute)的值

PropertyDescriporCollection myPropertyDescriporCollection = TypeDescripor.GetProperties(this);
for(PropertyDescripor myPropertyDescripor in myPropertyDescriporCollection)
{
    FieldAttribute myFieldAttribute = myPropertyDescripor.Attributes(typeof(FieldAttribute)) as FunctionParameterAttribute
    
    string fieldName = TableAttribute.FieldName;//User
    DbType fileDbType = TableAttribute.DbType;// DbType.String
}

public Class User
{
    [Filed("User",DbType.String)]
    public string User { get; set; }
}

public Class FieldAttrubute:Attribute
{
    public FieldAttrubute(string name,DbType dbType)
    {
        Name = name;
        FieldDbType = dbType;
    }
    public string Name{ get; set; }
    public DbType FieldDbType { get; set; }
}
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值