public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var daat = JObject.Load(reader); var ret = new JiraIssue(); foreach (var prop in ret.GetType().GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { var attr = prop.GetCustomAttributes(false).FirstOrDefault(); if (attr != null) { var propName = ((JsonPropertyAttribute)attr).PropertyName; if (!string.IsNullOrWhiteSpace(propName)) { var conventions = propName.Split('/'); if (conventions.Length == 3) { ret.Type = (string)((JValue)daat[conventions[0]][conventions[1]][conventions[2]]).Value; } ret.Id = Convert.ToInt32(((JValue)daat[propName]).Value); } } } return(ret); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var daat = JObject.Load(reader); var issue = new JiraIssue(); foreach (var prop in issue.GetType().GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { var attr = prop.GetCustomAttributes(false).FirstOrDefault(); if (attr != null) { var propName = ((JsonPropertyAttribute)attr).PropertyName; if (!string.IsNullOrWhiteSpace(propName)) { //split by the delimiter, and traverse recursevly according to the path var conventions = propName.Split('/'); object propValue = null; JToken token = null; for (var i = 0; i < conventions.Length; i++) { if (token == null) { token = daat[conventions[i]]; } else { token = token[conventions[i]]; } if (token == null) { //silent fail: exit the loop if the specified path was not found break; } else { //store the current value if (token is JValue) { propValue = ((JValue)token).Value; } } } if (propValue != null) { //workaround for numeric values being automatically created as Int64 (long) objects. if (propValue is long && prop.PropertyType == typeof(Int32)) { prop.SetValue(issue, Convert.ToInt32(propValue)); } else { prop.SetValue(issue, propValue); } } } } } return(issue); }
public static void Initialize(JiraIssue issue) { var scope = Scope.Get(issue.GetType()); scope.Initialize(issue); var properties = scope.Properties; if (properties == null || properties.Count == 0) { return; } var metadata = new JiraMetadataProvider(new[] { issue.GetType() }); foreach (var property in properties) { var field = metadata.GetFieldMetadata(property); issue.Controller.RegisterUnchangingField(field.FieldName); } }