Advertisement
N1K003

Untitled

Jun 30th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1.     internal static class SomeClassExtentions
  2.     {
  3.         public static String GetSomeValue(this Object classInstance, String fieldName)
  4.         {
  5.             const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
  6.             Type ft = classInstance.GetType();
  7.             Object value = classInstance;
  8.  
  9.             foreach (String field in fieldName.Split('.'))
  10.             {
  11.                 FieldInfo fi = ft.GetField(field, flags);
  12.                 if (fi != null)
  13.                 {
  14.                     value = fi.GetValue(value);
  15.                     ft = fi.FieldType;
  16.                 }
  17.             }
  18.             return value != null ? value.ToString() : String.Empty;
  19.         }
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement