Example #1
0
        public static dynamic ParseXElementAsDynamic(this IMyJsonHelper helper, XElement rootNode)
        {
            string jsonText      = JsonConvert.SerializeXNode(rootNode, Formatting.Indented);
            var    withoutATSign = Regex.Replace(jsonText, "(?<=\")(@)(?!.*\":\\s )",
                                                 string.Empty, RegexOptions.IgnoreCase);
            dynamic dyn = JsonConvert.DeserializeObject <ExpandoObject>(withoutATSign);

            return(dyn);
        }
Example #2
0
 public static T DeserializeObject <T>(this IMyJsonHelper helper, string json, T defaultValue)
 {
     if (string.IsNullOrWhiteSpace(json))
     {
         return(defaultValue);
     }
     if (typeof(T) == typeof(string))
     {
         if (string.IsNullOrWhiteSpace(json))
         {
             return(defaultValue);
         }
         return(json.As <T>());
     }
     return(JsonConvert.DeserializeObject <T>(json));
 }
Example #3
0
        public static dynamic ParseXmlFileAsDynamic(this IMyJsonHelper helper, string xmlFile)
        {
            var xDoc = XDocument.Load(xmlFile);

            return(helper.ParseXElementAsDynamic(xDoc.Elements().First()));
        }