コード例 #1
0
        public static void LoadVisitors(string gameType = "Unreal", Assembly loadFrom = null)
        {
            if ((object)loadFrom == null)
            {
                loadFrom = Assembly.GetExecutingAssembly();
            }
            LoadExportVisitors(gameType, loadFrom);
            LoadStructVisitors(gameType, loadFrom);
            Type baseType = typeof(FPropertyTag);

            foreach (Type item in from x in loadFrom.GetTypes()
                     where baseType.IsAssignableFrom(x) && x.GetCustomAttribute <CategoryAttribute>()?.Category == gameType
                     select x)
            {
                string text = item.GetCustomAttribute <DescriptionAttribute>()?.Description;
                if (string.IsNullOrWhiteSpace(text))
                {
                    throw new InvalidDataException(item.FullName + " has no DescriptionAttribute!");
                }
                PropertyVisitor propertyVisitor = (from x in item.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public).Select(CreateDelegate)
                                                   where x != null
                                                   select x).FirstOrDefault();
                Visitors[text] = (propertyVisitor ?? CreateTagDeserializer(item));
            }
        }
コード例 #2
0
        public object Build(object inst, IConfiguration configuration)
        {
            foreach (var item in propertyInfos.Values)
            {
                var selectConfig = configuration.GetSection(item.Key);
                var value        = selectConfig.Value;

                if (item.ProxyCreator is null)
                {
                    if (!string.IsNullOrEmpty(value) &&
                        TypeHelper.TryChangeType(value, item.PropertyInfo.PropertyType, out _, out var res))
                    {
                        PropertyVisitor.SetValue(inst, res, item.PropertyInfo);
                    }
                }
                else
                {
                    var propVal = PropertyVisitor.GetValue(inst, item.PropertyInfo);
                    if (propVal is null)
                    {
                        var val = item.ProxyCreator.Build(selectConfig);
                        PropertyVisitor.SetValue(inst, val, item.PropertyInfo);
                    }
                    else
                    {
                        item.ProxyCreator.Build(propVal, selectConfig);
                    }
                }
            }
            return(inst);
        }
コード例 #3
0
ファイル: WhereVisitor.cs プロジェクト: rflechner/KeyQuery
        static string GetPath(Expression expression)
        {
            var propertyVisitor = new PropertyVisitor();

            propertyVisitor.Visit(expression);
            return(propertyVisitor.Path);
        }
コード例 #4
0
 public NestedValuePropertyVisitor(PropertyVisitor parentPropertyVisitor,
                                   bool omitIfNull,
                                   PropertyInfo propertyInfo)
     : base(omitIfNull, propertyInfo)
 {
     this.parent_property_visitor = parentPropertyVisitor;
 }
コード例 #5
0
ファイル: AOTExtensions.cs プロジェクト: debuggerpls/pongDOTS
        public static void GenerateAOTFunctions <TProperty, TContainer, TValue>()
            where TProperty : IProperty <TContainer, TValue>
        {
            TProperty     property      = default(TProperty);
            TContainer    container     = default(TContainer);
            TValue        value         = default(TValue);
            ChangeTracker changeTracker = default(ChangeTracker);

            PropertyVisitor propertyVisitor = new PropertyVisitor();

            propertyVisitor.TryVisitContainerWithAdapters(property, ref container, ref value, ref changeTracker);
            propertyVisitor.TryVisitValueWithAdapters(property, ref container, ref value, ref changeTracker);
            PropertyVisitorAdapterExtensions.TryVisitContainer(null, null, property, ref container, ref value, ref changeTracker);
            PropertyVisitorAdapterExtensions.TryVisitValue(null, null, property, ref container, ref value, ref changeTracker);

            Actions.GetCollectionCountGetter <TContainer> getCollectionCountGetter       = new Actions.GetCollectionCountGetter <TContainer>();
            Actions.GetCountFromActualTypeCallback        getCountFromActualTypeCallback = new Actions.GetCountFromActualTypeCallback();
            getCountFromActualTypeCallback.Invoke <TContainer>();
            getCountFromActualTypeCallback.Invoke <TValue>();
            Actions.GetCountAtPathGetter <TContainer> getCountAtPathGetter = new Actions.GetCountAtPathGetter <TContainer>();
            Actions.VisitAtPathCallback visitAtPathCallback = default;
            visitAtPathCallback.Invoke <TContainer>();
            visitAtPathCallback.Invoke <TValue>();
            Actions.SetCountCallback setCountCallback = default;
            setCountCallback.Invoke <TContainer>();
            setCountCallback.Invoke <TValue>();

            Actions.TryGetCount(ref container, new PropertyPath(), 0, ref changeTracker, out var count);
            Actions.TryGetCountImpl(ref container, new PropertyPath(), 0, ref changeTracker, out var otherCount);
            Actions.GetCount(ref container, new PropertyPath(), 0, ref changeTracker);
        }
コード例 #6
0
        /// <summary>
        /// Get the property paths in the specified expression.
        /// </summary>
        /// <returns>The paths.</returns>
        /// <param name="expression">Expression.</param>
        /// <typeparam name="TResult">The 1st type parameter.</typeparam>
        public static IReadOnlyList <PropertyPath> Get <TResult>(Expression <Func <TSource, TResult> > expression)
        {
            var visitor = new PropertyVisitor();

            visitor.Visit(expression.Body);
            return(visitor.Paths);
        }
コード例 #7
0
        public static IReadOnlyList <MemberInfo> GetPropertyVistPath(this LambdaExpression expression)
        {
            var visitor = new PropertyVisitor();

            visitor.Visit(expression.Body);
            visitor.Path.Reverse();
            return(visitor.Path);
        }
コード例 #8
0
        public static IReadOnlyList <PropertyInfo> GetExpressionProperties <TSource, TResult>(this Expression <Func <TSource, TResult> > expression)
        {
            var visitor = new PropertyVisitor();

            visitor.Visit(expression.Body);
            visitor.Path.Reverse();
            return(visitor.Path.Distinct().ToArray());
        }
コード例 #9
0
        public static IReadOnlyList <MemberInfo> Get <TResult>(Expression <Func <TSource, TResult> > expression)
        {
            var visitor = new PropertyVisitor();

            visitor.Visit(expression.Body);
            visitor.Path.Reverse();
            return(visitor.Path);
        }
コード例 #10
0
        public static string ToStringPath <TSource, TResult>(this Expression <Func <TSource, TResult> > expression)
        {
            var visitor = new PropertyVisitor();

            visitor.Visit(expression.Body);
            visitor.Path.Reverse();
            return(string.Join(".", visitor.Path));
        }
コード例 #11
0
        /// <summary>
        /// Maps a property for the composite user type.
        /// </summary>
        /// <param name="property">A expression representing the property to map.</param>
        protected virtual void MapProperty(Expression <Func <T, object> > property)
        {
            var visitor = new PropertyVisitor();

            visitor.Visit(property);

            _properties.Add(visitor.Property);
        }
コード例 #12
0
        public void Find_Field_Throws()
        {
            Expression <Func <Foo, object> > expression = x => x.Bar.Field;
            var visitor = new PropertyVisitor();

            visitor.Invoking(x => x.Visit(expression.Body))
            .Should()
            .ThrowExactly <ArgumentException>();
        }
コード例 #13
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            Expression expression = base.Visit(node.Arguments[0]);

            if (node.Method.DeclaringType == typeof(EntityFrameworkQueryableExtensions))
            {
                if (node.Method.Name == nameof(EntityFrameworkQueryableExtensions.Include) ||
                    node.Method.Name == nameof(EntityFrameworkQueryableExtensions.ThenInclude))
                {
                    var visitor = new PropertyVisitor();
                    visitor.Visit(node.Arguments[1]);

                    if (visitor.Filter == null)
                    {
                        node = Expression.Call(null, node.Method, new Expression[] { expression, node.Arguments[1] });
                    }
                    else
                    {
                        if (node.Method.Name == nameof(EntityFrameworkQueryableExtensions.Include))
                        {
                            Type             entityType = node.Method.GetGenericArguments()[0];
                            MethodInfo       method     = node.Method.GetGenericMethodDefinition().MakeGenericMethod(entityType, visitor.Property.Type);
                            LambdaExpression lambda     = Expression.Lambda(visitor.Property, visitor.Parameter);
                            node = Expression.Call(null, method, new Expression[] { node.Arguments[0], lambda });
                        }
                        else
                        {
                            Type             entityType           = node.Method.GetGenericArguments()[0];
                            Type             previousPropertyType = node.Method.GetGenericArguments()[1];
                            MethodInfo       method = node.Method.GetGenericMethodDefinition().MakeGenericMethod(entityType, previousPropertyType, visitor.Property.Type);
                            LambdaExpression lambda = Expression.Lambda(visitor.Property, visitor.Parameter);
                            node = Expression.Call(null, method, new Expression[] { node.Arguments[0], lambda });
                        }
                    }

                    _includes.Add(new Include(visitor.Property.Member as PropertyInfo, visitor.Filter, false));
                }
            }
            else if (node.Method.DeclaringType == typeof(Queryable) && node.Method.Name == nameof(Queryable.Select))
            {
                var visitor = new NewVisitor();
                visitor.Visit(node.Arguments[1]);
                _includes.AddRange(visitor.SelectProperties.Select(p => new Include(p, null, true)));
            }
            else
            {
                if (node.Arguments.Count == 1)
                {
                    node = Expression.Call(node.Object, node.Method, expression);
                }
                else
                {
                    node = Expression.Call(node.Object, node.Method, expression, node.Arguments[1]);
                }
            }
            return(node);
        }
コード例 #14
0
        public override void Configure(ITypeBuilderContainer container)
        {
            var propVisitor = new PropertyVisitor(_propType, _propName);

            if (_attributeFactories != null)
            {
                _attributeFactories.ToList().ForEach(propVisitor.AddCustomAttributeFactory);
            }

            container.AddVisitor(propVisitor);
        }
コード例 #15
0
 public override void Visit(PropertyVisitor visitor, CharacterEnum character, CardProperty property = null)
 {
     if (property != null)
     {
         base.Visit(visitor, character, property);
     }
     else
     {
         base.Visit(visitor, character, Effect);
     }
 }
コード例 #16
0
        public void Find_Property_Succeeds()
        {
            Expression <Func <Foo, object> > expression = x => x.Bar.Baz;
            var visitor = new PropertyVisitor();

            visitor.Visit(expression.Body);

            var result = string.Join("", visitor.Path.Select(x => x.Name));

            result.Should().Be("BazBar");
        }
コード例 #17
0
            internal static PropertyInfo ExtractProperty(Expression node)
            {
                if (node == null)
                {
                    throw new ArgumentNullException(nameof(node));
                }

                var visited          = new PropertyVisitor().Visit(node);
                var memberExpression = visited as MemberExpression ?? throw new GitObjectDbException("Member expressions expected.");

                return(memberExpression.Member as PropertyInfo ?? throw new GitObjectDbException($"The member '{memberExpression.Member.Name}' is not a property."));
            }
コード例 #18
0
        private static ChildPropertyInfo ExtractProperty(IModelDataAccessor dataAccessor, Expression propertyPicker)
        {
            if (propertyPicker == null)
            {
                throw new ArgumentNullException(nameof(propertyPicker));
            }

            var property = PropertyVisitor.ExtractProperty(propertyPicker);
            var result   = dataAccessor.ChildProperties.FirstOrDefault(p => p.Property == property);

            return(result ?? throw new GitObjectDbException($"Member should be a child property."));
        }
コード例 #19
0
ファイル: AOTExtensions.cs プロジェクト: debuggerpls/pongDOTS
        public static void GenerateAOTCollectionFunctions <TProperty, TContainer, TValue>()
            where TProperty : ICollectionProperty <TContainer, TValue>
        {
            TProperty     property      = default(TProperty);
            TContainer    container     = default(TContainer);
            TValue        value         = default(TValue);
            ChangeTracker changeTracker = default(ChangeTracker);
            var           getter        = new VisitCollectionElementCallback <TContainer>();

            PropertyVisitor propertyVisitor = new PropertyVisitor();

            propertyVisitor.TryVisitContainerWithAdapters(property, ref container, ref value, ref changeTracker);
            propertyVisitor.TryVisitCollectionWithAdapters(property, ref container, ref value, ref changeTracker);
            propertyVisitor.TryVisitValueWithAdapters(property, ref container, ref value, ref changeTracker);
            PropertyVisitorAdapterExtensions.TryVisitCollection(null, null, property, ref container, ref value, ref changeTracker);
            PropertyVisitorAdapterExtensions.TryVisitContainer(null, null, property, ref container, ref value, ref changeTracker);
            PropertyVisitorAdapterExtensions.TryVisitValue(null, null, property, ref container, ref value, ref changeTracker);

            var arrayProperty = new ArrayProperty <TContainer, TValue>();

            arrayProperty.GetPropertyAtIndex(ref container, 0, ref changeTracker, ref getter);
            var arrayCollectionElementProperty = new ArrayProperty <TContainer, TValue> .CollectionElementProperty();

            arrayCollectionElementProperty.GetValue(ref container);
            arrayCollectionElementProperty.SetValue(ref container, value);
            propertyVisitor.VisitProperty <ArrayProperty <TContainer, TValue> .CollectionElementProperty, TContainer, TValue>(arrayCollectionElementProperty, ref container, ref changeTracker);

            var listProperty = new ListProperty <TContainer, TValue>();

            listProperty.GetPropertyAtIndex(ref container, 0, ref changeTracker, ref getter);
            var listCollectionElementProperty = new ListProperty <TContainer, TValue> .CollectionElementProperty();

            listCollectionElementProperty.GetValue(ref container);
            listCollectionElementProperty.SetValue(ref container, value);
            propertyVisitor.VisitProperty <ListProperty <TContainer, TValue> .CollectionElementProperty, TContainer, TValue>(listCollectionElementProperty, ref container, ref changeTracker);

            Actions.GetCollectionCountGetter <TContainer> getCollectionCountGetter       = new Actions.GetCollectionCountGetter <TContainer>();
            Actions.GetCountFromActualTypeCallback        getCountFromActualTypeCallback = new Actions.GetCountFromActualTypeCallback();
            getCountFromActualTypeCallback.Invoke <TContainer>();
            getCountFromActualTypeCallback.Invoke <TValue>();
            Actions.GetCountAtPathGetter <TContainer> getCountAtPathGetter = new Actions.GetCountAtPathGetter <TContainer>();
            Actions.VisitAtPathCallback visitAtPathCallback = default;
            visitAtPathCallback.Invoke <TContainer>();
            visitAtPathCallback.Invoke <TValue>();
            Actions.SetCountCallback setCountCallback = default;
            setCountCallback.Invoke <TContainer>();
            setCountCallback.Invoke <TValue>();

            Actions.TryGetCount(ref container, new PropertyPath(), 0, ref changeTracker, out var count);
            Actions.TryGetCountImpl(ref container, new PropertyPath(), 0, ref changeTracker, out var otherCount);
            Actions.GetCount(ref container, new PropertyPath(), 0, ref changeTracker);
        }
コード例 #20
0
        public override void ActivateInstance(object proxyInstance, object originalInstance, IActionConfiguration actionConfiguration)
        {
            var aggregateFieldInfo = proxyInstance.GetType().GetField(PropertyVisitor.PropertyFieldName(_propertyName),
                                                                      BindingFlags.NonPublic |
                                                                      BindingFlags.Instance);

            if (aggregateFieldInfo == null)
            {
                throw new Exception("Unable to activate instance");
            }

            aggregateFieldInfo.SetValue(proxyInstance, originalInstance);
        }
コード例 #21
0
 void ProcessNestedAttributes(string nestedName, PropertyVisitor parentProperty)
 {
     foreach (var propertyInfo in GetProperties(parentProperty.PropertyInfo.PropertyType, 0))
     {
         var attributes = propertyInfo.GetCustomAttributes(typeof(XmlAttributeAttribute), false);
         if (attributes.Length != 0)
         {
             var attribute_attribute = (XmlAttributeAttribute)attributes[0];
             var name = string.IsNullOrEmpty(attribute_attribute.Name)
                 ? propertyInfo.Name
                 : attribute_attribute.Name;
             var id = PropertyName.CreateForAttribute(name, attribute_attribute.Prefix, nestedName);
             properties[id] = new NestedValuePropertyVisitor(
                 parentProperty, attribute_attribute.OmitIfNull, propertyInfo);
         }
     }
 }
コード例 #22
0
 public abstract override int Visit(PropertyVisitor visitor);
コード例 #23
0
 internal static ExcludeContext <TContainer, TValue> FromProperty(
     PropertyVisitor visitor,
     Property <TContainer, TValue> property)
 {
     return(new ExcludeContext <TContainer, TValue>(visitor, property));
 }
コード例 #24
0
 public static PropertyVisitor WithAdapter <TAdapter>(this PropertyVisitor visitor)
     where TAdapter : IPropertyVisitorAdapter, new()
 {
     visitor.AddAdapter(new TAdapter());
     return(visitor);
 }
コード例 #25
0
 void ProcessNestedAttributes (string nestedName, PropertyVisitor parentProperty)
 {
     foreach (var propertyInfo in GetProperties (parentProperty.PropertyInfo.PropertyType, 0)) {
         var attributes = propertyInfo.GetCustomAttributes (typeof (XmlAttributeAttribute), false);
         if (attributes.Length != 0) {
             var attribute_attribute = (XmlAttributeAttribute)attributes[0];
             var name = string.IsNullOrEmpty (attribute_attribute.Name)
                 ? propertyInfo.Name
                 : attribute_attribute.Name;
             var id = PropertyName.CreateForAttribute (name, attribute_attribute.Prefix, nestedName);
             properties[id] = new NestedValuePropertyVisitor (
                 parentProperty, attribute_attribute.OmitIfNull, propertyInfo);
         }
     }
 }
コード例 #26
0
 internal PropertyTransformation(IModelObject instance, Expression propertyPicker, object value = null)
     : this(instance.Id, instance.GetDataPath(), PropertyVisitor.ExtractProperty(propertyPicker), value)
 {
 }
コード例 #27
0
 public NestedValuePropertyVisitor (PropertyVisitor parentPropertyVisitor,
                                    bool omitIfNull,
                                    PropertyInfo propertyInfo)
     : base (omitIfNull, propertyInfo)
 {
     this.parent_property_visitor = parentPropertyVisitor;
 }
コード例 #28
0
 ExcludeContext(PropertyVisitor visitor, Property <TContainer, TValue> property)
 {
     m_Visitor = visitor;
     Property  = property;
 }
コード例 #29
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            Expression expression = base.Visit(node.Arguments[0]);

            if (node.Method.DeclaringType == typeof(EntityFrameworkQueryableExtensions))
            {
                if (node.Method.Name == nameof(EntityFrameworkQueryableExtensions.Include) ||
                    node.Method.Name == nameof(EntityFrameworkQueryableExtensions.ThenInclude))
                {
                    var visitor = new PropertyVisitor(_isDatabaseNullHighestValue);
                    visitor.Visit(node.Arguments[1]);

                    if (_metadataProvider.IsNotMapped((PropertyInfo)visitor.PropertyExpression.Member))
                    {
                        _includes.Add(new EfInclude(visitor.PropertyExpression.Member as PropertyInfo, visitor.Filter, visitor.IsOrdered));
                        return(node.Arguments[0]);
                    }

                    if (visitor.Filter == null)
                    {
                        node = Expression.Call(null, node.Method, new Expression[] { expression, node.Arguments[1] });
                    }
                    else
                    {
                        Type       entityType = node.Method.GetGenericArguments()[0];
                        MethodInfo method;
                        if (node.Method.Name == nameof(EntityFrameworkQueryableExtensions.Include))
                        {
                            method = node.Method.GetGenericMethodDefinition().MakeGenericMethod(entityType, visitor.PropertyExpression.Type);
                        }
                        else
                        {
                            Type previousPropertyType = node.Method.GetGenericArguments()[1];
                            method = node.Method.GetGenericMethodDefinition().MakeGenericMethod(entityType, previousPropertyType, visitor.PropertyExpression.Type);
                        }
                        LambdaExpression lambda = Expression.Lambda(visitor.PropertyExpression, visitor.Parameter);
                        node = Expression.Call(null, method, new Expression[] { expression, lambda });
                    }

                    PropertyInfo parentProperty = null;
                    if (node.Method.Name == nameof(EntityFrameworkQueryableExtensions.ThenInclude))
                    {
                        var parentVisitor = new PropertyVisitor(_isDatabaseNullHighestValue);
                        parentVisitor.Visit(node.Arguments[0]);
                        parentProperty = parentVisitor.PropertyExpression.Member as PropertyInfo;
                    }

                    _includes.Add(new EfInclude(visitor.PropertyExpression.Member as PropertyInfo, visitor.Filter, visitor.IsOrdered, parentProperty));
                    return(node);
                }
            }
            else if (node.Method.DeclaringType == typeof(Queryable) && node.Method.Name == nameof(Queryable.Select))
            {
                var visitor = new NewVisitor();
                visitor.Visit(node.Arguments[1]);
                _includes.AddRange(visitor.SelectProperties.Select(p => new EfInclude(p, null, false)));
            }
            else if (node.Method.DeclaringType == typeof(Queryable) && node.Method.Name == nameof(Queryable.GroupJoin))
            {
                Type outerType = node.Arguments[0].Type.GetGenericArguments()[0];
                Type innerType = node.Arguments[1].Type.GetGenericArguments()[0];

                List <PropertyInfo> navigationProperties = outerType.GetProperties().Where(p => p.PropertyType == innerType).ToList();
                if (navigationProperties.Count == 0)
                {
                    Type         collectionType     = typeof(IEnumerable <>).MakeGenericType(innerType);
                    PropertyInfo navigationProperty = outerType.GetProperties().Where(p => collectionType.IsAssignableFrom(p.PropertyType)).Single();
                    _includes.Add(new EfInclude(navigationProperty, null, false));
                }
                else if (navigationProperties.Count == 1)
                {
                    _includes.Add(new EfInclude(navigationProperties[0], null, false));
                }
                else
                {
                    LambdaExpression outerKeySelector;
                    if (node.Arguments[2] is UnaryExpression unaryExpression)
                    {
                        outerKeySelector = (LambdaExpression)unaryExpression.Operand;
                    }
                    else
                    {
                        outerKeySelector = (LambdaExpression)node.Arguments[2];
                    }

                    if (outerKeySelector.Body is MemberExpression propertyExpression)
                    {
                        PropertyInfo navigationProperty = _metadataProvider.GetForeignKey((PropertyInfo)propertyExpression.Member).Single();
                        _includes.Add(new EfInclude(navigationProperty, null, false));
                    }
                    else if (outerKeySelector.Body is NewExpression newExpression)
                    {
                        List <PropertyInfo> properties = newExpression.Arguments.Select(a => (PropertyInfo)((MemberExpression)a).Member).ToList();
                        foreach (PropertyInfo navigationProperty in navigationProperties)
                        {
                            PropertyInfo[] structuralProperties = _metadataProvider.GetForeignKey(navigationProperty);
                            if (!structuralProperties.Except(properties).Any())
                            {
                                _includes.Add(new EfInclude(navigationProperty, null, false));
                                break;
                            }
                        }
                    }
                }
            }

            var arguments = new Expression[node.Arguments.Count];

            node.Arguments.CopyTo(arguments, 0);
            arguments[0] = expression;
            return(Expression.Call(node.Object, node.Method, arguments));
        }
コード例 #30
0
        public override void Configure(ITypeBuilderContainer container)
        {
            var propertyVisitior = new PropertyVisitor(_propertyType, _propertyName);

            container.AddVisitor(propertyVisitior);
        }
コード例 #31
0
        protected void WriteGlyphProperties(XmlTextWriter writer, IGlyph glyph)
        {
            IGlyphVisitor visitor = new PropertyVisitor(writer);

            glyph.Accept(visitor);
        }
コード例 #32
0
 public override int Visit(PropertyVisitor visitor)
 {
     return(visitor.Visit(this));
 }
コード例 #33
0
 protected void WriteGlyphProperties(XmlTextWriter writer, IGlyph glyph)
 {
     IGlyphVisitor visitor = new PropertyVisitor (writer);
     glyph.Accept (visitor);
 }