コード例 #1
0
        public bool TryGetPropertyInitializer <TProperty>(string propertyName, out IPropertyInitializer <TMessage, TInput> initializer)
        {
            var inputPropertyInfo = typeof(TInput).GetProperty(propertyName);

            if (inputPropertyInfo != null)
            {
                var propertyType      = typeof(TProperty);
                var inputPropertyType = inputPropertyInfo.PropertyType;

                // exactly the same type, we just copy it over unmodified
                if (inputPropertyType == propertyType)
                {
                    initializer = new CopyPropertyInitializer <TMessage, TInput, TProperty>(propertyName);
                    return(true);
                }

                // can only copy to object, no idea what the destination type would/could be
                if (propertyType == typeof(object))
                {
                    var type = typeof(CopyObjectPropertyInitializer <, ,>).MakeGenericType(typeof(TMessage), typeof(TInput), inputPropertyType);
                    initializer = (IPropertyInitializer <TMessage, TInput>)Activator.CreateInstance(type, propertyName, propertyName);
                    return(true);
                }

                if (PropertyInitializerCache.TryGetFactory <TProperty>(inputPropertyType, out var propertyConverter))
                {
                    initializer = propertyConverter.CreatePropertyInitializer <TMessage, TInput>(propertyName);
                    return(true);
                }
            }

            initializer = null;
            return(false);
        }
コード例 #2
0
        public bool TryGetPropertyInitializer <TProperty>(PropertyInfo propertyInfo, out IPropertyInitializer <TMessage, TInput> initializer)
        {
            var propertyName = propertyInfo?.Name ?? throw new ArgumentNullException(nameof(propertyInfo));

            if (_inputProperties.TryGetValue(propertyName, out var inputPropertyInfo))
            {
                var propertyType      = typeof(TProperty);
                var inputPropertyType = inputPropertyInfo.PropertyType;

                // exactly the same type, we just copy it over unmodified
                if (inputPropertyType == propertyType)
                {
                    initializer = new CopyPropertyInitializer <TMessage, TInput, TProperty>(propertyInfo, inputPropertyInfo);
                    return(true);
                }

                // can only copy to object, no idea what the destination type would/could be
                if (propertyType == typeof(object))
                {
                    var type = typeof(CopyObjectPropertyInitializer <, ,>).MakeGenericType(typeof(TMessage), typeof(TInput), inputPropertyType);
                    initializer = (IPropertyInitializer <TMessage, TInput>)Activator.CreateInstance(type, propertyInfo, inputPropertyInfo);
                    return(true);
                }

                if (_providerFactory.TryGetPropertyProvider(inputPropertyInfo, out IPropertyProvider <TInput, TProperty> provider))
                {
                    initializer = new ProviderPropertyInitializer <TMessage, TInput, TProperty>(provider, propertyInfo);
                    return(true);
                }
            }

            initializer = null;
            return(false);
        }
コード例 #3
0
        public override void VisitPropertyInitializer(IPropertyInitializer operation)
        {
            LogString(nameof(IPropertyInitializer));
            LogSymbol(operation.InitializedProperty, header: " (Property");
            LogString(")");
            LogCommonPropertiesAndNewLine(operation);

            base.VisitPropertyInitializer(operation);
        }
コード例 #4
0
        public bool TryGetPropertyInitializer <TProperty>(PropertyInfo propertyInfo, out IPropertyInitializer <TMessage, TMessage> initializer)
        {
            if (_initializers.TryGetValue(propertyInfo.Name, out initializer))
            {
                return(true);
            }

            initializer = default;
            return(false);
        }
コード例 #5
0
        public bool TryGetPropertyInitializer <TProperty>(PropertyInfo propertyInfo, out IPropertyInitializer <TMessage, TInput> initializer)
        {
            var key = propertyInfo?.Name ?? throw new ArgumentNullException(nameof(propertyInfo));

            if (typeof(TValue) == typeof(TProperty))
            {
                initializer = new DictionaryCopyPropertyInitializer <TMessage, TInput, TValue>(propertyInfo, key);
                return(true);
            }

            if (_providerFactory.TryGetPropertyConverter(out IPropertyConverter <TProperty, TValue> converter))
            {
                var providerType = typeof(InputDictionaryPropertyProvider <,>).MakeGenericType(typeof(TInput), typeof(TValue));

                var provider = (IPropertyProvider <TInput, TValue>)Activator.CreateInstance(providerType, key);

                var convertProvider = new PropertyConverterPropertyProvider <TInput, TProperty, TValue>(converter, provider);

                initializer = new ProviderPropertyInitializer <TMessage, TInput, TProperty>(convertProvider, propertyInfo);
                return(true);
            }

            if (typeof(TValue) == typeof(object))
            {
                var inputProviderType = typeof(InputDictionaryPropertyProvider <,>).MakeGenericType(typeof(TInput), typeof(TValue));

                var valueProvider = (IPropertyProvider <TInput, TValue>)Activator.CreateInstance(inputProviderType, key);

                var providerType = typeof(ObjectPropertyProvider <,>).MakeGenericType(typeof(TInput), typeof(TProperty));

                var provider = (IPropertyProvider <TInput, TProperty>)Activator.CreateInstance(providerType, _providerFactory, valueProvider);

                initializer = new ProviderPropertyInitializer <TMessage, TInput, TProperty>(provider, propertyInfo);
                return(true);
            }

            initializer = null;
            return(false);
        }
コード例 #6
0
        bool IInitializerConvention.TryGetPropertyInitializer <T, TInput, TProperty>(PropertyInfo propertyInfo, out IPropertyInitializer <T, TInput> initializer)
        {
            if (this is IInitializerConvention <T, TInput> convention)
            {
                return(convention.TryGetPropertyInitializer <TProperty>(propertyInfo, out initializer));
            }

            initializer = default;
            return(false);
        }
コード例 #7
0
 public void Add(string propertyName, IPropertyInitializer <TMessage, TMessage> initializer)
 {
     _initializers.Add(propertyName, initializer);
 }
コード例 #8
0
 public PropertyAdapter(IPropertyInitializer <TMessage> initializer)
 {
     _initializer = initializer;
 }
コード例 #9
0
 public virtual void VisitPropertyInitializer(IPropertyInitializer operation)
 {
     DefaultVisit(operation);
 }
コード例 #10
0
 public void Add(string propertyName, IPropertyInitializer <TMessage> initializer)
 {
     _initializers[propertyName] = new PropertyAdapter(initializer);
 }
コード例 #11
0
 public void Add(string propertyName, IPropertyInitializer <TMessage, TInput> initializer)
 {
     _initializers[propertyName] = initializer;
 }
コード例 #12
0
        public override void VisitPropertyInitializer(IPropertyInitializer operation)
        {
            var initializedProperty = operation.InitializedProperty;

            base.VisitPropertyInitializer(operation);
        }
コード例 #13
0
 public virtual void VisitPropertyInitializer(IPropertyInitializer operation)
 {
     DefaultVisit(operation);
 }
コード例 #14
0
 public bool TryGetPropertyInitializer <TInput, TProperty>(PropertyInfo propertyInfo, out IPropertyInitializer <TMessage, TInput> initializer)
     where TInput : class
 {
     return(_typeCache.GetOrAdd <TInput, IInitializerConvention <TMessage, TInput> >().TryGetPropertyInitializer <TProperty>(propertyInfo, out initializer));
 }
コード例 #15
0
 public override void VisitPropertyInitializer(IPropertyInitializer operation)
 {
     Visit(operation.Value);
 }
コード例 #16
0
 public bool TryGetPropertyInitializer <TProperty>(PropertyInfo propertyInfo, out IPropertyInitializer <TMessage, TInput> initializer)
 {
     initializer = default;
     return(false);
 }
コード例 #17
0
 /// <inheritdoc />
 public override IOperation VisitPropertyInitializer(IPropertyInitializer operation, object argument)
 {
     return(base.VisitPropertyInitializer(operation, argument));
 }
コード例 #18
0
 /// <inheritdoc />
 public override Expression VisitPropertyInitializer(IPropertyInitializer operation, LocalBinder argument)
 {
     return(base.VisitPropertyInitializer(operation, argument));
 }
コード例 #19
0
 public override IOperation VisitPropertyInitializer(IPropertyInitializer operation, object argument)
 {
     return(new PropertyInitializer(operation.InitializedProperty, Visit(operation.Value), operation.Kind, ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit));
 }
コード例 #20
0
ファイル: TestOperationWalker.cs プロジェクト: CAPCHIK/roslyn
        public override void VisitPropertyInitializer(IPropertyInitializer operation)
        {
            var initializedProperty = operation.InitializedProperty;

            base.VisitPropertyInitializer(operation);
        }