Example #1
0
        /// <summary>
        /// Deserialises the specified value node into a .NET object
        /// </summary>
        /// <param name="t"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public object Deserialise(Type t, ValueNode node)
        {
            Type nt = node.GetType();
            Type[] genArgs = nt.GetGenericArguments();
            if (genArgs?.Length > 0 && typeof(PrimitiveValue<>).MakeGenericType(genArgs) == nt)
            {
                return nt.GetProperty("Value").GetValue(node, null);
            }
            else if (node is EnumValue)
            {
                EnumValue enumvalue = (EnumValue)node;

                Type enumtype;

                if (EnumTranslator.EnumTypes.TryGetValue(String.Join(".", enumvalue.Value, 0, enumvalue.Value.Length - 1), out enumtype))
                    return Translate.Deserialise(enumvalue, enumtype);

                return null;
            }
            else
            {
                return null;
            }
        }
Example #2
0
 private static object ToBasicObject(ValueNode node)
 {
     Type t = node.GetType();
     Type[] genArgs = t.GetGenericArguments();
     if (genArgs?.Length > 0 && typeof(PrimitiveValue<>).MakeGenericType(genArgs) == t)
     {
         return t.GetProperty("Value").GetValue(node, null);
     }
     else
     {
         return null;
     }
 }