N

รหัสตัวอย่าง

3
0

c#จัดเรียนคุณสมบัติ

//through reflection
using System.Reflection;

//Get a List of the properties from a type
public static PropertyInfo[] ListOfPropertiesFromInstance(Type AType)
{
  	if (InstanceOfAType == null) return null;
    return AType.GetProperties(BindingFlags.Public);
}

//Get a List of the properties from a instance of a class
public static PropertyInfo[] ListOfPropertiesFromInstance(object InstanceOfAType)
{
  	if (InstanceOfAType == null) return null;
  	Type TheType = InstanceOfAType.GetType();
    return TheType.GetProperties(BindingFlags.Public);
}

//purrfect for usage example and Get a Map of the properties from a instance of a class
public static Dictionary<string, object> DictionaryOfPropertiesFromInstance(object InstanceOfAType)
{
    if (InstanceOfAType == null) return null;
    Type TheType = InstanceOfAType.GetType();
    PropertyInfo[] Properties = TheType.GetProperties(BindingFlags.Public);
    Dictionary<string, PropertyInfo> PropertiesMap = new Dictionary<string, PropertyInfo>();
    foreach (PropertyInfo Prop in Properties)
    {
        PropertiesMap.Add(Prop.Name, Prop);
    }
    return PropertiesMap;
}
0
0

c#เอารายชื่อของทุกช่องข้อมูลชั้นเรียน

using System.Reflection;

FieldInfo[] property_infos = typeof(Player).GetFields();

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................