Пример #1
0
        public static void LoadConfigToObject(Object obj, Type type, String filePath, Boolean isEncrypted = false)
        {
            Object target = null;

            var text = File.ReadAllText(filePath, _DefaultEncodeing);

            if (isEncrypted)
            {
                text = DefaultStringEncryptor.Decrypt(text);
            }
            target = SerializeAssistor.Deserialize(text, type);

            var propertyInfos = TypeInfoProvider.GetProperties(type);

            foreach (var prop in propertyInfos)
            {
                ConfigLoadPropertyAnalysis(target, prop);
            }
            CopyConfigObject(target, obj, type);
        }
Пример #2
0
        /// <summary>
        /// 将配置对象保存到指定路径
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="savePath">保存路径  </param>
        /// <param name="isEncrypt">表示是否需要加密</param>
        public static void SaveConfig(Object obj, Type type, String savePath, Boolean isEncrypt = false)
        {
            Object target      = obj;
            Object cloneTarget = Activator.CreateInstance(type);

            CopyConfigObject(target, cloneTarget, type);

            var propertyInfos = TypeInfoProvider.GetProperties(type);

            foreach (var prop in propertyInfos)
            {
                ConfiSavePropertyAnalysis(cloneTarget, prop);
            }

            var text = SerializeAssistor.Serialize(cloneTarget, type);

            if (isEncrypt)
            {
                text = DefaultStringEncryptor.Decrypt(text);
            }
            File.WriteAllText(savePath, text, _DefaultEncodeing);
        }