Beispiel #1
0
        public static object FromObjectDictionary(this Dictionary <string, object> values, Type type)
        {
            bool flag = type == typeof(Dictionary <string, object>);

            if (flag)
            {
                return((object)flag);
            }
            PlatformExtensions.ObjectDictionaryDefinition dictionaryDefinition;
            if (!PlatformExtensions.toObjectMapCache.TryGetValue(type, out dictionaryDefinition))
            {
                PlatformExtensions.toObjectMapCache[type] = dictionaryDefinition = PlatformExtensions.CreateObjectDictionaryDefinition(type);
            }
            object instance = type.CreateInstance();

            foreach (KeyValuePair <string, object> keyValuePair in values)
            {
                PlatformExtensions.ObjectDictionaryFieldDefinition dictionaryFieldDefinition;
                if (dictionaryDefinition.FieldsMap.TryGetValue(keyValuePair.Key, out dictionaryFieldDefinition) && keyValuePair.Value != null)
                {
                    dictionaryFieldDefinition.SetValue(instance, keyValuePair.Value);
                }
            }
            return(instance);
        }
Beispiel #2
0
        public static Dictionary <string, object> ToObjectDictionary(this object obj)
        {
            if (obj == null)
            {
                return((Dictionary <string, object>)null);
            }
            Dictionary <string, object> dictionary1 = obj as Dictionary <string, object>;

            if (dictionary1 != null)
            {
                return(dictionary1);
            }
            IDictionary <string, object> dictionary2 = obj as IDictionary <string, object>;

            if (dictionary2 != null)
            {
                return(new Dictionary <string, object>(dictionary2));
            }
            Type type = obj.GetType();

            PlatformExtensions.ObjectDictionaryDefinition dictionaryDefinition;
            if (!PlatformExtensions.toObjectMapCache.TryGetValue(type, out dictionaryDefinition))
            {
                PlatformExtensions.toObjectMapCache[type] = dictionaryDefinition = PlatformExtensions.CreateObjectDictionaryDefinition(type);
            }
            Dictionary <string, object> dictionary3 = new Dictionary <string, object>();

            foreach (PlatformExtensions.ObjectDictionaryFieldDefinition field in dictionaryDefinition.Fields)
            {
                dictionary3[field.Name] = field.GetValueFn(obj);
            }
            return(dictionary3);
        }
Beispiel #3
0
 public static bool IsEnumFlags(this Type type)
 {
     if (type.IsEnum)
     {
         return(PlatformExtensions.FirstAttribute <FlagsAttribute>(type) != null);
     }
     return(false);
 }
Beispiel #4
0
        public static object[] AllAttributes(this MemberInfo memberInfo, Type attrType)
        {
            PropertyInfo propertyInfo = memberInfo as PropertyInfo;

            if (propertyInfo != (PropertyInfo)null)
            {
                return(PlatformExtensions.AllAttributes(propertyInfo, attrType));
            }
            return(memberInfo.GetCustomAttributes(attrType, true));
        }
Beispiel #5
0
 public static TAttr[] AllAttributes <TAttr>(this PropertyInfo pi)
 {
     return(PlatformExtensions.AllAttributes(pi, typeof(TAttr)).Cast <TAttr>().ToArray <TAttr>());
 }
Beispiel #6
0
 public static TAttr[] AllAttributes <TAttr>(this FieldInfo fi)
 {
     return(PlatformExtensions.AllAttributes(fi, typeof(TAttr)).Cast <TAttr>().ToArray <TAttr>());
 }
Beispiel #7
0
        public static bool HasAttributeNamed(this FieldInfo fi, string name)
        {
            string normalizedAttr = name.Replace("Attribute", "").ToLower();

            return(((IEnumerable <object>)PlatformExtensions.AllAttributes(fi)).Any <object>((Func <object, bool>)(x => x.GetType().Name.Replace("Attribute", "").ToLower() == normalizedAttr)));
        }
Beispiel #8
0
 public static bool HasAttribute <T>(this FieldInfo fi)
 {
     return(((IEnumerable <object>)PlatformExtensions.AllAttributes(fi)).Any <object>((Func <object, bool>)(x => x.GetType() == typeof(T))));
 }