internal static property GetProperty(MemberInfo memberInfo, string prefix = "", Func <MemberInfo, bool> notNull = null)
        {
            if (memberInfo.IsReadOnlyProperty())
            {
                return(null);
            }
            if (memberInfo.DeclaringType.GetSettableFieldsAndProperties().Any(memberInfo.IsBackingFieldFor))
            {
                return(null);
            }

            notNull = notNull ?? (mi => !mi.IsNullable());
            var returnType = memberInfo.ReturnType();
            var type       = GetTypeForPropertyRules.Rules.Select(r => r(memberInfo)).FirstOrDefault(t => t != null);

            if (type == null || type == typeof(void))
            {
                return(null);                                      //not for mapping, this one
            }
            var property = new property()
            {
                name    = memberInfo.Name,
                access  = memberInfo.Access(),
                notnull = notNull(memberInfo),
            };

            property.column.Add(new column().Setup(memberInfo, columnPrefix: prefix, notnull: property.notnull));

            property.type1 = type.AssemblyQualifiedName;

            UniqueAttribute.SetUniqueProperties(memberInfo, property);

            //this if statement could be happily replaced by some nifty lookup table or something
            if (returnType == typeof(DateTimeOffset) || returnType == typeof(DateTimeOffset?))
            {
                property.type1 = "datetimeoffset";
            }
            if (returnType == typeof(DateTime) || returnType == typeof(DateTime?))
            {
                property.type1 = "UtcDateTime";
            }
            if (returnType.IsEnum)
            {
                property.type1 =
                    typeof(EnumStringType <>).MakeGenericType(returnType).AssemblyQualifiedName;
            }
            // check nullable enum
            if (returnType.IsGenericType &&
                returnType.GetGenericTypeDefinition() == typeof(Nullable <>) &&
                returnType.GetGenericArguments()[0].IsEnum)
            {
                property.type1 =
                    typeof(EnumStringType <>).MakeGenericType(returnType.GetGenericArguments()[0]).AssemblyQualifiedName;
            }
            return(property);
        }
示例#2
0
        component GetComponent(MemberInfo mi, string columnPrefix = "")
        {
            if (!_identificationRules.Any(rule => rule(mi)))
            {
                return(null);
            }

            var fields = mi.DeclaringType.GetSettableFieldsAndProperties();

            if (fields.Any(mi.IsBackingFieldFor))
            {
                return(null);                                  //we don't want to map the wrapping properties
            }
            var component = new component()
            {
                name = mi.Name, access = mi.Access()
            };
            var prefix = columnPrefix + component.name.Sanitise() + "_";
            var fieldsAndProperties = mi.ReturnType().GetSettableFieldsAndProperties().ToList();
            var parent = fieldsAndProperties.SingleOrDefault(p => p.Name.TrimStart('_').ToLower() == "parent");

            if (parent != null)
            {
                fieldsAndProperties.Remove(parent);
                component.parent = new parent()
                {
                    name = parent.Name,
                };
            }

            foreach (var memberInfo in fieldsAndProperties)
            {
                var subcomponent = GetComponent(memberInfo, prefix);
                if (subcomponent != null)
                {
                    component.component1.Add(component);
                    continue;
                }
                var property = CreateBasicProperties.GetProperty(memberInfo, prefix, propMi => false);
                if (property != null)
                {
                    component.property.Add(property);
                    continue;
                }
            }
            return(component);
        }