public void NullConverterAttributeException() { // Arrange ConverterAttribute converterAttribute = null; var expectedExceptionMessage = SourceParameterName; // Act var actualException = Assert.Throws <ArgumentNullException>(() => converterAttribute.BuildConverter()); // Assert Assert.Equal(expectedExceptionMessage, actualException.ParamName); }
public void Int32ConverterActivation() { // Arrange var expected = typeof(Int32Converter); var converterAttribute = new ConverterAttribute(expected); // Act var actual = converterAttribute.BuildConverter(); // Assert Assert.NotNull(actual); Assert.IsType <Int32Converter>(actual); }
private bool TryGetCustomConverter(Type type, out IJsonConverter customConverter) { if (!ConverterAttribute.IsDefined(type)) { customConverter = null !; return(false); } var customConverterType = type .GetCustomAttribute <ConverterAttribute>() .GetConverterType(type); var injections = new LocalList <object>(type, this); customConverter = (IJsonConverter)_services.Activate(customConverterType, injections); return(true); }
/// <summary> /// Initializes a new instance of the <see cref="SchemaAttributes"/> class. /// </summary> /// <param name="name">The name of the property that contains these attributes.</param> /// <param name="converter">The converter that defines how to convert from .NET to XLIFF.</param> /// <param name="defaultValue">The default .NET value of the property.</param> /// <param name="hasValueIndicator">The indicator that defines how to determine if the value has data.</param> /// <param name="schema">Defines how to map the property to XLIFF.</param> /// <param name="inheritanceList">A list that defines how to inherit the value from ancestors.</param> /// <param name="outputDependencies">A list of property names that, when written, must be accompanied by the /// property to which this attribute is applied.</param> public SchemaAttributes( string name, ConverterAttribute converter, DefaultValueAttribute defaultValue, HasValueIndicatorAttribute hasValueIndicator, SchemaEntityAttribute schema, IEnumerable <InheritValueAttribute> inheritanceList, IEnumerable <ExplicitOutputDependencyAttribute> outputDependencies) { this.Converter = converter; this.DefaultValue = defaultValue; this.ExplicitOutputDependencies = new List <ExplicitOutputDependencyAttribute>(outputDependencies); this.HasValueIndicator = hasValueIndicator; this.InheritanceList = new List <InheritValueAttribute>(inheritanceList); this.Name = name; this.Schema = schema; }
public static Dictionary <string, IPropertyConverter <T> > ActivatePropertyConverters <T>(IServiceProvider services) { var ownerType = Typeof <T> .Raw; var properties = ownerType.GetProperties(); var propertyConverters = new Dictionary <string, IPropertyConverter <T> >( properties.Length, StringUtils.IgnoreCaseComparer); var converters = (IConvertersCollection)services.GetService(typeof(IConvertersCollection)); foreach (var property in properties) { if (IgnoreAttribute.IsDefined(property)) { continue; } IPropertyConverter <T> propertyConverter; if (ConverterAttribute.IsDefined(property)) { var converterType = property .GetCustomAttribute <ConverterAttribute>() .GetConverterType(ownerType, property); var injections = new LocalList <object>(property, ownerType); propertyConverter = (IPropertyConverter <T>)services.Activate(converterType, injections); } else { propertyConverter = new PropertyConverter <T>(property, converters.Get(property.PropertyType)); } propertyConverters.Add(property.Name, propertyConverter); } return(propertyConverters); }
public void ConverterAttribute_Ctor() { ConverterAttribute instance; // // Test with null type. // try { instance = new ConverterAttribute(null); Assert.Fail("Expected ArgumentNullException to be thrown."); } catch (ArgumentNullException) { } // // Test with valid type. // instance = new ConverterAttribute(typeof(bool)); Assert.AreEqual(typeof(bool).FullName, instance.TypeName, "Name was not set properly."); }
public void Dispose() { ConverterAttribute.ClearCache(); }
private static void LogParamMissingConvInstance(MethodInfo method, ParameterInfo param, ConverterAttribute attr) { const GeneratorLogFlag code = GeneratorLogFlag.ParamMissingConverterInstance; if ((LogBuildWarnings & code) == code) { WebServerLog.Add( ServerLogType.Information, typeof(Generator), "generate class", "[{0:X4}] Method {1} ignored because parameter {2} has no converter instance set for attribute {3}", (int)code, method, param, attr ); } }
public PropertyPrimitiveAttribute(PropertyInfo p) { this.p = p; this.attr = (ConverterAttribute)p.GetCustomAttribute(typeof(ConverterAttribute), false); }