Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# get all class properties

//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;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# sql duplicate key exception 
Csharp :: change textbox text color c# 
Csharp :: Unity asset storre download forlder 
Csharp :: c# console play sound 
Csharp :: random seed in c# 
Csharp :: c# regex to find number between parenthesis 
Csharp :: unity keycode 
Csharp :: remove last comma from string c# 
Csharp :: unity check load scene 
Csharp :: c# shuffle array 
Csharp :: csharp check if env is development 
Csharp :: data annotation c# name 
Csharp :: parse int in c# 
Csharp :: blazor oninitializedasync 
Csharp :: c# multiple catch exceptions 
Csharp :: c# display float with 2 decimal places 
Csharp :: c# get class name by type 
Csharp :: SAVE FLOAT UNITY 
Csharp :: how to clear datagridview c# 
Csharp :: odd or even in c# 
Csharp :: print random number unity 
Csharp :: how to create a list in c# unity 
Csharp :: unity spherecast 
Csharp :: how to make multiplayer game in unity 
Csharp :: add object to list c# 
Csharp :: untiy instanciate prefab 
Csharp :: todictionary c# 
Csharp :: c# convert split to list 
Csharp :: how to add a queue unity 
Csharp :: where did mark twain go to school 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =