public static List <PropertyRoute> GenerateRoutes(Type type)
        {
            PropertyRoute        root   = PropertyRoute.Root(type);
            List <PropertyRoute> result = new List <PropertyRoute>();

            result.Add(root.Add(piId));

            foreach (PropertyInfo pi in Reflector.PublicInstancePropertiesInOrder(type))
            {
                PropertyRoute route = root.Add(pi);
                result.Add(route);

                if (Reflector.IsEmbeddedEntity(pi.PropertyType))
                {
                    result.AddRange(GenerateEmbeddedProperties(route));
                }

                if (Reflector.IsMList(pi.PropertyType))
                {
                    Type colType = pi.PropertyType.ElementType();
                    if (Reflector.IsEmbeddedEntity(colType))
                    {
                        result.AddRange(GenerateEmbeddedProperties(route.Add("Item")));
                    }
                }
            }

            foreach (var t in MixinDeclarations.GetMixinDeclarations(type))
            {
                result.AddRange(GenerateEmbeddedProperties(root.Add(t)));
            }

            return(result);
        }
示例#2
0
        MemberInfo GetMember(string fieldOrProperty)
        {
            if (fieldOrProperty.StartsWith("["))
            {
                var mixinName = ExtractMixin(fieldOrProperty);

                return(MixinDeclarations.GetMixinDeclarations(Type).FirstOrDefault(t => t.Name == mixinName) ??
                       throw new InvalidOperationException("{0}{1} does not exist".FormatWith(this, fieldOrProperty)));
            }
            else
            {
                var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;

                return((MemberInfo?)Type.GetProperty(fieldOrProperty, flags, null, null, IsCollection() ? new[] { typeof(int) } : new Type[0], null) ??
                       (MemberInfo?)Type.GetField(fieldOrProperty, flags) ??
                       throw new InvalidOperationException("{0}.{1} does not exist".FormatWith(this, fieldOrProperty)));
            }
        }
示例#3
0
        MemberInfo GetMember(string fieldOrProperty)
        {
            MemberInfo mi = (MemberInfo)Type.GetProperty(fieldOrProperty, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, null, IsCollection() ? new[] { typeof(int) } : new Type[0], null) ??
                            (MemberInfo)Type.GetField(fieldOrProperty, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            if (mi == null && Type.IsEntity())
            {
                string?name = ExtractMixin(fieldOrProperty);

                mi = MixinDeclarations.GetMixinDeclarations(Type).FirstOrDefault(t => t.Name == name);
            }

            if (mi == null)
            {
                throw new InvalidOperationException("{0}.{1} does not exist".FormatWith(this, fieldOrProperty));
            }

            return(mi);
        }