向类插入动态添加通用属性

时间:2014-06-30 14:10:33

标签: c# .net class

我必须构建一组使用事件类设置的通用属性,如果数组中的对象在其名称中包含$,则应通过类型事件的通用属性进行访问。

 string[] props = { "Id", "Status", "Title","Description" ,"$Fullname$"};

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < props.Length; i++)
        {
            if (props[i].ToLowerInvariant().Contains('$'))
            {
                if (props[i] == "$Fullname$")
                {
                    sb.Append("Fullname=emop.Object.Fullname");

                }

            }


        }

我想要做的是使用以下内容创建字符串构建器,当然。我无法在类构造函数中执行此操作,因为类不会在运行时之前将全名称作为类事件的属性。

            Incident incident = new Incident()
            {
                InternalId = emop.Object.Id,
                Id = emop.Object[null, "Id"] != null ? emop.Object[null, "Id"].ToString() : string.Empty,
                Title = emop.Object[null, "Title"] != null && emop.Object[null, "Title"].Value != null ? emop.Object[null, "Title"].Value.ToString() : string.Empty,
                Name = emop.Object.Name,
                sb.ToString(), //OUTPUT the generic properties
                LastModified = emop.Object.LastModified,
                Description = emop.Object[null, "Description"] != null && emop.Object[null, "Description"].Value != null ? emop.Object[null, "Description"].Value.ToString() : string.Empty
            };

0 个答案:

没有答案