object obj;
PropertyInfo pi = obj.GetType().GetProperty("VariableName");
YourType value = (YourType)(pi.GetValue(obj, null));
public static void RequiredCheck(object DataModel)
{
PropertyInfo[] Properties = DataModel.GetType().GetProperties();
foreach (var Property in Properties)
{
if (Property.PropertyType == typeof(string))
{
string value = Property.GetValue(DataModel, null) as string;
if (value == null || value.Trim() == string.Empty)
{
Property.SetValue(DataModel, "", null);
}
}
}
}'C#' 카테고리의 다른 글
직렬화/역직렬화 (0) | 2013.07.04 |
---|---|
IEnumerable list to an ObservableCollection (0) | 2013.06.24 |
간단한 SQL Server OLEDB 예제 (0) | 2011.04.14 |