Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# setting property values through reflection with attributes

PropertyInfo[] properties = typeof(MyClass).GetProperties();
foreach(PropertyInfo property in properties)
{
    StoredDataValueAttribute attribute =
        Attribute.GetCustomAttribute(property, typeof(StoredDataValueAttribute)) as StoredDataValueAttribute;

    if (attribute != null) // This property has a StoredDataValueAttribute
    {
         property.SetValue(instanceOfMyClass, attribute.DataValue, null); // null means no indexes
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: null check syntax c# 
Csharp :: c# convert long to int 
Csharp :: c# switch case greater than 
Csharp :: how to find current country c# 
Csharp :: c# close program 
Csharp :: c# delete files in directory and subdirectories 
Csharp :: rotate gameobject unity 
Csharp :: how to destroy parent gameobject unity 
Csharp :: how to get unique list in c# 
Csharp :: c# loops 
Csharp :: c# operator overloading 
Csharp :: random mac address c# 
Csharp :: replace first occurrence of character in string c# 
Csharp :: c# wpf timer 
Csharp :: c# max two values 
Csharp :: difference between awake and start unity 
Csharp :: unity guid to object 
Csharp :: c# foreach namevaluecollection 
Csharp :: which game engine is best 
Csharp :: c# make file not read only 
Csharp :: c# arrow 
Csharp :: reverse linked list 
Csharp :: c# remove time in datetime 
Csharp :: microsoft forms create bitmap 
Csharp :: c# round to closest multiple 
Csharp :: search of specified registry key 
Csharp :: c# object list to joined string 
Csharp :: unity check if gameobject is inside collider 
Csharp :: c# .equals vs == 
Csharp :: IsInstanceOf nunit 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =