forked from ln-dotnet/ln.json
Improve Property Handling in JSONConverter
parent
197884e101
commit
2cb115f1f2
|
@ -113,10 +113,17 @@ namespace sharp.json
|
|||
private static object ToArray(Type t,JSON json)
|
||||
{
|
||||
Array a = Array.CreateInstance(t.GetElementType(), json.Count);
|
||||
Type et = t.GetElementType();
|
||||
|
||||
JSONField jfield = t.GetCustomAttribute<JSONField>();
|
||||
if (!jfield.IsNull())
|
||||
{
|
||||
et = jfield.ConstructWithType;
|
||||
}
|
||||
|
||||
for (int n = 0; n < json.Count; n++)
|
||||
{
|
||||
a.SetValue(To(t.GetElementType(),json[n]), n);
|
||||
a.SetValue(To(et ,json[n]), n);
|
||||
}
|
||||
|
||||
return a;
|
||||
|
@ -261,7 +268,9 @@ namespace sharp.json
|
|||
}
|
||||
foreach (PropertyInfo pi in t.GetProperties(bf))
|
||||
{
|
||||
fpilist.Add(new FieldPropertyInfo(pi));
|
||||
if (pi.GetIndexParameters().Length == 0){
|
||||
fpilist.Add(new FieldPropertyInfo(pi));
|
||||
}
|
||||
}
|
||||
|
||||
FieldPropertyInfo[] temp = fpilist.ToArray();
|
||||
|
@ -309,7 +318,10 @@ namespace sharp.json
|
|||
{
|
||||
if (PropertyInfo != null)
|
||||
{
|
||||
PropertyInfo.SetValue(inst, value);
|
||||
if (PropertyInfo.SetMethod != null)
|
||||
{
|
||||
PropertyInfo.SetValue(inst, value);
|
||||
}
|
||||
}
|
||||
else if (FieldInfo != null)
|
||||
{
|
||||
|
@ -333,6 +345,10 @@ namespace sharp.json
|
|||
{
|
||||
get
|
||||
{
|
||||
if ((JSONField != null)&&(JSONField.ConstructWithType != null))
|
||||
{
|
||||
return JSONField.ConstructWithType;
|
||||
}
|
||||
if (PropertyInfo != null)
|
||||
{
|
||||
return PropertyInfo.PropertyType;
|
||||
|
|
|
@ -5,5 +5,7 @@ namespace sharp.json.attributes
|
|||
public class JSONField : Attribute
|
||||
{
|
||||
public string Alias { get; set; }
|
||||
public bool ConstructWithOwner { get; set; }
|
||||
public Type ConstructWithType { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue