Пример #1
0
        public ValueCalculatorFactory(ITypeConverter typeConverter)
        {
            if (typeConverter == null)
                throw new ArgumentNullException("typeConverter");

            _typeConverter = typeConverter;
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileFieldMapping"/> class.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <param name="nameExpression">
        /// The name expression.
        /// </param>
        /// <param name="contentExpression">
        /// The content expression.
        /// </param>
        /// <param name="locationExpression">
        /// The location expression.
        /// </param>
        /// <param name="typeConverter">
        /// The type converter.
        /// </param>
        /// <param name="fileManager">
        /// The file manager.
        /// </param>
        public FileFieldMapping(
            PropertyInfo property,
            MappingExpression nameExpression,
            MappingExpression contentExpression,
            MappingExpression locationExpression,
            ITypeConverter typeConverter,
            IFileManager fileManager)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            if (!typeof(IFileProcess).IsAssignableFrom(property.PropertyType))
                throw new ArgumentException("The specified property is not a file field.");

            if (typeConverter == null)
                throw new ArgumentNullException("typeConverter");

            if (fileManager == null)
                throw new ArgumentNullException("fileManager");

            _property = property;
            _nameExpression = nameExpression;
            _contentExpression = contentExpression;
            _locationExpression = locationExpression;
            _typeConverter = typeConverter;
            _fileManager = fileManager;
        }
Пример #3
0
		protected override void Init()
		{
			converter = Kernel.GetConversionManager();
			Kernel.ComponentModelBuilder.AddContributor(new StartableContributor(converter));

			InitFlag(flag ?? new LegacyStartFlag(), new StartableEvents(Kernel));
		}
Пример #4
0
        public static IDictionary<string, object> FormatParameters(
            IList<CommandActionParameter> source,
            IList<ParameterDescription> description,
            ITypeConverter converter)
        {
            // Determine parameter values
            Dictionary<string, object> result = new Dictionary<string, object>();

            foreach (CommandActionParameter param in source)
            {
                string name = param.Name;
                object value = param.Value;

                // Find the description of the parameter
                ParameterDescription expectedParam =
                    description.FirstOrDefault(p => p.Name == name);

                // Custom conversion
                value = converter.ConvertClrObject(value, expectedParam.Type);

                result.Add(name, value);
            }

            return result;
        }
		protected override void Init()
		{
			converter = (ITypeConverter) Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey);

			Kernel.ComponentModelCreated +=OnComponentModelCreated;
			Kernel.ComponentRegistered +=OnComponentRegistered;
		}
		protected virtual void AddFactories(IConfiguration facilityConfig, ITypeConverter converter)
		{
			if (facilityConfig != null)
			{
				foreach(IConfiguration config in facilityConfig.Children["factories"].Children)
				{
					String id = config.Attributes["id"];
					String creation = config.Attributes["creation"];
					String destruction = config.Attributes["destruction"];

					Type factoryType = (Type)
						converter.PerformConversion( config.Attributes["interface"], typeof(Type) );

					try
					{
						AddTypedFactoryEntry( 
							new FactoryEntry(id, factoryType, creation, destruction) );
					}
					catch(Exception)
					{
						string message = "Invalid factory entry in configuration";

						throw new ConfigurationErrorsException(message);
					}
				}
			}
		}
        public ValueBuilder(CultureInfo cultureInfo, ITypeConverter typeConverter)
        {
            // register custom BooleanTypeConverter, this might be a bad idea.
            TypeConverterAttribute converterAttribute = new TypeConverterAttribute(typeof(CustomBooleanConverter));
            _typeDescriptorProvider = TypeDescriptor.AddAttributes(typeof(Boolean), converterAttribute);

            this._typeConverter = typeConverter;
            this._culture = cultureInfo;
            this._errorCollector = null;
            this._targetType = new Stack<Type>();
            this._errorHandlers = new Stack<EventHandler<ErrorEventArg>>();
            this.ResolveInterfaceType +=
                (sender, args) =>
                {
                    if (args.RealType != null)
                        return;

                    if (typeof(IEnumerable) == args.InterfaceType)
                        args.RealType = typeof(List<object>);
                    else
                    {
                        Type[] genArgs;
                        if (args.InterfaceType.IsOfGenericType(typeof(IEnumerable<>), out genArgs))
                            args.RealType = typeof(List<>).MakeGenericType(genArgs);
                        if (args.InterfaceType.IsOfGenericType(typeof(IList<>), out genArgs))
                            args.RealType = typeof(List<>).MakeGenericType(genArgs);
                        else if (args.InterfaceType.IsOfGenericType(typeof(IDictionary<,>), out genArgs))
                            args.RealType = typeof(Dictionary<,>).MakeGenericType(genArgs);
                        else if (args.InterfaceType.IsOfGenericType(typeof(ILookup<,>), out genArgs))
                            args.RealType = typeof(Lookup<,>).MakeGenericType(genArgs);
                    }
                };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SingleCrossReferenceFieldMapping"/> class.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <param name="valueExpression">
        /// The value expression.
        /// </param>
        /// <param name="isKey">
        /// Specifies whether this is a key mapping.
        /// </param>
        /// <param name="typeConverter">
        /// The type converter.
        /// </param>
        /// <param name="dynamicTypeManager">
        /// The dynamic type manager.
        /// </param>
        /// <param name="runtimeDatabase">
        /// The runtime database.
        /// </param>
        /// <param name="childMappings">
        /// The child mappings.
        /// </param>
        public SingleCrossReferenceFieldMapping(
            PropertyInfo property,
            MappingExpression valueExpression,
            bool isKey,
            ITypeConverter typeConverter,
            IDynamicTypeManager dynamicTypeManager,
            IRuntimeDatabase runtimeDatabase,
            IEnumerable<IProcessFieldMapping> childMappings)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            var crAttribute = property.GetCustomAttribute<CrossRefFieldAttribute>();
            if (crAttribute == null || crAttribute.AllowMultiple || !typeof(int?).IsAssignableFrom(property.PropertyType))
                throw new ArgumentException("The specified property is not a single cross reference field.");

            if (typeConverter == null)
                throw new ArgumentNullException("typeConverter");

            if (dynamicTypeManager == null)
                throw new ArgumentNullException("dynamicTypeManager");

            if (runtimeDatabase == null)
                throw new ArgumentNullException("runtimeDatabase");

            _property = property;
            _valueExpression = valueExpression;
            _isKey = isKey;
            _typeConverter = typeConverter;
            _dynamicTypeManager = dynamicTypeManager;
            _runtimeDatabase = runtimeDatabase;
            _childMappings = (childMappings ?? Enumerable.Empty<IProcessFieldMapping>()).ToArray();
            _referencedProcessName = crAttribute.ReferenceTableName;
        }
Пример #9
0
        public DbContainer(DbContainerParameters parameters)
        {
            this.parameters = parameters;

            this.logger = new Logger();
            this.transformCache = new ConcurrentDictionary<string, IStoredProcedure>();
            this.converter = new DefaultTypeConverter();
        }
Пример #10
0
 public static ITypeConverter Combine(ICustomAttributeProvider attributeProvider, ITypeConverter typeConverter)
 {
     var results = GetTypeConverters(attributeProvider);
     if (!results.Any())
         return typeConverter;
     else
         return new CombinedTypeConverter(results.Concat(new[] { typeConverter }).ToArray());
 }
Пример #11
0
 public bool TryConvertTo(ITypeConverter root, TypeConversionContext context, Type convertTo, object value, out object result)
 {
     if ((Context & context) == context)
     {
         return Converter.TryConvertTo(root, context, convertTo, value, out result);
     }
     result = null;
     return false;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public CollectionConverterFixture()
        {
            this.converter = new CollectionConverter();
            this.context = new BindingContext() { TypeConverters = new[] { new FallbackConverter() } };

            this.mockStringTypeConverter = A.Fake<ITypeConverter>();
            A.CallTo(() => mockStringTypeConverter.CanConvertTo(null, null)).WithAnyArguments().Returns(true);
            A.CallTo(() => mockStringTypeConverter.Convert(null, null, null)).WithAnyArguments().Returns(string.Empty);
        }
 public bool TryConvertTo(ITypeConverter root, TypeConversionContext context, Type convertTo, object value, out object result)
 {
     if (convertTo == typeof(string[]) && (value?.GetType().IsArray ?? false))
     {
         result = new[] { string.Join(",", ((Array)value).Cast<object>().Select(x => root.ConvertTo<string>(context, x))) };
         return true;
     }
     result = null;
     return false;
 }
 public void AddConverter(ITypeConverter converter, int? index = null)
 {
     using (_lock.EnterWriteScope())
     {
         if (index != null)
             _converters.Insert(index.Value, converter);
         else
             _converters.Add(converter);
     }
 }
Пример #15
0
 public NullableConverter(Type type)
 {
     this.nullableType = type;
     this.simpleType = Nullable.GetUnderlyingType(type);
     if (this.simpleType == null)
     {
         throw new ArgumentException(TC.NullableConverterBadCtorArg, "type");
     }
     this.simpleTypeConverter = TypeConverterRegistry.GetConverter(this.simpleType);
 }
Пример #16
0
		/// <summary>
		///   Initializes a new instance of the <see cref = "RemotingInspector" /> class.
		/// </summary>
		/// <param name = "converter">The converter.</param>
		/// <param name = "isServer">if set to <c>true</c> is a server.</param>
		/// <param name = "isClient">if set to <c>true</c> is a client.</param>
		/// <param name = "baseUri">The base URI.</param>
		/// <param name = "remoteRegistry">The remote registry.</param>
		/// <param name = "localRegistry">The local registry.</param>
		public RemotingInspector(ITypeConverter converter, bool isServer, bool isClient,
		                         String baseUri, RemotingRegistry remoteRegistry, RemotingRegistry localRegistry)
		{
			this.converter = converter;
			this.isServer = isServer;
			this.isClient = isClient;
			this.baseUri = baseUri;
			this.remoteRegistry = remoteRegistry;
			this.localRegistry = localRegistry;
		}
        public XmlSerializableDeserializerSelector(ICompositeObjectContextFactory objectContextFactory, ITypeConverter typeConverter)
        {
            if (objectContextFactory == null)
                throw new ArgumentNullException("objectContextFactory");
            if (typeConverter == null)
                throw new ArgumentNullException("typeConverter");

            _deserializer = new XmlSerializableDeserializer(objectContextFactory, typeConverter);
            _typeConverter = typeConverter;
        }
Пример #18
0
 public bool TryConvertTo(ITypeConverter root, TypeConversionContext context, Type convertTo, object value, out object result)
 {
     if (convertTo.IsInstanceOfType(value))
     {
         result = value;
         return true;
     }
     result = null;
     return false;
 }
Пример #19
0
 public bool TryConvertTo(ITypeConverter root, TypeConversionContext context, Type convertTo, object value, out object result)
 {
     foreach (var typeConverter in typeConverters)
     {
         if (typeConverter.TryConvertTo(root, context, convertTo, value, out result))
             return true;
     }
     result = null;
     return false;
 }
Пример #20
0
 public NullableConverter(Type type)
 {
     this.nullableType = type;
     this.simpleType = Nullable.GetUnderlyingType(type);
     if (this.simpleType == null)
     {
         throw new ArgumentException("The specified type is not a nullable type.", "type");
     }
     this.simpleTypeConverter = TypeConverterRegistry.GetConverter(this.simpleType);
 }
Пример #21
0
        public CanonicalFunctionMapper(ITypeConverter converter)
        {
            this.converter = new EdmTypeConverter(converter);
            this.mappings = new Dictionary<string, Func<EdmFunction, Expression[], Expression>>();

            this.AddStringMappings();
            this.AddDateTimeMappings();
            this.AddMathMappings();
            this.AddBitwiseMappings();
            this.AddMiscMappings();
        }
Пример #22
0
		/// <summary>
		/// Creates a new <see cref="NullableConverter"/> for the given <see cref="Nullable{T}"/> <see cref="Type"/>.
		/// </summary>
		/// <param name="type">The nullable type.</param>
		/// <exception cref="System.ArgumentException">type is not a nullable type.</exception>
		public NullableConverter( Type type )
		{
			NullableType = type;
			UnderlyingType = Nullable.GetUnderlyingType( type );
			if( UnderlyingType == null )
			{
				throw new ArgumentException( "type is not a nullable type." );
			}

			UnderlyingTypeConverter = TypeConverterFactory.GetConverter( UnderlyingType );
		}
Пример #23
0
		public void Add(ITypeConverter converter)
		{
			converter.Context = this;

			converters.Add(converter);

			if (!(converter is IKernelDependentConverter))
			{
				standAloneConverters.Add(converter);
			}
		}
Пример #24
0
 public object GetField(string name, object ifNull, ITypeConverter converter)
 {
     var v = GetField(name, converter);
     if (v == null || v == DBNull.Value)
     {
         return ifNull;
     }
     else
     {
         return v;
     }
 }
Пример #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleValueCalculator"/> class.
        /// </summary>
        /// <param name="valueExpression">
        /// The value expression.
        /// </param>
        /// <param name="valueType">
        /// The value type.
        /// </param>
        /// <param name="typeConverter">
        /// The type converter.
        /// </param>
        public SimpleValueCalculator(MappingExpression valueExpression, Type valueType, ITypeConverter typeConverter)
        {
            if (valueType == null)
                throw new ArgumentNullException("valueType");

            if (typeConverter == null)
                throw new ArgumentNullException("typeConverter");

            _valueExpression = valueExpression;
            _valueType = valueType;
            _typeConverter = typeConverter;
        }
		protected override void Init()
		{
			converter = (ITypeConverter)Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey);
			Kernel.ComponentModelBuilder.AddContributor(new StartableContributor(converter));
			if(optimizeForSingleInstall)
			{
				Kernel.HandlersChanged += StartAll;
				Kernel.ComponentRegistered += CacheForStart;
				return;
			}
			Kernel.ComponentRegistered +=OnComponentRegistered;
		}
		protected override void Init()
		{
			converter = Kernel.GetConversionManager();
			Kernel.ComponentModelBuilder.AddContributor(new StartableContributor(converter));
			if (optimizeForSingleInstall)
			{
				Kernel.RegistrationCompleted += StartAll;
				Kernel.ComponentRegistered += CacheForStart;
				return;
			}
			Kernel.ComponentRegistered += OnComponentRegistered;
		}
        public DataContextChangeSynchronizer(BindingSource bindingSource, BindingTarget bindingTarget, ITypeConverterProvider typeConverterProvider)
        {
            _bindingTarget = bindingTarget;
            Guard.ThrowIfNull(bindingTarget.Object, nameof(bindingTarget.Object));
            Guard.ThrowIfNull(bindingTarget.Property, nameof(bindingTarget.Property));
            Guard.ThrowIfNull(bindingSource.SourcePropertyPath, nameof(bindingSource.SourcePropertyPath));
            Guard.ThrowIfNull(bindingSource.Source, nameof(bindingSource.Source));
            Guard.ThrowIfNull(typeConverterProvider, nameof(typeConverterProvider));

            _bindingEndpoint = new TargetBindingEndpoint(bindingTarget.Object, bindingTarget.Property);
            _sourceEndpoint = new ObservablePropertyBranch(bindingSource.Source, bindingSource.SourcePropertyPath);
            _targetPropertyTypeConverter = typeConverterProvider.GetTypeConverter(bindingTarget.Property.PropertyType);
        }
Пример #29
0
 public bool TryConvertTo(ITypeConverter root, TypeConversionContext context, Type convertTo, object obj, out object result)
 {
     try
     {
         result = Convert.ChangeType(obj, convertTo);
         return true;
     }
     catch (Exception)
     {
         result = null;
         return false;
     }
 }
Пример #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArrayValueCalculator"/> class.
        /// </summary>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <param name="valueExpression">
        /// The value expression.
        /// </param>
        /// <param name="elementCalculator">
        /// The element calculator.
        /// </param>
        /// <param name="typeConverter">
        /// The type converter.
        /// </param>
        public ArrayValueCalculator(Type elementType, MappingExpression valueExpression, IValueCalculator elementCalculator, ITypeConverter typeConverter)
        {
            if (elementType == null)
                throw new ArgumentNullException("elementType");

            if (typeConverter == null)
                throw new ArgumentNullException("typeConverter");

            _typeConverter = typeConverter;
            _elementType = elementType;
            _valueExpression = valueExpression;
            _elementCalculator = elementCalculator;
        }
Пример #31
0
 private void SetUpTypeConverter()
 {
     converter = Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey) as IConversionManager;
 }
Пример #32
0
 /// <summary>
 /// Specifies the <see cref="TypeConverter"/> to use
 /// when converting the property to and from a CSV field.
 /// </summary>
 /// <param name="typeConverter">The TypeConverter to use.</param>
 public virtual CsvPropertyMap TypeConverter(ITypeConverter typeConverter)
 {
     Data.TypeConverter = typeConverter;
     return(this);
 }
Пример #33
0
 /// <summary>
 /// Gets the type of this type instance using the specified type converter.
 /// </summary>
 /// <param name="typeConverter">The type converter interface.</param>
 public override Type GetType(ITypeConverter typeConverter)
 {
     return(typeConverter.GetType(UserType));
 }
Пример #34
0
 public OperatorSetBuilder <TToken> TypeConverter <TSelf>(Action <ITypeConverter> configureConverter)
 {
     _converter = new CustomTypeConverter <TSelf>();
     configureConverter(_converter);
     return(this);
 }
 public static void ConfigureConverters(ITypeConverter obj)
 {
     obj.Register((object o, out long r) => CoreConverters.TryHexConvert("&H", obj, o, out r) || obj.TryCoreConvert(o, out r))
     .Register((object o, out int r) => CoreConverters.TryHexConvert("&H", obj, o, out r) || obj.TryCoreConvert(o, out r));
 }
Пример #36
0
        /// <summary>
        /// Specifies the <see cref="TypeConverter"/> to use
        /// when converting the member to and from a CSV field.
        /// </summary>
        /// <param name="typeConverter">The TypeConverter to use.</param>
        public virtual MemberMap TypeConverter(ITypeConverter typeConverter)
        {
            Data.TypeConverter = typeConverter;

            return(this);
        }
Пример #37
0
 internal ValuesPopulator(ITypePropertiesExtractor typePropertiesExtractor, ITypeConverter typeConverter)
 {
     _typePropertiesExtractor = typePropertiesExtractor;
     _typeConverter           = typeConverter;
 }
Пример #38
0
 public DictionaryToObjectConverter(ITypeConverter converter)
 {
     _converter = converter ?? throw new ArgumentNullException(nameof(converter));
 }
Пример #39
0
 public static object ConvertTo(this ITypeConverter converter, object value, Type to)
 {
     return(converter.ConvertTo(CultureInfo.InvariantCulture, null, value, to));
 }
Пример #40
0
 public static object ConvertFrom(this ITypeConverter converter, object value)
 {
     return(converter.ConvertFrom(CultureInfo.InvariantCulture, value));
 }
 public QueryableComparableNotEqualsHandler(
     ITypeConverter typeConverter,
     InputParser inputParser)
     : base(typeConverter, inputParser)
 {
 }
Пример #42
0
 public TypeConverterPropertyInitializerFactory(ITypeConverter <TProperty, TInputProperty> converter)
 {
     _converter = converter;
 }
Пример #43
0
        public bool IsPropertyTypeConverter <T>(out ITypeConverter <TProperty, T> typeConverter)
        {
            typeConverter = _converter as ITypeConverter <TProperty, T>;

            return(typeConverter != null);
        }
Пример #44
0
 /// <summary>
 /// Sets a <see cref="ITypeConverter"/> instance to use when converting CLR types
 /// </summary>
 public Options SetTypeConverter(ITypeConverter typeConverter)
 {
     _typeConverter = typeConverter;
     return(this);
 }
 private static bool HasStatelessAttributeSet(ComponentModel model, ITypeConverter converter)
 {
     return(Helpers.IsFlag(model, converter, FacilityConstants.StatelessServiceKey));
 }
Пример #46
0
 public FallbackConverterFixture()
 {
     this.converter = new FallbackConverter();
 }
Пример #47
0
 public Parser(ITypeConverter typeConverter)
 {
     _typeConverter = typeConverter;
 }
Пример #48
0
 public CastingConverter(ITypeConverter <object> inner)
 {
     _inner = inner;
 }
Пример #49
0
 public CsvPropertyMapping(Expression <Func <TEntity, TProperty> > property, ITypeConverter <TProperty> typeConverter)
 {
     propertyConverter = typeConverter;
     propertyName      = ReflectionUtils.GetPropertyNameFromExpression(property);
     propertySetter    = ReflectionUtils.CreateSetter <TEntity, TProperty>(property);
 }
Пример #50
0
 public void RegisterTypeConverter(Type type, ITypeConverter converter)
 {
     _typeConverters.Add(type, new TypeConverterRegistration(type, converter));
 }
Пример #51
0
        /// <summary>
        /// Create a new method expression.
        /// The expression must be an lvalue expression or literal text.
        /// The expected return type may be <code>null</code>, meaning "don't care".
        /// If it is an lvalue expression, the parameter types must not be <code>null</code>.
        /// If it is literal text, the expected return type must not be <code>void</code>. </summary>
        /// <param name="store"> used to get the parse tree from. </param>
        /// <param name="functions"> the function mapper used to bind functions </param>
        /// <param name="variables"> the variable mapper used to bind variables </param>
        /// <param name="expr"> the expression string </param>
        /// <param name="returnType"> the expected return type (may be <code>null</code>) </param>
        /// <param name="paramTypes"> the expected parameter types (must not be <code>null</code> for lvalues) </param>
        public TreeMethodExpression(TreeStore store, FunctionMapper functions, VariableMapper variables, ITypeConverter converter, string expr, Type returnType, Type[] paramTypes) : base()
        {
            Tree tree = store.Get(expr);

            this.builder  = store.Builder;
            this.bindings = tree.Bind(functions, variables, converter);
            this.expr     = expr;
            this.type     = returnType;
            this.types    = paramTypes;
            this.node     = tree.Root;
            this.deferred = tree.Deferred;

            if (node.LiteralText)
            {
                if (returnType == typeof(void))
                {
                    throw new ELException(LocalMessages.Get("error.method.literal.void", expr));
                }
            }
            else if (!node.MethodInvocation)
            {
                if (!node.LeftValue)
                {
                    throw new ELException(LocalMessages.Get("error.method.invalid", expr));
                }
                if (paramTypes == null)
                {
                    throw new ELException(LocalMessages.Get("error.method.notypes"));
                }
            }
        }
 public bool TryGetField <T>(string name, int index, ITypeConverter converter, out T field)
 {
     throw new NotImplementedException();
 }
Пример #53
0
 /// <summary>
 /// Gets the type of this type instance using the specified type converter.
 /// </summary>
 /// <param name="typeConverter">The type converter interface.</param>
 public override Type GetType(ITypeConverter typeConverter)
 {
     return(IsVariable ? typeof(Variable) : typeof(UserType));
 }
 public bool TryGetField(Type type, string name, int index, ITypeConverter converter, out object field)
 {
     throw new NotImplementedException();
 }
Пример #55
0
 public static ITypeConverter Add(this ITypeConverter current, ITypeConverter register)
 {
     return(new CompositeConverter(current, register));
 }
 public T GetField <T>(string name, int index, ITypeConverter converter)
 {
     throw new NotImplementedException();
 }
 public object GetField(Type type, string name, int index, ITypeConverter converter)
 {
     throw new NotImplementedException();
 }
Пример #58
0
 public QueryableEnumNotInHandler(
     ITypeConverter typeConverter)
     : base(typeConverter)
 {
 }
Пример #59
0
 public static void RegisterConverter <T>(ITypeConverter typeConverter)
 {
     RegisterConverter(typeof(T), typeConverter);
 }
Пример #60
0
 public static ITypeConverter RemoveConverter <T>(ITypeConverter typeConverter)
 {
     return(RemoveConverter(typeof(T)));
 }