Beispiel #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);
                }
            }
        }
Beispiel #2
0
        public XmlLocation(XmlProperty propertyInfo, bool isChildLocation = false)
        {
            if (!isChildLocation)
            {
                var locationAtts = propertyInfo.Info.GetCustomAttributes <XmlLocationAttribute>(true).ToList();
                locationAtts.Add(new XmlLocationAttribute(XmlLocationType.Element | XmlLocationType.Attribute, propertyInfo.Info.Name));
                locationAtts.ForEach(AddLocation);

                if (propertyInfo.IsAssignableTypesAllowed)
                {
                    var assignableTypes = ReflectionManager.GetAssignableTypes(propertyInfo.PropertyType);
                    assignableTypes.ForEach(AddLocation);
                }
                else
                {
                    AddLocation(propertyInfo.PropertyType);
                }
            }
            else
            {
                var childLocationAtts = propertyInfo.Info.GetCustomAttributes <XmlChildLocationAttribute>(true).ToList();
                childLocationAtts.ForEach(AddLocation);

                var childType = propertyInfo.PropertyType.IsGenericType
                        ? propertyInfo.PropertyType.GetGenericArguments().Last()
                        : (propertyInfo.PropertyType.IsArray
                            ? propertyInfo.PropertyType.GetElementType()
                            : propertyInfo.PropertyType);

                if (childType == null)
                {
                    throw new TestLibsException($"Couldn't find child type for type: {propertyInfo.PropertyType}, for property: {propertyInfo}");
                }

                if (propertyInfo.IsAssignableTypesAllowed)
                {
                    var assignableTypes = ReflectionManager.GetAssignableTypes(childType);
                    assignableTypes.ForEach(AddLocation);
                }
                else
                {
                    AddLocation(childType);
                }
            }
        }
Beispiel #3
0
        public XmlLocation(XmlProperty propertyInfo, bool isChildLocation = false)
        {
            if (!isChildLocation)
            {
                var locationAtts = propertyInfo.Info.GetCustomAttributes<XmlLocationAttribute>(true).ToList();
                locationAtts.Add(new XmlLocationAttribute(propertyInfo.Info.Name));
                locationAtts.ForEach(AddLocation);

                if (propertyInfo.IsAssignableTypesAllowed)
                {
                    var assignableTypes = ReflectionManager.GetAssignableTypes(propertyInfo.PropertyType);
                    assignableTypes.ForEach(AddLocation);
                }
                else
                    AddLocation(propertyInfo.PropertyType);
            }
            else
            {
                var childLocationAtts = propertyInfo.Info.GetCustomAttributes<XmlChildLocationAttribute>(true).ToList();
                childLocationAtts.ForEach(AddLocation);

                var childType = propertyInfo.PropertyType.IsGenericType
                        ? propertyInfo.PropertyType.GetGenericArguments().Last()
                        : (propertyInfo.PropertyType.IsArray
                            ? propertyInfo.PropertyType.GetElementType()
                            : propertyInfo.PropertyType);

                if (childType == null)
                    throw new TestLibsException($"Couldn't find child type for type: {propertyInfo.PropertyType}, for property: {propertyInfo}");

                if (propertyInfo.IsAssignableTypesAllowed)
                {

                    var assignableTypes = ReflectionManager.GetAssignableTypes(childType);
                    assignableTypes.ForEach(AddLocation);
                }
                else
                    AddLocation(childType);
            }
        }
Beispiel #4
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);
                }
            }
        }