Пример #1
0
 public static string DisplayName <T>(Expression <Func <T, object> > ex)
 {
     return(Safe.Run(() => {
         var name = Name(ex);
         var p = GetClass.Property <T>(name);
         var list = p?.GetCustomAttributes(typeof(DisplayNameAttribute), true);
         if (list is null || list.Length < 1)
         {
             return name;
         }
         var a = list.Cast <DisplayNameAttribute>().Single();
         return a?.DisplayName ?? name;
     }, string.Empty));
 }
Пример #2
0
        private static void SetValuesForProperties(object o)
        {
            if (o is null)
            {
                return;
            }
            var t          = o.GetType();
            var properties = GetClass.Properties(t);

            foreach (var p in properties)
            {
                if (!p.CanWrite)
                {
                    continue;
                }
                if (p.PropertyType.Name == t.Name)
                {
                    continue;
                }
                var v = GetRandom.Value(p.PropertyType);
                p.SetValue(o, v);
            }
        }