Пример #1
0
        public void Complete(IEqualityComparerResolver resolver, PropertyInfo?pi)
        {
            Properties = MemberEntryFactory.GenerateList <T>(MemberOptions.Properties | MemberOptions.Typed | MemberOptions.Getter)
                         .Where(p => !((PropertyInfo)p.MemberInfo).HasAttribute <HiddenPropertyAttribute>())
                         .ToDictionary(a => a.Name, a => new PropertyComparer <T>(
                                           propertyInfo: (PropertyInfo)a.MemberInfo, a.Getter !,
                                           comparer: resolver.GetEqualityComparer(((PropertyInfo)a.MemberInfo).PropertyType, (PropertyInfo)a.MemberInfo)));

            Mixins = !typeof(Entity).IsAssignableFrom(typeof(T)) ? null :
                     MixinDeclarations.GetMixinDeclarations(typeof(T)).ToDictionary(t => t, t => resolver.GetEqualityComparer(t, null));
        }
Пример #2
0
        internal static void Start()
        {
            DescriptionManager.Invalidated       += () => cache.Clear();
            Schema.Current.OnMetadataInvalidated += () => cache.Clear();

            var mainTypes  = Schema.Current.Tables.Keys;
            var mixins     = mainTypes.SelectMany(t => MixinDeclarations.GetMixinDeclarations(t));
            var operations = OperationLogic.RegisteredOperations.Select(o => o.FieldInfo.DeclaringType);

            EntityAssemblies = mainTypes.Concat(mixins).Concat(operations).AgGroupToDictionary(t => t.Assembly, gr => gr.Select(a => a.Namespace).ToHashSet());
            EntityAssemblies[typeof(PaginationMode).Assembly].Add(typeof(PaginationMode).Namespace);
        }
Пример #3
0
        PropertyInfo GetPropertyInfo(LambdaExpression property, out Type mixin)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            Expression body = property.Body;

            if (body.NodeType == ExpressionType.Convert)
            {
                body = ((UnaryExpression)body).Operand;
            }

            MemberExpression ex = body as MemberExpression;

            if (ex == null)
            {
                throw new ArgumentException("The lambda 'property' should be an expression accessing a property");
            }

            PropertyInfo pi = ex.Member as PropertyInfo;

            if (pi == null)
            {
                throw new ArgumentException("The lambda 'property' should be an expression accessing a property");
            }

            var mce = ex.Expression as MethodCallExpression;

            if (ex.Expression == property.Parameters.Only())
            {
                mixin = null;

                return(pi);
            }
            else if (mce != null && mce.Method.IsInstantiationOf(MixinDeclarations.miMixin))
            {
                mixin = mce.Method.GetGenericArguments()[0];

                if (!MixinDeclarations.GetMixinDeclarations(typeof(T)).Contains(mixin))
                {
                    throw new ArgumentException("The mixin {0} used in lambda 'property' is not registered".FormatWith(mixin.TypeName()));
                }

                return(pi);
            }
            else
            {
                throw new ArgumentException("The lambda 'property' should be an expression accessing a property");
            }
        }
Пример #4
0
        private Dictionary <Type, FieldMixin> GenerateMixins(PropertyRoute propertyRoute, Table table, NameSequence nameSequence)
        {
            Dictionary <Type, FieldMixin> mixins = null;

            foreach (var t in MixinDeclarations.GetMixinDeclarations(table.Type))
            {
                if (mixins == null)
                {
                    mixins = new Dictionary <Type, FieldMixin>();
                }

                mixins.Add(t, this.GenerateFieldMixin(propertyRoute.Add(t), nameSequence, table));
            }

            return(mixins);
        }
Пример #5
0
        public EntityMapping(bool fillProperties)
        {
            if (fillProperties)
            {
                properties.AddRange(Validator.GetPropertyValidators(typeof(T)).Values
                                    .Where(pv => !pv.PropertyInfo.IsReadOnly())
                                    .Select(pv => NewProperty(pv, null)));

                if (typeof(Entity).IsAssignableFrom(typeof(T)))
                {
                    foreach (var t in MixinDeclarations.GetMixinDeclarations(typeof(T)))
                    {
                        properties.AddRange(Validator.GetPropertyValidators(t).Values
                                            .Where(pv => !pv.PropertyInfo.IsReadOnly())
                                            .Select(pv => NewProperty(pv, t)));
                    }
                }
            }
        }
Пример #6
0
    MemberInfo GetMember(string fieldOrProperty)
    {
        if (fieldOrProperty.Contains("."))
        {
            throw new ArgumentException($"{nameof(fieldOrProperty)} contains '.'");
        }

        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)));
        }
    }