コード例 #1
0
        public static ConfigurationFileInfo Load(string path)
        {
            const string baseTag      = "base";
            const string importTag    = "import";
            const string referenceTag = "r";
            const string langTag      = "lang";

            var allTags = new[] { baseTag, importTag, referenceTag, langTag };

            var ext      = Path.GetExtension(path) ?? "";
            var dir      = Path.GetDirectoryName(path) ?? "";
            var fileName = Path.GetFileName(path) ?? "";
            var cfgName  = fileName.Replace(ext, "");
            var contents = File.ReadAllText(path);
            var cfi      = new ConfigurationFileInfo
            {
                Name                 = cfgName, //TODO: remove all non alpanumeric characters (to be able to build correct clr type names)
                Directory            = dir,
                ReferencedAssemblies = GetTagValues(contents, referenceTag).ToArray(),
                NamespaceImports     = GetTagValues(contents, importTag).ToArray(),
            };

            var baseConfigs = GetTagValues(contents, baseTag);

            if (baseConfigs.Count() > 1)
            {
                throw new Exception("Multiple base configurations specified for " + cfgName);
            }

            if (baseConfigs.Any())
            {
                cfi.Base = Load(Path.Combine(dir, baseConfigs.Single() + ext));
            }

            var lang = GetTagValues(contents, langTag).FirstOrDefault();

            switch (lang)
            {
            case "cs": cfi.Language = ConfigLang.Csharp; break;

            case "xml": cfi.Language = ConfigLang.Xml; break;

            default: cfi.Language = ConfigLang.Csharp; break;
            }

            cfi.Contents = RemoveTags(contents, allTags);

            return(cfi);
        }
コード例 #2
0
        public static ConfigurationFileInfo Load(string path)
        {
            const string baseTag = "base";
            const string importTag = "import";
            const string referenceTag = "r";
            const string langTag = "lang";

            var allTags = new[] {baseTag, importTag, referenceTag, langTag};

            var ext = Path.GetExtension(path) ?? "";
            var dir = Path.GetDirectoryName(path) ?? "";
            var fileName = Path.GetFileName(path) ?? "";
            var cfgName = fileName.Replace(ext, "");
            var contents = File.ReadAllText(path);
            var cfi = new ConfigurationFileInfo
            {
                Name = cfgName, //TODO: remove all non alpanumeric characters (to be able to build correct clr type names)
                Directory = dir,
                ReferencedAssemblies = GetTagValues(contents, referenceTag).ToArray(),
                NamespaceImports = GetTagValues(contents, importTag).ToArray(),
            };

            var baseConfigs = GetTagValues(contents, baseTag);
            if (baseConfigs.Count() > 1)
                throw new Exception("Multiple base configurations specified for " + cfgName);

            if (baseConfigs.Any())
                cfi.Base = Load(Path.Combine(dir, baseConfigs.Single() + ext));

            var lang = GetTagValues(contents, langTag).FirstOrDefault();
            switch (lang)
            {
                case "cs": cfi.Language = ConfigLang.Csharp; break;
                case "xml": cfi.Language = ConfigLang.Xml; break;
                default: cfi.Language = ConfigLang.Csharp; break;
            }

            cfi.Contents = RemoveTags(contents, allTags);

            return cfi;
        }