本文整理汇总了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;
}