Esempio n. 1
0
        public static Dictionary <string, object> ParseObjectKeyValues(object obj, params string[] exclude)
        {
            if (obj == null)
            {
                return(null);
            }
            Type typeOfObj = obj.GetType();
            var  props     = typeOfObj.GetDatabaseUsableProperties().ToArray();

            if (exclude.Any())
            {
                props = props.Where(x => !exclude.Contains(x.Name)).ToArray();
            }
            var getterMap = PropertyCallerCache.GetterOfType(typeOfObj);
            var dict      = new Dictionary <string, object>();

            foreach (var p in props)
            {
                var propertyName = p.Name;

                var propertyValue = getterMap.Get <object>(obj, propertyName); // p.GetValue(obj);
                dict.Add(propertyName, propertyValue);
            }

            if (!props.Any())
            {
                dict = ((IDictionary <string, object>)obj).ToDictionary(x => x.Key, x => x.Value);
            }
            return(dict);
        }
Esempio n. 2
0
        internal TType GetPropertyAs <TType>(T instance, string fieldName)
        {
            if (_getter == null)
            {
                _getter = PropertyCallerCache.GetterOfType(_typeofT);
            }

            return(_getter.Get <TType>(instance, fieldName));
        }
Esempio n. 3
0
 private void CreateMapIfNotDone()
 {
     _setter = PropertyCallerCache.SetterOfType(_typeofT);
 }