Exemplo n.º 1
0
        private void Init()
        {
            var xmlTypeAtt = XType.GetCustomAttribute <XmlTypeAttribute>();

            Description = xmlTypeAtt.Description;

            KeyProperty = XType.GetProperty(xmlTypeAtt.KeyPropertyName);
            if (KeyProperty == null)
            {
                throw new TestLibsException($"Couldn't find KeyProperty with name: {xmlTypeAtt.KeyPropertyName} for type: {XType}");
            }

            Location = new XmlLocation(XType);
            var propertyInfos = XType.GetProperties();

            foreach (var propertyInfo in propertyInfos)
            {
                var xmlPropertyAtt = propertyInfo.GetCustomAttribute <XmlPropertyAttribute>(true);
                if (xmlPropertyAtt != null)
                {
                    var xmlProperty = new XmlProperty(this, propertyInfo);
                    XmlProperties.Add(xmlProperty);
                }
            }
        }
Exemplo n.º 2
0
        public static List <object> Parse(Type type, XElement config, XmlLocation childLocation, bool isAssignableTypesAllowed, IContext context)
        {
            var list = new List <object>();
            var els  = childLocation.GetChildElements(config);

            foreach (var el in els)
            {
                var obj = Parse(type, el, isAssignableTypesAllowed, null, context);
                list.Add(obj);
            }

            return(list);
        }
Exemplo n.º 3
0
        private void Init()
        {
            var xmlTypeAtt = XType.GetCustomAttribute<XmlTypeAttribute>();

            Description = xmlTypeAtt.Description;

            KeyProperty = XType.GetProperty(xmlTypeAtt.KeyPropertyName);
            if (KeyProperty == null)
                throw new TestLibsException($"Couldn't find KeyProperty with name: {xmlTypeAtt.KeyPropertyName} for type: {XType}");

            Location = new XmlLocation(XType);
            var propertyInfos = XType.GetProperties();

            foreach (var propertyInfo in propertyInfos)
            {
                var xmlPropertyAtt = propertyInfo.GetCustomAttribute<XmlPropertyAttribute>(true);
                if (xmlPropertyAtt != null)
                {
                    var xmlProperty = new XmlProperty(this, propertyInfo);
                    XmlProperties.Add(xmlProperty);
                }
            }
        }
Exemplo n.º 4
0
 public static T Parse <T>(XElement config, bool isAssignableTypesAllowed = false, XmlLocation childLocation = null, IContext context = null)
 {
     return((T)Parse(typeof(T), config, isAssignableTypesAllowed, childLocation, context));
 }
Exemplo n.º 5
0
        public static object Parse(Type type, XObject config, bool isAssignableTypesAllowed = false, XmlLocation childLocation = null, IContext context = null)
        {
            if (config == null)
            {
                throw new TestLibsException($"Config for type: {type} is null.");
            }

            var parser = Parsers.FirstOrDefault(p => p.IsMatch(type));

            if (parser == null)
            {
                throw new TestLibsException($"Couldn't find parser for type: {type}");
            }

            return(parser.Parse(type, config, isAssignableTypesAllowed, childLocation, context));
        }