|
using System;
using System.Reflection;
namespace System.Web
{
public partial class LocalBase
{
public static class Reflection
{
public static T GetPropertyValue<T>(object obj, string propertykey)
{
PropertyInfo property = obj.GetType().GetProperty(propertykey);
return (T)property.GetValue(obj, null);
}
public static void SetPropertyValue<T>(object obj, string propertykey, T value)
{
SetPropertyValue<T>(obj, propertykey, value, false);
}
public static void SetPropertyValue<T>(object obj, string propertykey, T value, bool setOnlyWhenValuesDiffer)
{
PropertyInfo property = obj.GetType().GetProperty(propertykey);
if (setOnlyWhenValuesDiffer)
{
T val = (T)property.GetValue(obj, null);
if (val.Equals(value))
return;
}
property.SetValue(obj, value, null);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.