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


C# Setting.GetType方法代码示例

本文整理汇总了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));
                }
            }
        }
开发者ID:luqizheng,项目名称:lb_releaseIt,代码行数:48,代码来源:SettingManager.cs

示例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);
            }
        }
开发者ID:luqizheng,项目名称:lb_releaseIt,代码行数:28,代码来源:SettingManager.cs

示例3: Create

 public static ICommand Create(Setting setting)
 {
     var type = setting.GetType();
     return _builder[type](setting);
 }
开发者ID:luqizheng,项目名称:lb_releaseIt,代码行数:5,代码来源:CommandSettingMap.cs


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