Fix JSONObjectMapping.Apply(..) (don't add illegal setters)

master
Harald Wolff 2020-02-24 17:35:18 +01:00
parent d8c313c14c
commit 93bad5af43
1 changed files with 6 additions and 2 deletions

View File

@ -32,7 +32,9 @@ namespace ln.json.mapping
JSONMappingAttribute mappingAttribute = fieldInfo.GetCustomAttribute<JSONMappingAttribute>();
if ((mappingAttribute == null) || !mappingAttribute.Private)
{
setters.Add(fieldInfo.Name, (object arg1, object arg2) => fieldInfo.SetValue(arg1, arg2));
if (!fieldInfo.IsInitOnly)
setters.Add(fieldInfo.Name, (object arg1, object arg2) => fieldInfo.SetValue(arg1, arg2));
getters.Add(fieldInfo.Name, (object arg) => fieldInfo.GetValue(arg));
types.Add(fieldInfo.Name, fieldInfo.FieldType);
}
@ -42,7 +44,9 @@ namespace ln.json.mapping
JSONMappingAttribute mappingAttribute = propertyInfo.GetCustomAttribute<JSONMappingAttribute>();
if ((propertyInfo.GetIndexParameters().Length == 0) && ((mappingAttribute == null) || !mappingAttribute.Private))
{
setters.Add(propertyInfo.Name, (object arg1, object arg2) => propertyInfo.SetValue(arg1, arg2));
if (propertyInfo.CanWrite)
setters.Add(propertyInfo.Name, (object arg1, object arg2) => propertyInfo.SetValue(arg1, arg2));
getters.Add(propertyInfo.Name, (object arg) => propertyInfo.GetValue(arg));
types.Add(propertyInfo.Name, propertyInfo.PropertyType);
}