Exemplo n.º 1
0
        /// <summary>
        /// 根据枚举获取数据
        /// </summary>
        /// <param name="enumValue"></param>
        /// <returns></returns>
        public static string GetEnumDescription(Enum enumValue)
        {
            if (_enumValueDic.ContainsKey(enumValue))
            {
                return(_enumValueDic[enumValue]);
            }
            if (enumValue == null)
            {
                return("");
            }
            string str = enumValue.ToString();

            System.Reflection.FieldInfo field = enumValue.GetType().GetField(str);
            if (field == null)
            {
                _enumValueDic.Add(enumValue, str);
                return(str);
            }
            object[] objs = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
            if (objs == null || objs.Length == 0)
            {
                return(str);
            }
            System.ComponentModel.DescriptionAttribute da = (System.ComponentModel.DescriptionAttribute)objs[0];
            _enumValueDic.Add(enumValue, da.Description);
            return(da.Description);
        }
Exemplo n.º 2
0
        static List <System.Collections.DictionaryEntry> ResolveEnum <TEnum>()
        {
            Type type = typeof(TEnum);

            if (!type.IsEnum)
            {
                throw new ArgumentException("TEnum requires a Enum", "TEnum");
            }

            FieldInfo[] fields = type.GetFields();

            List <System.Collections.DictionaryEntry> col = new List <System.Collections.DictionaryEntry>();

            foreach (FieldInfo field in fields)
            {
                object[] objs = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);

                if (objs != null && objs.Length > 0)
                {
                    System.ComponentModel.DescriptionAttribute attr = objs[0] as System.ComponentModel.DescriptionAttribute;

                    col.Add(new System.Collections.DictionaryEntry(attr.Description, ((int)Enum.Parse(type, field.Name)).ToString()));
                }
            }

            return(col);
        }
Exemplo n.º 3
0
        /// <summary>
        ///		Gets the description from an enum (using System.ComponentModel to utilize the DescriptionAttribute and System.Reflection to get the Attribute's value).
        ///		For iOS (or for the case of no Description attribute), defaults to the string value of the enum.
        ///		NOTE: Is not able to differentiate between two enum entries that share the same value.
        ///			If differentiation is required, use EnumUtility.GetDescriptions() instead.
        /// </summary>
        /// <param name="enumValue">The enum to return a Description for.</param>
        /// <param name="userFriendlyAsFallback">If true, uses a user-friendly text format if there is no description.  See FormatUtility.GetUserFriendlyText.</param>
        /// <returns>string, either being the description, a user-friendly fallback, or the ToString representation.</returns>
        public static string GetDescription(this Enum enumValue, bool userFriendlyAsFallback = true)
        {
                        #if !UNITY_IOS
            Type   type = enumValue.GetType();
            string name = Enum.GetName(type, enumValue);
            if (name != null)
            {
                FieldInfo field = type.GetField(name);
                if (field != null)
                {
                    System.ComponentModel.DescriptionAttribute attr = Attribute.GetCustomAttribute(field, typeof(System.ComponentModel.DescriptionAttribute)) as System.ComponentModel.DescriptionAttribute;
                    if (attr != null)
                    {
                        return(attr.Description);
                    }
                }
            }
                        #endif

            if (userFriendlyAsFallback)
            {
                return(FormatUtility.GetUserFriendlyText(enumValue.ToString()));
            }
            return(enumValue.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取枚举值的详细文本
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static string GetEnumDescription(object e)
        {
            //获取字段信息
            System.Reflection.FieldInfo[] ms = e.GetType().GetFields();

            Type t = e.GetType();

            foreach (System.Reflection.FieldInfo f in ms)
            {
                //判断名称是否相等
                if (f.Name != e.ToString())
                {
                    continue;
                }

                //反射出自定义属性
                foreach (Attribute attr in f.GetCustomAttributes(true))
                {
                    //类型转换找到一个Description,用Description作为成员名称
                    System.ComponentModel.DescriptionAttribute dscript = attr as System.ComponentModel.DescriptionAttribute;
                    if (dscript != null)
                    {
                        return(dscript.Description);
                    }
                }
            }

            //如果没有检测到合适的注释,则用默认名称
            return(e.ToString());
        }
Exemplo n.º 5
0
        private void Read()
        {
            if (!m_pi.CanRead)
                return;

            if (!m_pi.CanWrite)
                return;

            object[] attributes = m_pi.GetCustomAttributes(true);
            if (attributes == null)
                return;

            m_documentable = true;
            foreach (Attribute attribute in attributes)
            {
                if (attribute is DescriptionAttribute)
                {
                    m_description = attribute as DescriptionAttribute;
                }
                else if (attribute is BrowsableAttribute)
                {
                    m_documentable = (attribute as BrowsableAttribute).Browsable;
                }
                else if (attribute is Required)
                {
                    m_required = (attribute as Required).IsRequired;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取每句的描述,获取相关值,用于页面,上绑定,要继承byte,参数indexNum获取枚举的条件
        /// </summary>
        /// <param name="enumType"></param>
        /// <param name="indexNum"></param>
        /// <returns></returns>
        public static List <KeyValuePair <byte, string> > GetEnum(Type enumType, int indexFirst, int indexLast)
        {
            var names = System.Enum.GetNames(enumType);

            if (names != null && names.Length > 0)
            {
                List <KeyValuePair <byte, string> > kvList = new List <KeyValuePair <byte, string> >(names.Length);
                foreach (var item in names)
                {
                    System.Reflection.FieldInfo finfo = enumType.GetField(item);
                    if ((byte)finfo.GetValue(null) > indexFirst && (byte)finfo.GetValue(null) < indexLast)
                    {
                        object[] enumAttr = finfo.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), true).ToArray();
                        if (enumAttr != null && enumAttr.Length > 0)
                        {
                            string description = string.Empty;

                            System.ComponentModel.DescriptionAttribute desc = enumAttr[0] as System.ComponentModel.DescriptionAttribute;
                            if (desc != null)
                            {
                                description = desc.Description;
                            }
                            kvList.Add(new KeyValuePair <byte, string>((byte)finfo.GetValue(null), description));
                        }
                    }
                }
                return(kvList);
            }
            return(null);
        }
 public OptionPropertyValue(PropertyInfo propertyInfo, object owner)
 {
     _propertyInfo = propertyInfo;
     _owner = owner;
     _displayName = _propertyInfo.GetCustomAttribute<DisplayNameAttribute>();
     _description = _propertyInfo.GetCustomAttribute<DescriptionAttribute>();
 }
Exemplo n.º 8
0
        public static String  GetDescriptionAttribute(string controller, string method)
        {
            String   sDescription = "";
            Assembly assembly     = System.Reflection.Assembly.GetExecutingAssembly();

            Type type = assembly.GetType(controller);     //命名空间名 + 类名

            MethodInfo[] mi = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            foreach (MethodInfo m in mi)
            {
                if (m.Name == method)
                {
                    if (m.ReturnType.Name == "IHttpActionResult")
                    {
                        object[] t1 = m.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
                        if (t1 != null && t1.Length > 0)
                        {
                            System.ComponentModel.DescriptionAttribute d = (System.ComponentModel.DescriptionAttribute)t1[0];
                            sDescription = d.Description;
                        }
                    }
                    break;
                }
            }
            return(sDescription);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 获取枚举描述
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string GetDescription(this Enum value)
        {
            System.Reflection.FieldInfo field = value.GetType().GetField(value.ToString());

            System.ComponentModel.DescriptionAttribute attribute = Attribute.GetCustomAttribute(field, typeof(System.ComponentModel.DescriptionAttribute)) as System.ComponentModel.DescriptionAttribute;

            return(attribute == null?value.ToString() : attribute.Description);
        }
Exemplo n.º 10
0
        public void ConstructorTest()
        {
            string description = "Some Attribute Description";

            DescriptionAttribute target = VisualStudio_Project_Samples_ResourcesDescriptionAttributeAccessor.CreatePrivate(description);

            Assert.IsNotNull(target, "ResourcesDescriptionAttribute instance was not created successfully.");
        }
Exemplo n.º 11
0
        public static string GetPropDescription(Type type, string prop)
        {
            PropertyInfo propInfo = type.GetProperty(prop);

            System.ComponentModel.DescriptionAttribute attrib =
                (System.ComponentModel.DescriptionAttribute)propInfo.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false).FirstOrDefault();
            return(attrib.Description);
        }
        /// <summary>
        /// Add design time attributes.
        /// </summary>
        /// <param name="builder">The assembly attribute table builder.</param>
        private static void AddAttributes(AttributeTableBuilder builder)
        {
            builder.AddCustomAttributes(
                typeof(SignInButton),
                new Attribute[] {
                    new DefaultPropertyAttribute("ClientId"),
                    new DefaultEventAttribute("SessionChanged"),
                    new ToolboxBrowsableAttribute(true),
                    new ToolboxCategoryAttribute(LiveServicesCategory),
                    new ToolboxTabNameAttribute(LiveServicesCategory)});

            EditorBrowsableAttribute browsableAlways = new EditorBrowsableAttribute(EditorBrowsableState.Always);
            CategoryAttribute categoryLive = new CategoryAttribute(LiveServicesCategory);

            DescriptionAttribute description = new DescriptionAttribute(StringResources.DescriptionBrandingType);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "Branding",
                new Attribute[] { browsableAlways, categoryLive, description });

            description = new DescriptionAttribute(StringResources.DescriptionClientId);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "ClientId",
                new Attribute[] { browsableAlways, categoryLive, description });

            description = new DescriptionAttribute(StringResources.DescriptionRedirectUri);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "RedirectUri",
                new Attribute[] { browsableAlways, categoryLive, description });

            description = new DescriptionAttribute(StringResources.DescriptionScopes);
            DefaultValueAttribute defaultValue = new DefaultValueAttribute("wl.signin");
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "Scopes",
                new Attribute[] { browsableAlways, categoryLive, description, defaultValue });

            description = new DescriptionAttribute(StringResources.DescriptionTextType);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "TextType",
                new Attribute[] { browsableAlways, categoryLive, description });

            description = new DescriptionAttribute(StringResources.DescriptionSigninText);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "SignInText",
                new Attribute[] { browsableAlways, categoryLive, description });

            description = new DescriptionAttribute(StringResources.DescriptionSignoutText);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "SignOutText",
                new Attribute[] { browsableAlways, categoryLive, description });            
        }
Exemplo n.º 13
0
        public OptionPropertyValue(PropertyInfo propertyInfo, object owner, PropertyInfo defaultPropertyInfo)
        {
            this.propertyInfo = propertyInfo;
            this.owner = owner;
            displayName = this.propertyInfo.GetCustomAttribute<DisplayNameAttribute>();
            description = this.propertyInfo.GetCustomAttribute<DescriptionAttribute>();

            if (defaultPropertyInfo != null)
                DefaultValue = (string)defaultPropertyInfo.GetValue(owner);
        }
        static SendReplyDesigner()
        {
            AttributeTableBuilder builder = new AttributeTableBuilder();
            Type sendType = typeof(SendReply);

            builder.AddCustomAttributes(sendType, sendType.GetProperty("CorrelationInitializers"), PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor)));

            var categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(CorrelationsCategoryLabelKey));

            builder.AddCustomAttributes(sendType, sendType.GetProperty("CorrelationInitializers"), categoryAttribute, BrowsableAttribute.Yes,
                PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor)));

            categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(MiscellaneousCategoryLabelKey));

            builder.AddCustomAttributes(sendType, sendType.GetProperty("DisplayName"), categoryAttribute);
            var descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingValueHint", "<Value to bind>"));
            builder.AddCustomAttributes(sendType, sendType.GetProperty("Content"), categoryAttribute, descriptionAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(SendContentPropertyEditor)));
            builder.AddCustomAttributes(sendType, sendType.GetProperty("Request"),
                categoryAttribute,
                PropertyValueEditor.CreateEditorAttribute(typeof(ActivityXRefPropertyEditor)));

            var advancedAttribute = new EditorBrowsableAttribute(EditorBrowsableState.Advanced);
            builder.AddCustomAttributes(sendType, sendType.GetProperty("Action"), categoryAttribute, advancedAttribute);

            Action = sendType.GetProperty("Action").Name;

            Type sendMessageContentType = typeof(SendMessageContent);
            Message = sendMessageContentType.GetProperty("Message").Name;
            DeclaredMessageType = sendMessageContentType.GetProperty("DeclaredMessageType").Name;

            MetadataStore.AddAttributeTable(builder.CreateTable());

            Func<Activity, IEnumerable<ArgumentAccessor>> argumentAccessorGenerator = (activity) => new ArgumentAccessor[]
            {
                new ArgumentAccessor
                {
                    Getter = (ownerActivity) =>
                    {
                        SendReply sendReply = (SendReply)ownerActivity;
                        SendMessageContent content = sendReply.Content as SendMessageContent;
                        return content != null ? content.Message : null;
                    },
                    Setter = (ownerActivity, arg) =>
                    {
                        SendReply sendReply = (SendReply)ownerActivity;
                        SendMessageContent content = sendReply.Content as SendMessageContent;
                        if (content != null)
                        {
                            content.Message = arg as InArgument;
                        }
                    },
                },
            };
            ActivityArgumentHelper.RegisterAccessorsGenerator(sendType, argumentAccessorGenerator);
        }
Exemplo n.º 15
0
        public void EnumerationExtensions_GetAttributeOfType_ShouldMatch()
        {
            const TestEnum val1 = TestEnum.TestVal1;
            const TestEnum val2 = TestEnum.TestVal2;

            q.DescriptionAttribute attr1 = val1.GetAttributeOfType <q.DescriptionAttribute>();
            q.DescriptionAttribute attr2 = val2.GetAttributeOfType <q.DescriptionAttribute>();

            Assert.AreEqual(attr1.Description, "description of testval1");
            Assert.AreEqual(attr2.Description, "description of testval2");
        }
Exemplo n.º 16
0
        public void DescriptionAttributeTest()
        {
            string description          = "AssemblyName";
            DescriptionAttribute target = VisualStudio_Project_Samples_ResourcesDescriptionAttributeAccessor.CreatePrivate(description);

            Assert.IsNotNull(target, "ResourcesDescriptionAttribute instance was not created successfully.");

            VisualStudio_Project_Samples_ResourcesDescriptionAttributeAccessor accessor = new VisualStudio_Project_Samples_ResourcesDescriptionAttributeAccessor(target);

            Assert.IsNotNull(accessor.Description, "Description property value was uninitialized.");
        }
Exemplo n.º 17
0
        private static string GetDescriptionForEnum(Enum value)
        {
            FieldInfo fieldInfo = value.GetType().GetField(value.ToString());

            if (fieldInfo == null)
            {
                return(null);
            }

            Attr.DescriptionAttribute attribute = (Attr.DescriptionAttribute)fieldInfo.GetCustomAttribute(typeof(Attr.DescriptionAttribute));
            return(attribute?.Description);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 获取枚举的描述信息
        /// </summary>
        /// <param name="enumValue">枚举值</param>
        /// <returns>描述</returns>
        public static string GetDescription(this Enum enumValue)
        {
            string value = enumValue.ToString();

            System.Reflection.FieldInfo field = enumValue.GetType().GetField(value);
            object[] objs = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
            if (objs == null || objs.Length == 0)
            {
                return(value);
            }
            System.ComponentModel.DescriptionAttribute attr = (System.ComponentModel.DescriptionAttribute)objs[0];
            return(attr.Description);
        }
Exemplo n.º 19
0
        /// <summary>
        /// 获取某一个枚举的描述
        /// </summary>
        /// <param name="enumValue"></param>
        /// <returns></returns>
        public static string GetEnumDescription(Enum enumValue)
        {
            string str = enumValue.ToString();

            System.Reflection.FieldInfo field = enumValue.GetType().GetField(str);
            object[] objs = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
            if (objs.Length == 0)
            {
                return(str);
            }
            System.ComponentModel.DescriptionAttribute da = (System.ComponentModel.DescriptionAttribute)objs[0];
            return(da.Description);
        }
Exemplo n.º 20
0
 /// <summary>
 /// 根据fieldInfo 获取它对应的描述。
 /// </summary>
 /// <param name="field"></param>
 /// <param name="inherit"></param>
 /// <returns></returns>
 public string GetFieldDesc(FieldInfo field, bool inherit)
 {
     object[] desc = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), inherit);
     if (desc == null || desc.Length == 0)
     {
         return(string.Empty);
     }
     System.ComponentModel.DescriptionAttribute a = desc[0] as System.ComponentModel.DescriptionAttribute;
     if (a != null)
     {
         return(a.Description);
     }
     return(string.Empty);
 }
Exemplo n.º 21
0
 /// <summary>
 /// 获取枚举的description标签内容.
 /// </summary>
 /// <param name="enumType">类型</param>
 /// <param name="enumValue">枚举值</param>
 /// <returns></returns>
 public static string GetEnumDescription(Type enumType, string enumValue)
 {
     System.Reflection.FieldInfo finfo = enumType.GetField(enumValue);
     object[] enumAttr = finfo.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), true);
     if (enumAttr.Length > 0)
     {
         System.ComponentModel.DescriptionAttribute desc = enumAttr[0] as System.ComponentModel.DescriptionAttribute;
         if (desc != null)
         {
             return(desc.Description);
         }
     }
     return(enumValue);
 }
Exemplo n.º 22
0
        /// <summary>
        /// 根据对的象type 获取该对象的所有 propertys 描述。
        /// </summary>
        /// <param name="objType"></param>
        /// <param name="fTypes"></param>
        /// <param name="inherit"></param>
        /// <returns></returns>
        public string[] GetPropertysDesc(Type objType, PropertyType fTypes, bool inherit)
        {
            PropertyInfo[] infos = objType.GetProperties();
            ArrayList      aList = new ArrayList();

            foreach (PropertyInfo info in infos)
            {
                if ((fTypes & PropertyType.CanRead) == PropertyType.CanRead)
                {
                    if (!info.CanRead)
                    {
                        continue;
                    }
                }
                if ((fTypes & PropertyType.CanWrite) == PropertyType.CanWrite)
                {
                    if (!info.CanWrite)
                    {
                        continue;
                    }
                }
                if ((fTypes & PropertyType.IsSpecialName) == PropertyType.IsSpecialName)
                {
                    if (!info.IsSpecialName)
                    {
                        continue;
                    }
                }

                object[] desc = info.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), inherit);
                if (desc == null || desc.Length == 0)
                {
                    continue;
                }
                System.ComponentModel.DescriptionAttribute a = desc[0] as System.ComponentModel.DescriptionAttribute;
                if (a != null)
                {
                    aList.Add(a.Description);
                }
            }
            string[] des = new string[aList.Count];
            for (int i = 0; i < aList.Count; i++)
            {
                des[i] = aList[i].ToString();
            }
            return(des);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Creates a new field instance for the specified property.
 /// </summary>
 /// <param name="property">The property name.</param>
 /// <param name="databaseAttribute">The database attribute</param>
 public DbField(PropertyInfo property, DbAttribute databaseAttribute)
 {
     // Set the property.
     this.property = property;
     // Set the database attribute.
     this.databaseAttribute = databaseAttribute;
     // Set the database name.
     this.databaseName = this.databaseAttribute.Name;
     // Get the display name attributes.
     object[] displayNameAttributes = property.GetCustomAttributes(typeof(DisplayNameAttribute), true);
     // If at least one attribute exists, set the display name attribute.
     if (displayNameAttributes.Length > 0) this.displayNameAttribute = displayNameAttributes[0] as DisplayNameAttribute;
     // Get the description attributes.
     object[] descriptionAttributes = property.GetCustomAttributes(typeof(DescriptionAttribute), true);
     // If at least one attribute exists, set the description attribute.
     if (descriptionAttributes.Length > 0) this.descriptionAttribute = descriptionAttributes[0] as DescriptionAttribute;
 }
Exemplo n.º 24
0
        public static String ToEnumTypeDescription(this Type e)
        {
            String tmpstr = e.ToString();
            //获取字段信息
            FieldInfo ms = e.GetField(e.ToString());

            if (ms != null)
            {
                Object[] objs = ms.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);

                if (objs != null && objs.Length != 0)
                {
                    System.ComponentModel.DescriptionAttribute da = (System.ComponentModel.DescriptionAttribute)objs[0];
                    tmpstr = da.Description;
                }
            }
            return(tmpstr);
        }
Exemplo n.º 25
0
        private void MockData()
        {
            _setting = new Setting
            {
                Namespace   = "Timespans",
                Key         = SettingKey.RequestAutoCancelTimespan,
                Value       = "value",
                Description = "description"
            };

            _settingWithDefaultNamespace = new Setting
            {
                Namespace   = Setting.DefaultNamespace,
                Key         = SettingKey.RequestAutoCancelTimespan,
                Value       = "value1",
                Description = "description1"
            };

            _settingWithNullValue = new Setting
            {
                Namespace   = "Namespace",
                Key         = SettingKey.RequestAutoCancelTimespan,
                Value       = null,
                Description = "desc"
            };

            _defaultValueAttribute = new DefaultValueAttribute("defaultValue");
            _descriptionAttribute  = new DescriptionAttribute("description");
            _namespaceAttribute    = new NamespaceAttribute("namespace");

            _settingDto = new SettingDto
            {
                Key   = _setting.Key,
                Value = "new value"
            };

            _describedSettingDto = new DescribedSettingDto
            {
                Key          = _setting.Key,
                Value        = _setting.Value,
                Description  = _setting.Description,
                DefaultValue = _defaultValueAttribute.Value?.ToString()
            };
        }
Exemplo n.º 26
0
        public void FillOutComboBoxA()
        {
            Type t = typeof(GridData);

            PropertyInfo[] props = t.GetProperties();
            toolStripComboBox1.Items.Clear();
            toolStripComboBox2.Items.Clear();
            graphFields.Clear();
            foreach (PropertyInfo p in props)
            {
                object[] attributes = p.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
                System.ComponentModel.DescriptionAttribute da = (System.ComponentModel.DescriptionAttribute)attributes[0];
                toolStripComboBox1.Items.Add(da.Description);
                toolStripComboBox2.Items.Add(da.Description);
                graphFields.Add(da.Description, p.Name);
            }
            toolStripComboBox2.Items.Add("Disable Graph");
            toolStripComboBox1.SelectedIndex = 0;
            toolStripComboBox2.SelectedIndex = 7;
        }
Exemplo n.º 27
0
        public static string GetEnumDesc(Type enumType, object val)
        {
            string enumvalue = System.Enum.GetName(enumType, val);

            if (string.IsNullOrEmpty(enumvalue))
            {
                return("");
            }
            System.Reflection.FieldInfo finfo = enumType.GetField(enumvalue);
            object[] enumAttr = finfo.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), true);
            if (enumAttr.Length > 0)
            {
                System.ComponentModel.DescriptionAttribute desc = enumAttr[0] as System.ComponentModel.DescriptionAttribute;
                if (desc != null)
                {
                    return(desc.Description);
                }
            }
            return(enumvalue);
        }
Exemplo n.º 28
0
        /// <summary>
        /// 获取枚举的描述文本
        /// </summary>
        /// <param name="obj">枚举成员</param>
        /// <returns></returns>
        public static string GetEnumDescription(object obj)
        {
            System.Reflection.FieldInfo[] ms;
            try
            {
                //获取字段信息
                ms = obj.GetType().GetFields();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "获取枚举的描述文本异常");
                return("数据异常:" + ex.Message);
            }

            Type t = obj.GetType();

            foreach (System.Reflection.FieldInfo f in ms)
            {
                //判断名称是否相等
                if (f.Name != obj.ToString())
                {
                    continue;
                }

                //反射出自定义属性
                foreach (Attribute attr in f.GetCustomAttributes(true))
                {
                    //类型转换找到一个Description,用Description作为成员名称
                    System.ComponentModel.DescriptionAttribute dscript = attr as System.ComponentModel.DescriptionAttribute;
                    if (dscript != null)
                    {
                        return(dscript.Description);
                    }
                }
            }

            //如果没有检测到合适的注释,则用默认名称
            return(obj.ToString());
        }
Exemplo n.º 29
0
        public WrappedProperty(MemberDescriptor descr, PropertyView propertyView, Attribute[] attrs)
            : base(descr, attrs)
        {
            this.realPropertyDescriptor = (PropertyDescriptor) descr;
            this.name = propertyView.Name;
            this.displayName = propertyView.DisplayName;

            Attribute[] attribs = new Attribute[descr.Attributes.Count + 4];

            int i = 0;
            foreach (Attribute attrib in descr.Attributes)
            {
                attribs[i] = attrib;
                i++;
            }
            attribs[i] = new DescriptionAttribute(propertyView.Description);
            attribs[i + 1] = new CategoryAttribute(propertyView.Category);
            attribs[i + 2] = new DescriptionAttribute(propertyView.Description);
            attribs[i + 3] = new ReadOnlyAttribute(propertyView.IsReadOnly);

            attributes = new AttributeCollection(attribs);
        }
        public ObjectPropertyDescriptor(MemberDescriptor descr, IContext context, IPropertyMap propertyMap, object obj, Attribute[] attrs)
            : base(descr, attrs)
        {
            this.realPropertyDescriptor = (PropertyDescriptor) descr;
            this.name = propertyMap.Name;
            this.displayName = propertyMap.Name;

            Attribute[] attribs = new Attribute[descr.Attributes.Count + 4];

            int i = 0;
            foreach (Attribute attrib in descr.Attributes)
            {
                attribs[i] = attrib;
                i++;
            }
            attribs[i] = new DescriptionAttribute(propertyMap.Name + " is a property.");
            attribs[i + 1] = new CategoryAttribute("");
            attribs[i + 2] = new DefaultValueAttribute(context.ObjectManager.GetOriginalPropertyValue(obj, propertyMap.Name));
            attribs[i + 3] = new ReadOnlyAttribute(propertyMap.IsReadOnly);

            attributes = new AttributeCollection(attribs);
        }
Exemplo n.º 31
0
        /// <summary>
        /// 获取枚举值的详细文本
        /// </summary>
        /// <param name="e">object</param>
        /// <param name="enumType">枚举类型</param>
        /// <returns></returns>
        public static string GetEnumDescription(object e, Type enumType)
        {
            //获取字段信息
            System.Reflection.FieldInfo[] ms = enumType.GetFields();
            int  value;
            Type t = enumType;

            foreach (System.Reflection.FieldInfo f in ms)
            {
                //判断名称是否相等

                try
                {
                    value = (int)enumType.InvokeMember(f.Name, BindingFlags.GetField, null, null, null);
                    if (value != (int)e)
                    {
                        continue;
                    }
                }
                catch
                {
                    continue;
                }
                //反射出自定义属性
                foreach (Attribute attr in f.GetCustomAttributes(true))
                {
                    //类型转换找到一个Description,用Description作为成员名称
                    System.ComponentModel.DescriptionAttribute dscript = attr as System.ComponentModel.DescriptionAttribute;
                    if (dscript != null)
                    {
                        return(dscript.Description);
                    }
                }
            }

            //如果没有检测到合适的注释,则用默认名称
            return(e.ToString());
        }
Exemplo n.º 32
0
        /// <summary>
        /// 根据对象的类型和类属性的名称获取它对应的描述。
        /// </summary>
        /// <param name="objType"></param>
        /// <param name="propertyName"></param>
        /// <param name="inherit"></param>
        /// <returns></returns>
        public string GetPropertyDesc(Type objType, string propertyName, bool inherit)
        {
            PropertyInfo[] infos = objType.GetProperties();
            ArrayList      aList = new ArrayList();

            foreach (PropertyInfo info in infos)
            {
                if (string.Compare(info.Name, propertyName, true) == 0)
                {
                    object[] desc = info.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), inherit);
                    if (desc == null || desc.Length == 0)
                    {
                        continue;
                    }
                    System.ComponentModel.DescriptionAttribute a = desc[0] as System.ComponentModel.DescriptionAttribute;
                    if (a != null)
                    {
                        return(a.Description);
                    }
                }
            }
            return(null);
        }
 private static IDescribedAsFacet Create(DescriptionAttribute attribute, ISpecification holder) {
     return new DescribedAsFacetAnnotation(attribute.Description, holder);
 }
Exemplo n.º 34
0
        private static void ApplyAnnotation(XmlSchemaAnnotated annotatedType, DescriptionAttribute[] descriptionAtts,
            ConfigurationPropertyAttribute configProperty, string xmlDocumentation, string typeName, string fullName)
        {
            string standardDesc;

            if (configProperty != null)
            {
                standardDesc = configProperty.IsRequired ? "Required" : "Optional";
                standardDesc += " " + fullName;
                standardDesc += " " +
                                (configProperty.DefaultValue == null || configProperty.DefaultValue.ToString() == "System.Object"
                                    ? string.Empty
                                    : "[" + configProperty.DefaultValue + "]");
            }
            else
            {
                standardDesc = string.Empty;
            }

            var documentation = new XmlSchemaDocumentation();
            if (descriptionAtts.Length > 0)
            {
                documentation.Markup = TextToNodeArray(descriptionAtts[0].Description + " " + standardDesc);
            }
            else if (!String.IsNullOrEmpty(xmlDocumentation))
            {
                // normalise line endings and remove trailing whitespace(s)
                xmlDocumentation = Regex.Replace(xmlDocumentation, @"\s*(\r\n|\n\r|\n|\r)", "\r\n");

                documentation.Markup = TextToNodeArray(xmlDocumentation);
            }
            else
            {
                documentation.Markup = TextToNodeArray(standardDesc);
            }

            //  machine documentation
            var appInfo = new XmlSchemaAppInfo
            {
                Markup = TextToNodeArray(typeName)
            };

            //  add the documentation to the object
            annotatedType.Annotation.Items.Add(documentation);
            annotatedType.Annotation.Items.Add(appInfo);
        }
 public void SetDescription( string description )
 {
     var attr = (DescriptionAttribute)attributes.FirstOrDefault(a => a is DescriptionAttribute);
     if (attr != null)
     {
         attributes.RemoveAll(a => a is DescriptionAttribute);
     }
     attr = new DescriptionAttribute(description);
     attributes.Add(attr);
 }
Exemplo n.º 36
0
        private TableItem(Type type)
        {
            _EntityType = type;
            _Table = type.GetCustomAttribute<BindTableAttribute>(true);
            if (_Table == null) throw new ArgumentOutOfRangeException("type", "类型" + type + "没有" + typeof(BindTableAttribute).Name + "特性!");

            _Indexes = type.GetCustomAttributes<BindIndexAttribute>(true);
            _Relations = type.GetCustomAttributes<BindRelationAttribute>(true);

            _Description = type.GetCustomAttribute<DescriptionAttribute>(true);

            _ModelCheckMode = type.GetCustomAttribute<ModelCheckModeAttribute>(true);

            InitFields();
        }
Exemplo n.º 37
0
        /// <summary>
        /// Initializes a new instance of <see cref="T:Dataweb.NShape.Advanced.PropertyDescriptorDg" />
        /// </summary>
        public PropertyDescriptorDg(IPropertyController controller, PropertyDescriptor descriptor, Attribute[] attributes)
            : base(descriptor.Name, attributes)
        {
            this.descriptor = descriptor;
            this.controller = controller;

            // We have to store the attributes and return their values in the appropriate
            // methods because if we don't, modifying the readonly attribute will not work
            browsableAttr = Attributes[typeof(BrowsableAttribute)] as BrowsableAttribute;
            readOnlyAttr = Attributes[typeof(ReadOnlyAttribute)] as ReadOnlyAttribute;
            descriptionAttr = Attributes[typeof(DescriptionAttribute)] as DescriptionAttribute;
            permissionAttr = descriptor.Attributes[typeof(RequiredPermissionAttribute)] as RequiredPermissionAttribute;
        }
Exemplo n.º 38
0
		/// <ToBeCompleted></ToBeCompleted>
		protected DescriptionAttribute GetNotGrantedDescription(DescriptionAttribute descAttr, Permission permission)
		{
			return new DescriptionAttribute(
				string.Format("{0}{1}{1}Property is read only because you don't have the permission for '{2}'.",
				              (descAttr != null) ? descAttr.Description : string.Empty,
				              (descAttr != null) ? Environment.NewLine : string.Empty,
				              permission
					)
				);
		}
Exemplo n.º 39
0
        /// <summary>
        /// 由类型内获取需变更属性
        /// </summary>
        /// <param name="t">传入类型</param>
        /// <returns>成功返回需设置变更的信息</returns>
        private List <Neusoft.FrameWork.Models.NeuObject> GetProperty(Type t)
        {
            //获取类的DisplayName属性 用于类中文名称
            object[] display = t.GetCustomAttributes(false);
            if (display != null)
            {
                foreach (object oDisplay in display)
                {
                    if (oDisplay is System.ComponentModel.DisplayNameAttribute)
                    {
                        System.ComponentModel.DisplayNameAttribute displayAttribute = oDisplay as System.ComponentModel.DisplayNameAttribute;

                        this.lbDescrip.Text = displayAttribute.DisplayName;

                        break;
                    }
                }
            }
            //获取类型内所有的属性Property
            PropertyInfo[] propertyCollection = t.GetProperties();

            List <Neusoft.FrameWork.Models.NeuObject> recordList = new List <Neusoft.FrameWork.Models.NeuObject>();

            //对类型内属性进行循环判断
            foreach (PropertyInfo p in propertyCollection)
            {
                //对只读或只写属性不进行处理
                if (p.CanRead && p.CanWrite)
                {
                    string propertyID      = "";
                    string propertyName    = "";
                    string propertyDescrip = "";
                    //获取对每个属性设置的属性 (Property的Attribute)
                    foreach (Attribute a in p.GetCustomAttributes(true))
                    {
                        //属性中文名称显示
                        if (a is System.ComponentModel.DisplayNameAttribute)
                        {
                            System.ComponentModel.DisplayNameAttribute displayName = a as System.ComponentModel.DisplayNameAttribute;

                            propertyName = displayName.DisplayName;
                        }
                        //属性描述
                        if (a is System.ComponentModel.DescriptionAttribute)
                        {
                            System.ComponentModel.DescriptionAttribute descrip = a as System.ComponentModel.DescriptionAttribute;

                            propertyDescrip = descrip.Description;
                        }
                    }
                    //如 存在有效数据 进行保存 ID Name不能为空
                    if (propertyName != "")
                    {
                        Neusoft.FrameWork.Models.NeuObject shiftProperty = new Neusoft.FrameWork.Models.NeuObject();
                        shiftProperty.ID   = p.Name;
                        shiftProperty.Name = propertyName;
                        shiftProperty.Memo = propertyDescrip;

                        recordList.Add(shiftProperty);
                    }
                }
            }

            return(recordList);
        }
Exemplo n.º 40
0
        /// <summary>构造函数</summary>
        /// <param name="table"></param>
        /// <param name="property"></param>
        public FieldItem(TableItem table, PropertyInfo property)
        {
            if (property == null) throw new ArgumentNullException("property");

            _Table = table;

            _Property = property;
            _Column = BindColumnAttribute.GetCustomAttribute(_Property);
            _DataObjectField = DataObjectAttribute.GetCustomAttribute(_Property, typeof(DataObjectFieldAttribute)) as DataObjectFieldAttribute;
            _Description = DescriptionAttribute.GetCustomAttribute(_Property, typeof(DescriptionAttribute)) as DescriptionAttribute;
        }
Exemplo n.º 41
0
 private string GetDisplayStringValue(DescriptionAttribute[] a)
 {
     if (a == null || a.Length == 0) return null;
     DescriptionAttribute dsa = a[0];
     return dsa.Description;
 }
Exemplo n.º 42
0
        /// <summary>
        /// 根据对象的type 获取它的所有field 的描述
        /// </summary>
        /// <param name="objType"></param>
        /// <param name="fTypes"></param>
        /// <param name="inherit"></param>
        /// <returns></returns>
        public string[] GetFieldsDesc(Type objType, ClassFieldType fTypes, bool inherit)
        {
            FieldInfo[] infos = objType.GetFields();
            ArrayList   aList = new ArrayList();

            foreach (FieldInfo info in infos)
            {
                if ((fTypes & ClassFieldType.IsPrivate) == ClassFieldType.IsPrivate)
                {
                    if (!info.IsPrivate)
                    {
                        continue;
                    }
                }
                if ((fTypes & ClassFieldType.IsPublic) == ClassFieldType.IsPublic)
                {
                    if (!info.IsPublic)
                    {
                        continue;
                    }
                }
                if ((fTypes & ClassFieldType.IsStatic) == ClassFieldType.IsStatic)
                {
                    if (!info.IsStatic)
                    {
                        continue;
                    }
                }
                if ((fTypes & ClassFieldType.IsSpecialName) == ClassFieldType.IsSpecialName)
                {
                    if (!info.IsSpecialName)
                    {
                        continue;
                    }
                }
                if ((fTypes & ClassFieldType.IsInitOnly) == ClassFieldType.IsInitOnly)
                {
                    if (!info.IsInitOnly)
                    {
                        continue;
                    }
                }

                object[] desc = info.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), inherit);
                if (desc == null || desc.Length == 0)
                {
                    continue;
                }
                System.ComponentModel.DescriptionAttribute a = desc[0] as System.ComponentModel.DescriptionAttribute;
                if (a != null)
                {
                    aList.Add(a.Description);
                }
            }
            string[] des = new string[aList.Count];
            for (int i = 0; i < aList.Count; i++)
            {
                des[i] = aList[i].ToString();
            }
            return(des);
        }
Exemplo n.º 43
0
        private Type ValidateGeneratedEnum(Type serverEnumType, AssemblyGenerator asmGen)
        {
            Type clientEnumType = asmGen.GetGeneratedType(serverEnumType.FullName);

            Assert.IsNotNull(clientEnumType, "Expected to see generated " + serverEnumType + " but saw " + asmGen.GeneratedTypeNames);

            // validate the enum integral type is the same
            Type serverUnderlyingType = serverEnumType.GetEnumUnderlyingType();
            Type clientUnderlyingType = clientEnumType.GetEnumUnderlyingType();

            Assert.AreEqual(serverUnderlyingType.FullName, clientUnderlyingType.FullName, "Mismatch in server enum type's underlying type and generated form");

            DataContractAttribute serverDCAttr = (DataContractAttribute)Attribute.GetCustomAttribute(serverEnumType, typeof(DataContractAttribute));

            if (serverDCAttr != null)
            {
                IList <CustomAttributeData> cads = AssemblyGenerator.GetCustomAttributeData(clientEnumType, typeof(DataContractAttribute));
                Assert.AreEqual(1, cads.Count, "Expected DataContract on " + clientEnumType);
                CustomAttributeData cad    = cads[0];
                string serverAttrName      = serverDCAttr.Name;
                string serverAttrNamespace = serverDCAttr.Namespace;
                string clientAttrName      = AssemblyGenerator.GetCustomAttributeValue <string>(cad, "Name");
                string clientAttrNamespace = AssemblyGenerator.GetCustomAttributeValue <string>(cad, "Namespace");

                Assert.AreEqual(serverAttrName, clientAttrName, "Expected DC.Name to be the same on " + clientEnumType);
                Assert.AreEqual(serverAttrNamespace, clientAttrNamespace, "Expected DC.Namespace to be the same on " + clientEnumType);
            }

            string[] serverMemberNames = Enum.GetNames(serverEnumType);
            string[] clientMemberNames = Enum.GetNames(clientEnumType);
            Assert.AreEqual(serverMemberNames.Length, clientMemberNames.Length, "Different number of fields generated");

            for (int i = 0; i < serverMemberNames.Length; ++i)
            {
                Assert.AreEqual(serverMemberNames[i], clientMemberNames[i], "Member name difference");

                // We have to use GetRawConstantValue because the ReflectionOnlyLoad does not support Enum.GetValues
                FieldInfo serverFieldInfo = serverEnumType.GetField(serverMemberNames[i]);
                Assert.IsNotNull(serverFieldInfo, "Failed to find server's " + serverMemberNames[i] + " as field info");
                object serverMemberValue = serverFieldInfo.GetRawConstantValue();

                FieldInfo clientFieldInfo = clientEnumType.GetField(clientMemberNames[i]);
                Assert.IsNotNull(clientFieldInfo, "Failed to find client's " + clientMemberNames[i] + " as field info");
                object clientMemberValue = clientFieldInfo.GetRawConstantValue();

                Assert.AreEqual(serverMemberValue, clientMemberValue, "Different values for field " + serverMemberNames[i]);

                EnumMemberAttribute enumMemberAttr = (EnumMemberAttribute)Attribute.GetCustomAttribute(serverFieldInfo, typeof(EnumMemberAttribute));
                if (enumMemberAttr != null)
                {
                    IList <CustomAttributeData> cads = AssemblyGenerator.GetCustomAttributeData(clientFieldInfo, typeof(EnumMemberAttribute));
                    Assert.AreEqual(1, cads.Count, "Expected EnumMember on " + clientEnumType + "." + clientMemberNames[i]);
                    CustomAttributeData cad = cads[0];
                    string clientValue      = null;
                    AssemblyGenerator.TryGetCustomAttributeValue <string>(cad, "Value", out clientValue);

                    string serverValue = enumMemberAttr.Value;
                    Assert.AreEqual(serverValue, clientValue, "EnumMember had different values for Value arg for " + clientEnumType + "." + clientMemberNames[i]);
                }

                // Validate Display custom attribute propagates correctly
                DisplayAttribute displayAttr = (DisplayAttribute)Attribute.GetCustomAttribute(serverFieldInfo, typeof(DisplayAttribute));
                if (displayAttr != null)
                {
                    IList <CustomAttributeData> cads = AssemblyGenerator.GetCustomAttributeData(clientFieldInfo, typeof(DisplayAttribute));
                    Assert.AreEqual(1, cads.Count, "Expected [Display] on " + clientEnumType + "." + clientMemberNames[i]);
                    CustomAttributeData cad = cads[0];
                    string clientValue      = null;
                    AssemblyGenerator.TryGetCustomAttributeValue <string>(cad, "Name", out clientValue);

                    string serverValue = displayAttr.Name;
                    Assert.AreEqual(serverValue, clientValue, "[Display] had different values for Name arg for " + clientEnumType + "." + clientMemberNames[i]);
                }

                // Validate Description custom attribute propagates correctly
                ComponentModelDescriptionAttribute descriptionAttr = (ComponentModelDescriptionAttribute)Attribute.GetCustomAttribute(serverFieldInfo, typeof(ComponentModelDescriptionAttribute));
                if (descriptionAttr != null)
                {
                    IList <CustomAttributeData> cads = AssemblyGenerator.GetCustomAttributeData(clientFieldInfo, typeof(ComponentModelDescriptionAttribute));
                    Assert.AreEqual(1, cads.Count, "Expected [Description] on " + clientEnumType + "." + clientMemberNames[i]);
                    CustomAttributeData cad = cads[0];
                    string clientValue      = null;
                    AssemblyGenerator.TryGetCustomAttributeValue <string>(cad, "Description", out clientValue);

                    string serverValue = descriptionAttr.Description;
                    Assert.AreEqual(serverValue, clientValue, "[Description] had different values for Description arg for " + clientEnumType + "." + clientMemberNames[i]);
                }

                // Validate ServerOnlyAttribute does not propagate
                ServerOnlyAttribute serverOnlyAttr = (ServerOnlyAttribute)Attribute.GetCustomAttribute(serverFieldInfo, typeof(ServerOnlyAttribute));
                if (serverOnlyAttr != null)
                {
                    IList <CustomAttributeData> cads = AssemblyGenerator.GetCustomAttributeData(clientFieldInfo, typeof(ServerOnlyAttribute));
                    Assert.AreEqual(0, cads.Count, "Expected [ServerOnlyAttribute] *not* to be generated on " + clientEnumType + "." + clientMemberNames[i]);
                }
            }

            bool serverHasFlags = serverEnumType.GetCustomAttributes(false).OfType <FlagsAttribute>().Any();

            // Have to use CustomAttributeData due to ReflectionOnly load
            IList <CustomAttributeData> clientFlagsAttributes = AssemblyGenerator.GetCustomAttributeData(clientEnumType, typeof(FlagsAttribute));
            bool clientHasFlags = clientFlagsAttributes.Any();

            Assert.AreEqual(serverHasFlags, clientHasFlags, "Server and client differ in appearance of [Flags]");

            return(clientEnumType);
        }
        static ReceiveDesigner()
        {
            AttributeTableBuilder builder = new AttributeTableBuilder();
            Type receiveType = typeof(Receive);

            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelationInitializers"), PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor)));

            var categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(CorrelationsCategoryLabelKey));
            var descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingCorrelatesWithHint", "<Correlation handle>"));
            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelatesWith"), categoryAttribute, descriptionAttribute);

            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelatesOn"), categoryAttribute, BrowsableAttribute.Yes,
                PropertyValueEditor.CreateEditorAttribute(typeof(CorrelatesOnValueEditor)));
            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelationInitializers"), categoryAttribute, BrowsableAttribute.Yes,
                PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor)));

            categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(MiscellaneousCategoryLabelKey));
            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("DisplayName"), categoryAttribute);
            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("OperationName"), categoryAttribute);
            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("ServiceContractName"), categoryAttribute, new TypeConverterAttribute(typeof(XNameConverter)));
            descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingValueHint", "<Value to bind>"));
            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("Content"), categoryAttribute, descriptionAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(ReceiveContentPropertyEditor)));

            var advancedAttribute = new EditorBrowsableAttribute(EditorBrowsableState.Advanced);
            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("Action"), advancedAttribute, categoryAttribute);
            builder.AddCustomAttributes(
                receiveType,
                "KnownTypes",
                advancedAttribute,
                categoryAttribute,
                PropertyValueEditor.CreateEditorAttribute(typeof(TypeCollectionPropertyEditor)),
                new EditorOptionAttribute { Name = TypeCollectionPropertyEditor.AllowDuplicate, Value = false });

            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("ProtectionLevel"), advancedAttribute, categoryAttribute);
            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("SerializerOption"), advancedAttribute, categoryAttribute);
            builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CanCreateInstance"), advancedAttribute, categoryAttribute);

            Action = receiveType.GetProperty("Action").Name;

            Type receiveMessageContentType = typeof(ReceiveMessageContent);
            Message = receiveMessageContentType.GetProperty("Message").Name;
            DeclaredMessageType = receiveMessageContentType.GetProperty("DeclaredMessageType").Name;
            MetadataStore.AddAttributeTable(builder.CreateTable());

            Func<Activity, IEnumerable<ArgumentAccessor>> argumentAccessorGenerator = (activity) => new ArgumentAccessor[]
            {
                new ArgumentAccessor
                {
                    Getter = (ownerActivity) =>
                    {
                        Receive receive = (Receive)ownerActivity;
                        ReceiveMessageContent content = receive.Content as ReceiveMessageContent;
                        return content != null ? content.Message : null;
                    },
                    Setter = (ownerActivity, arg) =>
                    {
                        Receive receive = (Receive)ownerActivity;
                        ReceiveMessageContent content = receive.Content as ReceiveMessageContent;
                        if (content != null)
                        {
                            content.Message = arg as OutArgument;
                        }
                    },
                },
            };
            ActivityArgumentHelper.RegisterAccessorsGenerator(receiveType, argumentAccessorGenerator);
        }
		private static Attribute[] CreateAttributes(IImageProperty imageProperty)
		{
			CategoryAttribute category = new CategoryAttribute(imageProperty.Category);
			DescriptionAttribute description = new DescriptionAttribute(imageProperty.Description);
			EditorAttribute editor = new EditorAttribute(typeof(ShowValueEditor), typeof(UITypeEditor));

			return new Attribute[] { category, description, editor };
		}