Пример #1
0
        public static Type ParseTypeOrNullFromXml(XElement xml)
        {
            if (IsEmptyXml(xml))
            {
                return(null);
            }

            ExpressionSerializationTypeResolver resolver = new ExpressionSerializationTypeResolver();

            return(ParseTypeFromXml(xml, resolver));
        }
Пример #2
0
        static private Type ParseNormalTypeFromXmlCore(XElement xml, ExpressionSerializationTypeResolver resolver)
        {
            if (!xml.HasElements)
            {
                return(resolver.GetType(xml.Attribute("Name").Value));
            }

            var genericArgumentTypes = from genArgXml in xml.Elements()
                                       select ParseTypeFromXmlCore(genArgXml, resolver);

            return(resolver.GetType(xml.Attribute("Name").Value, genericArgumentTypes));
        }
Пример #3
0
        public static Type ParseTypeFromXmlCore(XElement xml, ExpressionSerializationTypeResolver resolver)
        {
            switch (xml.Name.ToString())
            {
            case "Type":
                return(ParseNormalTypeFromXmlCore(xml, resolver));

            case "AnonymousType":
                return(ParseAnonymousTypeFromXmlCore(xml, resolver));

            default:
                throw new ArgumentException("Expected 'Type' or 'AnonymousType'");
            }
        }
Пример #4
0
        static private Type ParseAnonymousTypeFromXmlCore(XElement xElement, ExpressionSerializationTypeResolver resolver)
        {
            string name       = xElement.Attribute("Name").Value;
            var    properties = from propXml in xElement.Elements("Property")
                                select new ExpressionSerializationTypeResolver.NameTypePair
            {
                Name = propXml.Attribute("Name").Value,
                Type = ParseTypeFromXml(propXml, resolver)
            };
            var ctr_params = from propXml in xElement.Elements("Constructor").Elements("Parameter")
                             select new ExpressionSerializationTypeResolver.NameTypePair
            {
                Name = propXml.Attribute("Name").Value,
                Type = ParseTypeFromXml(propXml, resolver)
            };

            return(resolver.GetOrCreateAnonymousTypeFor(name, properties.ToArray(), ctr_params.ToArray()));
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DLinqCustomExpressionXmlConverter"/> class.
 /// </summary>
 /// <param name="dc">
 /// The dc.
 /// </param>
 /// <param name="resolver">
 /// The resolver.
 /// </param>
 public DLinqCustomExpressionXmlConverter(DataContext dc, ExpressionSerializationTypeResolver resolver)
 {
     this.dc       = dc;
     this.resolver = resolver;
 }
Пример #6
0
 public ExpressionSerializer()
 {
     this.resolver = new ExpressionSerializationTypeResolver();
     Converters    = new List <CustomExpressionXmlConverter>();
 }
Пример #7
0
 public static Type ParseTypeFromXml(XElement xml, ExpressionSerializationTypeResolver resolver)
 {
     Debug.Assert(xml.Elements().Count() == 1);
     return(ParseTypeFromXmlCore(xml.Elements().First(), resolver));
 }