Exemplo n.º 1
0
        public Type ParseType(string typeName)
        {
            ConfigGuard.ArgumentNotNull(typeName, "typeName", "ParseType does not accept null");

            string parsedTypeName = ResolveGenericAliases(typeName);

            int startIndex = parsedTypeName.IndexOf('[');
            int endIndex   = parsedTypeName.LastIndexOf(']');

            if (startIndex == -1)
            {
                // try to load the non-generic type (e.g. System.Int32)
                return(GetNonGenericType(parsedTypeName));
            }
            else
            {
                // get the FullName of the non-generic type (e.g. System.Collections.Generic.List`1)
                string fullName = parsedTypeName.Substring(0, startIndex);
                if (parsedTypeName.Length - endIndex - 1 > 0)
                {
                    fullName += parsedTypeName.Substring(endIndex + 1, parsedTypeName.Length - endIndex - 1);
                }

                // parse the child type arguments for this generic type (recursive)
                List <Type> list          = new List <Type>();
                string      typeArguments = parsedTypeName.Substring(startIndex + 1, endIndex - startIndex - 1);
                foreach (string typeArgument in typeArguments.Split(",".ToCharArray()))
                {
                    list.Add(GetNonGenericType(typeArgument.Trim()));
                }

                return(GetNonGenericType(fullName).MakeGenericType(list.ToArray()));
            }
        }
        public XmlConfigurationLoader(IContext context, Stream configStream, List <ISettingValidator> validators,
                                      Dictionary <string, Type> typeAliases)
            : base(context, validators, typeAliases)
        {
            ConfigGuard.ArgumentNotNull(configStream, "configStream", "XmlConfiguration loader requires a non null Stream");

            LoadStream(configStream);
        }
Exemplo n.º 3
0
        public ISettingParser Resolve(Type parsedType)
        {
            ConfigGuard.ArgumentNotNull(parsedType, "parsedType", "Parsed type cannot be null");

            foreach (var parser in _parsers)
            {
                if (parser.CanParse(parsedType))
                {
                    return(parser);
                }
            }

            throw new ConfigurationException("No parser was found for type of " + parsedType.Name);
        }
Exemplo n.º 4
0
 public void Register(ISettingParser parser)
 {
     ConfigGuard.ArgumentNotNull(parser, "parser", "Cannot add a null parser");
     _parsers.Add(parser);
 }