diff --git a/JSONConverter.cs b/JSONConverter.cs index 81628c3..69a4047 100644 --- a/JSONConverter.cs +++ b/JSONConverter.cs @@ -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(); + 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; diff --git a/attributes/JSONField.cs b/attributes/JSONField.cs index cf54e84..809ec08 100644 --- a/attributes/JSONField.cs +++ b/attributes/JSONField.cs @@ -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; } } }