private static void LoadConfig() { string tmpPath = ConfigurationManager.AppSettings["TypeVersionConfigFilePath"]; if (tmpPath == null || tmpPath.Trim().Length <= 0) { tmpPath = Config_File_Path; } else if (!tmpPath.Contains(':')) // 说明配得相对路径 { tmpPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, tmpPath); } if (File.Exists(tmpPath)) { s_Instance = LoadFromFile <TypeVersionConfig>(tmpPath); } else { s_Instance = new TypeVersionConfig() { AssemblyFolder = string.Empty, GlobalDefaultVersion = string.Empty, Maps = new TypeVersionMap[0] }; } if (s_Instance != null && s_Instance.Maps != null && s_Instance.Maps.Length > 0) { foreach (var map in s_Instance.Maps) { if (map.Type == null || map.Type.Trim().Length <= 0) { throw new ArgumentException("AssemblyQualifiedName of type can't be blank in type version config file.", "typeAssemblyQualifiedName"); } if (map.Version == null || map.Version.Trim().Length <= 0) { throw new ArgumentException("Version can't be blank for type '" + map.Type.Trim() + "' in type version config file.", "typeAssemblyQualifiedName"); } string[] tmpArray = map.Type.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (tmpArray == null || tmpArray.Length < 2) { throw new ArgumentException("Error format for assemblyQualifiedName ['" + map.Type.Trim() + "'] of type in type version config file.", "typeAssemblyQualifiedName"); } string key = tmpArray[0].Trim() + "," + tmpArray[1].Trim(); if (s_VersionMap.ContainsKey(key)) { throw new ArgumentException("Duplicated assemblyQualifiedName of type '" + key + "' in type version config file.", "typeAssemblyQualifiedName"); } s_VersionMap.Add(key, map.Version); } } }
private static string GetVersion() { string version = TypeVersionConfig.Instance.GlobalDefaultVersion; if (version == null || version.Trim().Length <= 0) { version = TypeVersionConfig.VERSION_DEFAULT; } if (TypeVersionConfig.ExistVersionMap(typeof(T))) { version = TypeVersionConfig.GetVersion(typeof(T)); } return(version); }