Пример #1
0
        private static IInstanceProvider ParseStaticInstanceElement(XElement xStaticInstance, RIContext context)
        {
            var typeName = xStaticInstance.Attribute("type").Value;

            try
            {
                var type       = context.GetType(typeName);
                var memberName = xStaticInstance.Attribute("member").Value;
                return(new StaticInstanceProvider(type, memberName));
            }
            catch (XmlException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new XmlException(xStaticInstance, ex);
            }
        }
Пример #2
0
        private static IInstanceProvider ParseNullInstanceElement(XElement xNullInstance, RIContext context)
        {
            var typeName = xNullInstance.Attribute("type")?.Value;

            if (typeName == null)
            {
                try
                {
                    return(new NullTypeInstanceProvider(typeof(object)));
                }
                catch (Exception ex)
                {
                    throw new XmlException(xNullInstance, ex);
                }
            }
            else
            {
                var type = context.GetType(typeName);
                return(new NullTypeInstanceProvider(type));
            }
        }
Пример #3
0
        private static IInstanceProvider ParseListInstanceElement(XElement xList, RIContext context)
        {
            var collector = new List <IInstanceProvider>();

            foreach (var xChild in xList.Elements())
            {
                var instanceProvider = ParseInstanceElement(xChild, context);
                collector.Add(instanceProvider);
            }

            var collectionType       = GetCollectionType(xList);
            var elementTypeAttribute = xList.Attribute("element-type");

            if (elementTypeAttribute == null)
            {
                return(new ListInstanceProvider(collector, collectionType));
            }

            var elementType = context.GetType(elementTypeAttribute.Value);

            return(new ListInstanceProvider(collector, elementType, collectionType));
        }
Пример #4
0
        private static ComplexInstanceProvider ParseComplexInstanceElement(XElement xComplexInstance, RIContext context)
        {
            var typeName = xComplexInstance.Attribute("class").Value;

            try
            {
                var type = context.GetType(typeName);

                var constructorInstanceProviders = new List <IInstanceProvider>();

                foreach (var xConstructorArg in xComplexInstance.Elements(Ns + "constructor-args").Elements())
                {
                    constructorInstanceProviders.Add(ParseInstanceElement(xConstructorArg, context));
                }

                var propertiesInstanceProviders = new Dictionary <string, IInstanceProvider>();
                foreach (var xProperty in xComplexInstance.Elements(Ns + "properties").Elements())
                {
                    var name = xProperty.Attribute("name").Value;
                    if (propertiesInstanceProviders.ContainsKey(name))
                    {
                        throw new XmlException(xProperty, $"A value for the property by the name '{name}' has already been defined.");
                    }

                    propertiesInstanceProviders[name] = ParseInstanceElement(xProperty, context);
                }

                return(new ComplexInstanceProvider(type, constructorInstanceProviders, propertiesInstanceProviders));
            }
            catch (XmlException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new XmlException(xComplexInstance, ex);
            }
        }