当前位置: 首页>>代码示例>>C#>>正文


C# IConfig.GetType方法代码示例

本文整理汇总了C#中IConfig.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IConfig.GetType方法的具体用法?C# IConfig.GetType怎么用?C# IConfig.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConfig的用法示例。


在下文中一共展示了IConfig.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Save

        /// <summary>
        /// Saves the provided configuration component to file.
        /// </summary>
        /// <param name="config">The configuration component to save to file.</param>
        public virtual void Save(IConfig config)
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Saving configuration file."))
            {
                if (config == null)
                    throw new ArgumentNullException("config");

                if (config.FilePath == String.Empty)
                    throw new ArgumentException("The provided configuration file path must be specified.", "config.FilePath");

                LogWriter.Debug("Config file path: " + config.FilePath);
                LogWriter.Debug("Config type: " + config == null ? "[null]" : config.GetType().ToString());
                LogWriter.Debug("Config name: " + config.Name);

                // Check if it's the application level configuration object
                if (config is IAppConfig)
                {
                    LogWriter.Debug("The configuration object is derived from IAppConfig. Setting it to Config.Application.");
                    Config.Application = (IAppConfig)config;
                }

                if (config.Name == String.Empty)
                    throw new ArgumentException("The config.Name property must be set.");

                string name = config.Name;

                string configPath = config.FilePath;

                LogWriter.Debug("Configuration path: " + configPath);

                if (!Directory.Exists(Path.GetDirectoryName(config.FilePath)))
                    Directory.CreateDirectory(Path.GetDirectoryName(config.FilePath));

                using (FileStream stream = File.Create(configPath))
                {
                    LogWriter.Debug("Created configuration file stream");
                    XmlSerializer serializer = new XmlSerializer(config.GetType());
                    serializer.Serialize(stream, config);
                    LogWriter.Debug("Serialized config to file");
                    stream.Close();
                }

                Config.All.Add(config);

                LogWriter.Debug("Configuration file added to Config.All.");
            }
        }
开发者ID:jeremysimmons,项目名称:sitestarter,代码行数:51,代码来源:ConfigSaver.cs

示例2: LoadConfig

        /// <summary>
        /// 加载(反序列化)指定对象类型的配置对象
        /// </summary>
        /// <param name="fileoldchange">文件加载时间</param>
        /// <param name="configFilePath">配置文件所在路径(包括文件名)</param>
        /// <param name="configinfo">相应的变量 注:该参数主要用于设置m_configinfo变量 和 获取类型.GetType()</param>
        /// <param name="checkTime">是否检查并更新传递进来的"文件加载时间"变量</param>
        /// <returns></returns>
        protected static IConfig LoadConfig(ref DateTime fileoldchange, string configFilePath, IConfig configinfo, bool checkTime)
        {
            _configFilePath = configFilePath;
            _configInfo = configinfo;

            if (checkTime)
            {
                DateTime m_filenewchange = System.IO.File.GetLastWriteTime(configFilePath);

                //当程序运行中config文件发生变化时则对config重新赋值
                if (fileoldchange != m_filenewchange)
                {
                    fileoldchange = m_filenewchange;
                    lock (_lockHelper)
                    {
                        _configInfo = DeserializeInfo(configFilePath, configinfo.GetType());
                    }
                }
            }
            else
            {
                lock (_lockHelper)
                {
                    _configInfo = DeserializeInfo(configFilePath, configinfo.GetType());
                }

            }

            return _configInfo;
        }
开发者ID:bluexray,项目名称:Left4Framework,代码行数:38,代码来源:DefaultConfigFileManager.cs

示例3: SaveConfig

 /// <summary>
 /// 保存(序列化)指定路径下的配置文件
 /// </summary>
 /// <param name="configFilePath">指定的配置文件所在的路径(包括文件名)</param>
 /// <param name="configinfo">被保存(序列化)的对象</param>
 /// <returns></returns>
 public bool SaveConfig(string configFilePath, IConfig configinfo)
 {
     bool succeed = false;
     FileStream fs = null;
     try
     {
         fs = new FileStream(configFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
         XmlSerializer serializer = new XmlSerializer(configinfo.GetType());
         serializer.Serialize(fs, configinfo);
         //成功则将会返回true
         succeed = true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (fs != null)
         {
             fs.Close();
         }
     }
     return succeed;
 }
开发者ID:bluexray,项目名称:Left4Framework,代码行数:31,代码来源:DefaultConfigFileManager.cs


注:本文中的IConfig.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。