Ejemplo n.º 1
0
        internal static string GetMappingName(this PropertyInfo info, string defaultName = null)
        {
            ZuoraNameAttribute attribute = info.GetCustomAttribute <ZuoraNameAttribute>();

            if (attribute != null && !string.IsNullOrEmpty(attribute.MappingOverride))
            {
                return(attribute.MappingOverride);
            }

            return(defaultName);
        }
Ejemplo n.º 2
0
        internal static string GetMappingName(this Type type)
        {
            ZuoraNameAttribute attribute = type.GetCustomAttribute <ZuoraNameAttribute>();

            if (attribute == null)
            {
                return(type.Name);
            }

            return(attribute.MappingOverride ?? (attribute.Name ?? type.Name));
        }
Ejemplo n.º 3
0
        private static string GetPropertyMappingName(PropertyInfo info)
        {
            ZuoraNameAttribute attribute = info.GetCustomAttribute <ZuoraNameAttribute>();

            if (attribute == null || string.IsNullOrEmpty(attribute.MappingOverride))
            {
                return(info.PropertyType.IsGenericType
                    ? info.PropertyType.GenericTypeArguments[0].GetMappingName()
                    : info.PropertyType.GetMappingName());
            }

            return(attribute.MappingOverride ?? attribute.Name);
        }
Ejemplo n.º 4
0
        private static void ParseRelations <T>(T item, Type type, CsvRow row, TypeAccessor accessor, Type parent = null)
            where T : ZObject
        {
            foreach (PropertyInfo property in type.GetObjectProperties())
            {
                string             mappingName  = null;
                string             propertyName = property.Name;
                Type               propertyType = property.PropertyType;
                ZuoraNameAttribute attribute    = property.GetCustomAttribute <ZuoraNameAttribute>();
                if (attribute != null && !string.IsNullOrEmpty(attribute.MappingOverride))
                {
                    mappingName = attribute.MappingOverride;
                }

                if (parent != null && property.PropertyType == parent)
                {
                    continue;
                }
                object value;

                if (property.PropertyType.IsGenericType)
                {
                    propertyType = propertyType.GetGenericArguments()[0];
                    if (parent != null && property.PropertyType == parent)
                    {
                        continue;
                    }
                    value = accessor[item, propertyName] ?? CreateGenericList(propertyType);
                    dynamic obj = ParseItem(propertyType, row, GetAccessor(propertyType), mappingName, type);
                    if (obj == null)
                    {
                        continue;
                    }
                    dynamic actualValue = Cast(value, CreateGenericList(obj, CastList(obj, value)));
                    accessor[item, propertyName] = actualValue;
                    continue;
                }

                if (accessor[item, propertyName] != null)
                {
                    continue;
                }
                value = ParseItem(propertyType, row, GetAccessor(propertyType), mappingName, type);
                if (value != null)
                {
                    accessor[item, propertyName] = value;
                }
            }
        }
Ejemplo n.º 5
0
        internal static string GetSelectName(this PropertyInfo info, string typeName)
        {
            string             propertyName = info.Name;
            ZuoraNameAttribute attribute    = info.GetCustomAttribute <ZuoraNameAttribute>();

            if (attribute != null)
            {
                propertyName = attribute.Name;
                if (!string.IsNullOrEmpty(attribute.MappingOverride))
                {
                    typeName = attribute.MappingOverride;
                }
            }

            return(typeName + "." + propertyName);
        }
Ejemplo n.º 6
0
        private static IEnumerable <string> GetSpecificObjectNames(Type type, List <string> list, string objectName, Type parent = null)
        {
            list.AddRange(GetSpecificProperties(type, objectName).Where(x => !list.Contains(x)));
            foreach (PropertyInfo property in type.GetObjectProperties().Where(propertyType => parent == null || propertyType != parent))
            {
                Type propertyType = property.PropertyType.IsGenericType
                    ? property.PropertyType.GetGenericArguments()[0]
                    : property.PropertyType;

                ZuoraNameAttribute attribute = property.GetCustomAttribute <ZuoraNameAttribute>();
                string             name      = attribute != null && !string.IsNullOrEmpty(attribute.MappingOverride)
                    ? attribute.MappingOverride
                    : propertyType.GetName();

                list.AddRange(GetSpecificObjectNames(propertyType, list, name, type));
            }

            return(list);
        }
Ejemplo n.º 7
0
        internal static string GetName(this Type type)
        {
            ZuoraNameAttribute attribute = type.GetCustomAttribute <ZuoraNameAttribute>();

            return(attribute != null ? attribute.Name ?? type.Name : type.Name);
        }