本文整理汇总了C#中Setting.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Setting.GetType方法的具体用法?C# Setting.GetType怎么用?C# Setting.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Setting
的用法示例。
在下文中一共展示了Setting.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillProperities
private void FillProperities(Setting setting, IniSection section)
{
var iniProperties = section.Properties.ToDictionary(s => s.Name, s => s.Value);
foreach (var propertyInfo in setting.GetType().GetProperties())
{
if (propertyInfo.Name == "Id")
continue;
if (iniProperties.ContainsKey(propertyInfo.Name))
{
var strValue = iniProperties[propertyInfo.Name];
if (propertyInfo.PropertyType == typeof(string))
{
propertyInfo.SetValue(setting, strValue);
continue;
}
if (propertyInfo.PropertyType.IsEnum)
{
propertyInfo.SetValue(setting, Enum.Parse(propertyInfo.PropertyType, strValue));
continue;
}
if (propertyInfo.PropertyType == typeof(int))
{
propertyInfo.SetValue(setting, Convert.ToInt32(strValue));
continue;
}
if (propertyInfo.PropertyType == typeof(bool))
{
propertyInfo.SetValue(setting, Convert.ToBoolean(strValue));
continue;
}
if (propertyInfo.PropertyType.IsArray &&
propertyInfo.PropertyType.GetElementType() == typeof(string))
{
var aryStrValue = strValue.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
propertyInfo.SetValue(setting, aryStrValue);
continue;
}
throw new ApplicationException(string.Format("Can't Convert {0} to type {1}", strValue,
propertyInfo.PropertyType.Name));
}
}
}
示例2: SetToSection
private void SetToSection(IniSection section, Setting s, bool buildComment)
{
foreach (var propInfo in s.GetType().GetProperties())
{
if (propInfo.Name == "Id")
continue;
if (propInfo.PropertyType.IsArray)
{
var ary = (Array)propInfo.GetValue(s);
if (ary == null)
continue;
IList<string> aryJoin = (from object ele in ary select Convert.ToString(ele)).ToList();
section.Set(propInfo.Name, string.Join(",", aryJoin.ToArray()));
continue;
}
string comment = null;
if (buildComment)
{
var descript = propInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (descript.Length > 0)
{
comment = ((DescriptionAttribute)descript[0]).Description.Replace("\r\n", "#\r\n");
}
}
section.Set(propInfo.Name, Convert.ToString(propInfo.GetValue(s)), comment);
}
}
示例3: Create
public static ICommand Create(Setting setting)
{
var type = setting.GetType();
return _builder[type](setting);
}