Exemplo n.º 1
0
        public static ConcurrentDictionary <PropertyInfo, Action <object, object> > SetterDelegatesByPropertyInfo(Type type)
        {
            if (!SetterDelegatesByPropertyInfoCache.ContainsKey(type))
            {
                SetterDelegatesByPropertyInfoCache[type] = new ConcurrentDictionary <PropertyInfo, Action <object, object> >();
            }

            foreach (var propertyInfo in PropertiesInfo(type))
            {
                SetterDelegatesByPropertyInfoCache[type][propertyInfo] = DelegateGenerator.SetDelegate(propertyInfo);
            }

            return(SetterDelegatesByPropertyInfoCache[type]);
        }
Exemplo n.º 2
0
        public static ConcurrentDictionary <string, Action <object, object> > SetterDelegatesByPropertyName(Type type, Case toCase = Case.Default)
        {
            if (!SetterDelegatesByPropertyNameCache.ContainsKey(type))
            {
                SetterDelegatesByPropertyNameCache[type] = new ConcurrentDictionary <Case, ConcurrentDictionary <string, Action <object, object> > >();
            }

            if (!SetterDelegatesByPropertyNameCache[type].ContainsKey(toCase))
            {
                SetterDelegatesByPropertyNameCache[type][toCase] = new ConcurrentDictionary <string, Action <object, object> >();

                foreach (var propertyInfo in PropertiesInfo(type))
                {
                    var name = propertyInfo.Name;
                    switch (toCase)
                    {
                    case Case.Snake:
                        name = name.ToSnakeCase();
                        break;

                    case Case.Camel:
                        name = name.ToCamelCase();
                        break;

                    case Case.Pascal:
                        name = name.ToPascalCase();
                        break;

                    case Case.Default:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(toCase), toCase, null);
                    }

                    SetterDelegatesByPropertyNameCache[type][toCase][name] = DelegateGenerator.SetDelegate(propertyInfo);
                }
            }

            return(SetterDelegatesByPropertyNameCache[type][toCase]);
        }
Exemplo n.º 3
0
        private static IEnumerable <PropertyMapper> PropertyMappers(Type type)
        {
            if (!cache.ContainsKey(type))
            {
                cache[type] = type.GetProperties().Select(propertyInfo => new PropertyMapper(propertyInfo, DelegateGenerator.GetDelegate(propertyInfo), DelegateGenerator.SetDelegate(propertyInfo))).ToArray();
            }

            return(cache[type]);
        }