private static void ConfigSavePropertyAnalysis(Object target, PropertyInfo prop) { var configTag = TypeInfoProvider.GetConfigTag(prop); if (configTag != null) { Object value = TypeInfoProvider.GetValue(prop, target); if (configTag.IsEncrypted && value != null && prop.PropertyType == typeof(String)) { String strValue = value as String; strValue = DefaultStringEncryptor.Encrypt(strValue); TypeInfoProvider.SetValue(prop, target, strValue); return; } if (prop.PropertyType.IsSubclassOf(typeof(ConfigBase))) { Object valueCopy = TypeInfoProvider.CreateInstance(prop.PropertyType); CopyConfigObject(value, valueCopy, prop.PropertyType); TypeInfoProvider.SetValue(prop, target, valueCopy); Type type = prop.PropertyType; var propertyInfos = TypeInfoProvider.GetProperties(type); foreach (var cprop in propertyInfos) { ConfigSavePropertyAnalysis(valueCopy, cprop); } } } }
/// <summary> /// 从指定路径加载配置对象 /// </summary> /// <param name="filePath"></param> /// <param name="isEncrypted">表示文件是否被加密</param> /// <returns></returns> public static Object LoadConfig(Type type, String filePath, Boolean isEncrypted = false) { Object target = TypeInfoProvider.CreateInstance(type); LoadConfigToObject(target, type, filePath, isEncrypted); return(target); }
public static T LoadConfig <T>(String filePath, Boolean isEncrypted = false) where T : ConfigBase { Type type = typeof(T); Object target = TypeInfoProvider.CreateInstance(typeof(T)); LoadConfigToObject(target, type, filePath, isEncrypted); return(target as T); }