首页  编辑  

取得对象的Name属性值

Tags: /C#/RTTI/   Date Created:

using System . Reflection;

private string GetNameProperty( object AObject)

{

    if (AObject == null ) return "" ;

    Type vType = AObject . GetType();

    PropertyInfo vPropertyInfo = vType . GetProperty( "Name" );

    if (vPropertyInfo != null )

        return vPropertyInfo . GetValue(AObject, null ) . ToString();

    else return "" ;

}