コード例 #1
0
        void ReflectionConverter_ConvertMethodParametersTestCore(string method, bool withParameter)
        {
            IValueConverter reflectionConverter = new ReflectionConverter()
            {
                ConvertMethodOwner = typeof(ReflectionConvertTestMockStatic), ConvertMethod = method
            };

            Assert.AreEqual(withParameter ? "36" : "22", reflectionConverter.Convert(22, typeof(string), 14, CultureInfo.InvariantCulture));
        }
コード例 #2
0
        void ReflectionConverter_ConvertMethodParametersTest(Action <Mock <IReflectionConverterTestMock> > setup, string method, bool withParameter)
        {
            var mock = new Mock <IReflectionConverterTestMock>(MockBehavior.Strict);

            ReflectionConvertTestMockStatic.Mock = mock.Object;
            setup(mock);
            IValueConverter reflectionConverter = new ReflectionConverter()
            {
                ConvertMethodOwner = typeof(ReflectionConvertTestMockStatic), ConvertMethod = method
            };

            Assert.AreEqual(withParameter ? "36" : "22", reflectionConverter.Convert(22, typeof(string), 14, CultureInfo.InvariantCulture));
        }
コード例 #3
0
        public FallbackValueConverter(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(converter));
            }

            converter = TypeDescriptor.GetConverter(type);

            if (!CanConvert)
            {
                converter           = null;
                reflectionConverter = new ReflectionConverter(type);
            }
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="builder"></param>
        public async void Configure(EntityTypeBuilder <Currency> builder)
        {
            var request = await CurrencyRate.GetExchangeRate();

            var rates = ReflectionConverter.GetPropertyValues(request.Rates);

            for (int i = 0; i <= rates.Count; i++)
            {
                var name  = ReflectionConverter.GetPropertyName(rates[i]);
                var value = ReflectionConverter.GetPropertyValue(request.Rates, name);

                builder.HasData(
                    new Currency {
                    Id = i + 1, Code = name
                });
            }
        }
コード例 #5
0
        public void ReflectionConverterShouldNotPassNullIntoContructorIfTargetTypeIsNotValueType()
        {
            var converter1 = new ReflectionConverter();

            Assert.AreEqual(null, (FromString)converter1.Convert(null, typeof(FromString), null, null));
        }