Set Property Value - CSharp System.Reflection

CSharp examples for System.Reflection:PropertyInfo

Description

Set Property Value

Demo Code


using System.Reflection;
using System.Linq;
using System;/*from   www .  j  av  a2  s.  c o m*/

public class Main{
        public static void SetPropertyValue(object entity, string propertyName, object value)
        {
            Type type = entity.GetType();
            PropertyInfo propertyInfo = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.IgnoreCase);
            propertyInfo.SetValue(entity,value,null);
        }
}

Related Tutorials