Ejemplo n.º 1
0
        static ImmutableBase()
        {
            ordinalIgnoreCase = StringComparer.OrdinalIgnoreCase;
            var propertiesByName = PropertyHelpers.GetPropertyMap <TImmutable>();

            var constructor =
                ConstructorHelpers
                .GetImmutableSetterConstructor <TImmutable>(propertiesByName);

            createImmutable = constructor.CreateArrayFunc <TImmutable>();

            var properties =
                constructor
                .GetParameters()
                .Select(parameter => propertiesByName[parameter.Name])
                .ToImmutableArray();

            var provider = AggregatePropertyHandlerProvider.Create(
                new StringPropertyHandlerProvider(),
                new SinglePropertyHandlerProvider(),
                new DoublePropertyHandlerProvider(),
                new NullablePropertyHandlerProvider <Single>(new SinglePropertyHandlerProvider()),
                new NullablePropertyHandlerProvider <Double>(new DoublePropertyHandlerProvider()),
                new EnumerablePropertyHandlerProvider(),
                new DefaultPropertyHandlerProvider()
                );

            var handlersBuilder       = ImmutableArray.CreateBuilder <IPropertyHandler>();
            var handlersByNameBuilder =
                ImmutableDictionary.CreateBuilder <String, IPropertyHandler>(ordinalIgnoreCase);

            foreach (var property in properties)
            {
                var handler = provider.Create(property);

                handlersBuilder.Add(handler);
                handlersByNameBuilder.Add(handler.PropertyName, handler);
            }

            handlers        = handlersBuilder.ToImmutable();
            handlersByName  = handlersByNameBuilder.ToImmutable();
            stringFormatter = new DefaultStringFormatter();
        }
Ejemplo n.º 2
0
        public void Create_NullInProviders()
        {
            // Act

            var exception = Record.Exception(
                () => AggregatePropertyHandlerProvider.Create(
                    new DefaultPropertyHandlerProvider(),
                    null,
                    new DefaultPropertyHandlerProvider()
                    )
                );

            // Assert

            Assert.IsType <ArgumentException>(exception);

            Assert.Equal(
                "One or more of the providers was null." +
                Environment.NewLine + "Parameter name: providers",
                exception.Message
                );
        }