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); }
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); }
public override void VisitPropertyInitializer(IPropertyInitializer operation) { LogString(nameof(IPropertyInitializer)); LogSymbol(operation.InitializedProperty, header: " (Property"); LogString(")"); LogCommonPropertiesAndNewLine(operation); base.VisitPropertyInitializer(operation); }
public bool TryGetPropertyInitializer <TProperty>(PropertyInfo propertyInfo, out IPropertyInitializer <TMessage, TMessage> initializer) { if (_initializers.TryGetValue(propertyInfo.Name, out initializer)) { return(true); } initializer = default; return(false); }
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); }
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); }
public void Add(string propertyName, IPropertyInitializer <TMessage, TMessage> initializer) { _initializers.Add(propertyName, initializer); }
public PropertyAdapter(IPropertyInitializer <TMessage> initializer) { _initializer = initializer; }
public virtual void VisitPropertyInitializer(IPropertyInitializer operation) { DefaultVisit(operation); }
public void Add(string propertyName, IPropertyInitializer <TMessage> initializer) { _initializers[propertyName] = new PropertyAdapter(initializer); }
public void Add(string propertyName, IPropertyInitializer <TMessage, TInput> initializer) { _initializers[propertyName] = initializer; }
public override void VisitPropertyInitializer(IPropertyInitializer operation) { var initializedProperty = operation.InitializedProperty; base.VisitPropertyInitializer(operation); }
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)); }
public override void VisitPropertyInitializer(IPropertyInitializer operation) { Visit(operation.Value); }
public bool TryGetPropertyInitializer <TProperty>(PropertyInfo propertyInfo, out IPropertyInitializer <TMessage, TInput> initializer) { initializer = default; return(false); }
/// <inheritdoc /> public override IOperation VisitPropertyInitializer(IPropertyInitializer operation, object argument) { return(base.VisitPropertyInitializer(operation, argument)); }
/// <inheritdoc /> public override Expression VisitPropertyInitializer(IPropertyInitializer operation, LocalBinder argument) { return(base.VisitPropertyInitializer(operation, argument)); }
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)); }