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


C# Setting.ToList方法代码示例

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


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

示例1: GetFtpConfigurationFromSettings

        public static FtpClientConfiguration GetFtpConfigurationFromSettings(Setting[] settings)
        {
            var settingsList = settings.ToList();
            var settingNames = settingsList.ToList().Select(s => s.Name);
            if (!settingNames.Contains("Password"))
            {
                throw new Exception("Password is a required setting.");
            }

            if (!settingNames.Contains("UserName"))
            {
                throw new Exception("UserName is a required setting.");
            }

            if (!settingNames.Contains("Uri"))
            {
                throw new Exception("Uri is a required setting.");
            }

            if (!settingNames.Contains("TargetFileName"))
            {
                throw new Exception("Target File Name is a required setting.");
            }

            if (!settingNames.Contains("FileFormat"))
            {
                throw new Exception("File Format is a required setting.");
            }

            var config = new FtpClientConfiguration();
            config.EnableSsl = settingNames.Contains("EnableSsl")
                                ? Convert.ToBoolean(settingsList.ToList().First(x => x.Name == "EnableSsl").Value)
                                : false;
            config.KeepAlive = settingNames.Contains("KeepAlive")
                                ? Convert.ToBoolean(settingsList.ToList().First(x => x.Name == "KeepAlive").Value)
                                : false;
            config.UseBinary = settingNames.Contains("UseBinary")
                                ? Convert.ToBoolean(settingsList.ToList().First(x => x.Name == "UseBinary").Value)
                                : true;
            config.UsePassive = settingNames.Contains("UsePassive")
                                ? Convert.ToBoolean(settingsList.ToList().First(x => x.Name == "UsePassive").Value)
                                : false;
            config.AppendExecutionDateToFileName = settingNames.Contains("AppendExecutionDateToFileName")
                                ? Convert.ToBoolean(settingsList.ToList().First(x => x.Name == "AppendExecutionDateToFileName").Value)
                                : false;
            config.FtpPort = settingNames.Contains("FtpPort")
                                ? Convert.ToInt32(settingsList.ToList().First(x => x.Name == "FtpPort").Value)
                                : 21;
            config.FtpFolder = settingNames.Contains("FtpFolder")
                                ? settingsList.ToList().First(x => x.Name == "FtpFolder").Value
                                : String.Empty;
            config.DateTimeFormatToAppend = settingNames.Contains("DateTimeFormatToAppend")
                                ? settingsList.ToList().First(x => x.Name == "DateTimeFormatToAppend").Value
                                : String.Empty;
            
            config.Password = settingsList.ToList().First(x => x.Name == "Password").Value;
            config.TargetFileName = settingsList.ToList().First(x => x.Name == "TargetFileName").Value;
            config.Uri = settingsList.ToList().First(x => x.Name == "Uri").Value;
            config.UserName = settingsList.ToList().First(x => x.Name == "UserName").Value;
            config.FileFormat = settingsList.ToList().First(x => x.Name == "FileFormat").Value;
            return config;
        }
开发者ID:ifandelse,项目名称:Starfish.Extensions,代码行数:62,代码来源:FtpClientConfiguration.cs


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