private static bool TryGetArgumentValueAs <T>(IServiceProvider serviceProvider, AttributeInfo attribInfo, string propertyName, out T propertyValue)
        {
            string[] argumentNames = GetAttributePropertyNames(attribInfo);
            int      argumentIndex = -1;

            for (int index = 0; index < argumentNames.Length; index++)
            {
                // skip unnamed arguments these are constructor arguments
                if (string.IsNullOrEmpty((argumentNames[index])))
                {
                    continue;
                }
                else
                {
                    if (argumentNames[index].Equals(propertyName))
                    {
                        argumentIndex = index;
                        break;
                    }
                }
            }
            if (argumentIndex == -1)
            {
                propertyValue = default(T);
                return(false);
            }
            propertyValue = (T)attribInfo.GetArgumentValueAs(serviceProvider, argumentIndex, typeof(T));
            return(true);
        }
예제 #2
0
        T GetAttributePropertyValue <T>(IServiceProvider provider, AttributeInfo attribInfo, string propertyName)
        {
            string[] argumentNames = GetAttributePropertyNames(attribInfo);
            int      argumentIndex = -1;

            for (int index = 0; index < argumentNames.Length; index++)
            {
                // skip unnamed arguments these are constructor arguments
                if ((argumentNames[index] == null) || (argumentNames[index].Length == 0))
                {
                    continue;
                }
                else
                {
                    if (argumentNames[index].Equals(propertyName))
                    {
                        argumentIndex = index;
                        break;
                    }
                }
            }
            if (argumentIndex != -1)
            {
                return((T)attribInfo.GetArgumentValueAs(provider, argumentIndex, typeof(T)));
            }
            else
            {
                return(default(T));
            }
        }
예제 #3
0
        private static CustomProperty CreateCustomProperty(IServiceProvider serviceProvider, Type customActivityType, MemberInfo member, Type propertyType)
        {
            CustomProperty customProperty = new CustomProperty(serviceProvider);

            customProperty.Name    = member.Name;
            customProperty.IsEvent = (member is EventInfo);

            if (propertyType == typeof(ActivityBind))
            {
                customProperty.GenerateDependencyProperty = false;
                customProperty.Type = typeof(ActivityBind).FullName;
            }
            else
            {
                string    fieldSuffix = (customProperty.IsEvent) ? "Event" : "Property";
                FieldInfo fieldInfo   = customActivityType.GetField(member.Name + fieldSuffix, BindingFlags.Public | BindingFlags.Static);
                if ((fieldInfo != null && fieldInfo.FieldType == typeof(DependencyProperty)))
                {
                    customProperty.GenerateDependencyProperty = true;
                }
                else
                {
                    customProperty.GenerateDependencyProperty = false;
                }

                customProperty.Type = propertyType.FullName;
            }

            customProperty.oldPropertyName = member.Name;
            customProperty.oldPropertyType = propertyType.FullName;

            object[] hiddenCodeAttributes = member.GetCustomAttributes(typeof(FlagsAttribute), true);
            if (hiddenCodeAttributes != null && hiddenCodeAttributes.Length > 0)
            {
                customProperty.Hidden = true;
            }

            foreach (object attributeObj in member.GetCustomAttributes(false))
            {
                AttributeInfoAttribute attribute     = attributeObj as AttributeInfoAttribute;
                AttributeInfo          attributeInfo = (attribute != null) ? attribute.AttributeInfo : null;
                if (attributeInfo != null)
                {
                    try
                    {
                        if (attributeInfo.AttributeType == typeof(BrowsableAttribute) && attributeInfo.ArgumentValues.Count > 0)
                        {
                            customProperty.Browseable = (bool)attributeInfo.GetArgumentValueAs(serviceProvider, 0, typeof(bool));
                        }
                        else if (attributeInfo.AttributeType == typeof(CategoryAttribute) && attributeInfo.ArgumentValues.Count > 0)
                        {
                            customProperty.Category = attributeInfo.GetArgumentValueAs(serviceProvider, 0, typeof(string)) as string;
                        }
                        else if (attributeInfo.AttributeType == typeof(DescriptionAttribute) && attributeInfo.ArgumentValues.Count > 0)
                        {
                            customProperty.Description = attributeInfo.GetArgumentValueAs(serviceProvider, 0, typeof(string)) as string;
                        }
                        else if (attributeInfo.AttributeType == typeof(DesignerSerializationVisibilityAttribute) && attributeInfo.ArgumentValues.Count > 0)
                        {
                            customProperty.DesignerSerializationVisibility = (DesignerSerializationVisibility)attributeInfo.GetArgumentValueAs(serviceProvider, 0, typeof(DesignerSerializationVisibility));
                        }
                        else if (attributeInfo.AttributeType == typeof(EditorAttribute) && attributeInfo.ArgumentValues.Count > 1)
                        {
                            Type editorType = attributeInfo.GetArgumentValueAs(serviceProvider, 1, typeof(Type)) as Type;
                            if (editorType == typeof(UITypeEditor))
                            {
                                Type uiTypeEditorType = attributeInfo.GetArgumentValueAs(serviceProvider, 0, typeof(Type)) as Type;
                                if (uiTypeEditorType != null)
                                {
                                    customProperty.UITypeEditor = uiTypeEditorType.FullName;
                                }

                                if (String.IsNullOrEmpty(customProperty.UITypeEditor))
                                {
                                    customProperty.UITypeEditor = attributeInfo.GetArgumentValueAs(serviceProvider, 0, typeof(string)) as string;
                                }
                            }
                        }
                    }
                    catch
                    {
                        // Catch and ignore all attribute value conversion errors
                    }
                }
            }

            return(customProperty);
        }
        private static CustomProperty CreateCustomProperty(IServiceProvider serviceProvider, System.Type customActivityType, MemberInfo member, System.Type propertyType)
        {
            CustomProperty property = new CustomProperty(serviceProvider)
            {
                Name    = member.Name,
                IsEvent = member is EventInfo
            };

            if (propertyType == typeof(ActivityBind))
            {
                property.GenerateDependencyProperty = false;
                property.Type = typeof(ActivityBind).FullName;
            }
            else
            {
                FieldInfo field = customActivityType.GetField(member.Name + (property.IsEvent ? "Event" : "Property"), BindingFlags.Public | BindingFlags.Static);
                if ((field != null) && (field.FieldType == typeof(DependencyProperty)))
                {
                    property.GenerateDependencyProperty = true;
                }
                else
                {
                    property.GenerateDependencyProperty = false;
                }
                property.Type = propertyType.FullName;
            }
            property.oldPropertyName = member.Name;
            property.oldPropertyType = propertyType.FullName;
            object[] customAttributes = member.GetCustomAttributes(typeof(FlagsAttribute), true);
            if ((customAttributes != null) && (customAttributes.Length > 0))
            {
                property.Hidden = true;
            }
            foreach (object obj2 in member.GetCustomAttributes(false))
            {
                AttributeInfoAttribute attribute = obj2 as AttributeInfoAttribute;
                AttributeInfo          info2     = (attribute != null) ? attribute.AttributeInfo : null;
                if (info2 != null)
                {
                    try
                    {
                        if ((info2.AttributeType == typeof(BrowsableAttribute)) && (info2.ArgumentValues.Count > 0))
                        {
                            property.Browseable = (bool)info2.GetArgumentValueAs(serviceProvider, 0, typeof(bool));
                        }
                        else if ((info2.AttributeType == typeof(CategoryAttribute)) && (info2.ArgumentValues.Count > 0))
                        {
                            property.Category = info2.GetArgumentValueAs(serviceProvider, 0, typeof(string)) as string;
                        }
                        else if ((info2.AttributeType == typeof(DescriptionAttribute)) && (info2.ArgumentValues.Count > 0))
                        {
                            property.Description = info2.GetArgumentValueAs(serviceProvider, 0, typeof(string)) as string;
                        }
                        else if ((info2.AttributeType == typeof(DesignerSerializationVisibilityAttribute)) && (info2.ArgumentValues.Count > 0))
                        {
                            property.DesignerSerializationVisibility = (DesignerSerializationVisibility)info2.GetArgumentValueAs(serviceProvider, 0, typeof(DesignerSerializationVisibility));
                        }
                        else if ((info2.AttributeType == typeof(EditorAttribute)) && (info2.ArgumentValues.Count > 1))
                        {
                            System.Type type = info2.GetArgumentValueAs(serviceProvider, 1, typeof(System.Type)) as System.Type;
                            if (type == typeof(UITypeEditor))
                            {
                                System.Type type2 = info2.GetArgumentValueAs(serviceProvider, 0, typeof(System.Type)) as System.Type;
                                if (type2 != null)
                                {
                                    property.UITypeEditor = type2.FullName;
                                }
                                if (string.IsNullOrEmpty(property.UITypeEditor))
                                {
                                    property.UITypeEditor = info2.GetArgumentValueAs(serviceProvider, 0, typeof(string)) as string;
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
            return(property);
        }