public StringMapTypeDeserializer(Type type) { this.type = type; if (type.IsOrHasGenericInterfaceTypeOf(typeof(IEnumerable <>))) { return; } foreach (var propertyInfo in type.GetProperties()) { var propertySetFn = JsvDeserializeType.GetSetPropertyMethod(type, propertyInfo); var propertyType = propertyInfo.PropertyType; var propertyParseStringFn = JsvReader.GetParseFn(propertyType); var propertySerializer = new PropertySerializerEntry(propertySetFn, propertyParseStringFn) { PropertyType = propertyType }; var attr = propertyInfo.FirstAttribute <DataMemberAttribute>(); if (attr != null && attr.Name != null) { propertySetterMap[attr.Name] = propertySerializer; } propertySetterMap[propertyInfo.Name] = propertySerializer; } }
public void Get_setter_method_for_simple_properties() { Type type = typeof(Test); PropertyInfo propertyInfo = type.GetProperty("TestProperty"); SetPropertyDelegate setMethod = JsvDeserializeType.GetSetPropertyMethod(type, propertyInfo); Test test = new Test(); setMethod.Invoke(test, "test"); Assert.AreEqual("test", test.TestProperty); }
public StringMapTypeDeserializer(Type type) { this.type = type; foreach (var propertyInfo in type.GetProperties()) { var propertySetFn = JsvDeserializeType.GetSetPropertyMethod(type, propertyInfo); var propertyParseStringFn = JsvReader.GetParseFn(propertyInfo.PropertyType); var propertySerializer = new PropertySerializerEntry(propertySetFn, propertyParseStringFn); propertySetterMap.Add(propertyInfo.Name, propertySerializer); } }
public void Get_setter_method_for_dictionary_properties() { var dict = new Dictionary <string, string>(); Type type = typeof(Dictionary <string, string>); foreach (var propertyInfo in type.GetProperties()) { SetPropertyDelegate setMethod = JsvDeserializeType.GetSetPropertyMethod(type, propertyInfo); if (setMethod == null) { continue; } Console.WriteLine(propertyInfo.Name); setMethod.Invoke(dict, propertyInfo.Name); } }
public StringMapTypeDeserializer(Type type) { this.type = type; if (type.IsOrHasGenericInterfaceTypeOf(typeof(IEnumerable <>))) { return; } foreach (var propertyInfo in type.GetProperties()) { var propertySetFn = JsvDeserializeType.GetSetPropertyMethod(type, propertyInfo); var propertyParseStringFn = JsvReader.GetParseFn(propertyInfo.PropertyType); var propertySerializer = new PropertySerializerEntry(propertySetFn, propertyParseStringFn); propertySetterMap.Add(propertyInfo.Name, propertySerializer); } }
public StringMapTypeDeserializer(Type type) { this.type = type; foreach (var propertyInfo in type.GetSerializableProperties()) { var propertySetFn = JsvDeserializeType.GetSetPropertyMethod(type, propertyInfo); var propertyType = propertyInfo.PropertyType; var propertyParseStringFn = GetParseFn(propertyType); var propertySerializer = new PropertySerializerEntry(propertySetFn, propertyParseStringFn) { PropertyType = propertyType }; var attr = propertyInfo.FirstAttribute <DataMemberAttribute>(); if (attr != null && attr.Name != null) { propertySetterMap[attr.Name] = propertySerializer; } // Enhanced by William var attr2 = propertyInfo.FirstAttribute <XmlElementAttribute>(); if (attr2 != null && attr2.ElementName != null) { propertySetterMap[attr2.ElementName] = propertySerializer; } propertySetterMap[propertyInfo.Name] = propertySerializer; } if (JsConfig.IncludePublicFields) { foreach (var fieldInfo in type.GetSerializableFields()) { var fieldSetFn = JsvDeserializeType.GetSetFieldMethod(type, fieldInfo); var fieldType = fieldInfo.FieldType; var fieldParseStringFn = JsvReader.GetParseFn(fieldType); var fieldSerializer = new PropertySerializerEntry(fieldSetFn, fieldParseStringFn) { PropertyType = fieldType }; propertySetterMap[fieldInfo.Name] = fieldSerializer; } } }