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)); }
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)); }
public FallbackValueConverter(Type type) { if (type == null) { throw new ArgumentNullException(nameof(converter)); } converter = TypeDescriptor.GetConverter(type); if (!CanConvert) { converter = null; reflectionConverter = new ReflectionConverter(type); } }
/// <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 }); } }
public void ReflectionConverterShouldNotPassNullIntoContructorIfTargetTypeIsNotValueType() { var converter1 = new ReflectionConverter(); Assert.AreEqual(null, (FromString)converter1.Convert(null, typeof(FromString), null, null)); }