Reflection의 활용

C# 2011. 11. 7. 15:47

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
Posted by 백운성
,