public static CustomProperty CreateCustomProperty(IServiceProvider serviceProvider, string customPropertyName, PropertyDescriptor propertyDescriptor, object propertyOwner) { CustomProperty property = new CustomProperty(serviceProvider) { Name = customPropertyName }; if (TypeProvider.IsAssignable(typeof(ActivityBind), propertyDescriptor.PropertyType)) { System.Type type = PropertyDescriptorUtils.GetBaseType(propertyDescriptor, propertyOwner, serviceProvider); if (type == null) { throw new InvalidOperationException(SR.GetString("Error_CantDeterminePropertyBaseType", new object[] { propertyDescriptor.Name })); } property.Type = type.FullName; } else { property.Type = propertyDescriptor.PropertyType.FullName; } if (propertyDescriptor is ActivityBindPropertyDescriptor) { DependencyProperty property2 = DependencyProperty.FromName(propertyDescriptor.Name, propertyDescriptor.ComponentType); property.IsEvent = (property2 != null) && property2.IsEvent; } property.Category = propertyDescriptor.Category; return property; }
private static AttributeInfo[] CreateCustomPropertyAttributeArray(CustomProperty property, IServiceProvider serviceProvider) { if ((property == null) || property.Hidden) { return(new AttributeInfo[0]); } List <AttributeInfo> list = new List <AttributeInfo>(); if (property.Category != null) { list.Add(new AttributeInfo(typeof(CategoryAttribute), new string[0], new object[] { new CodePrimitiveExpression(property.Category) })); } if (property.Description != null) { list.Add(new AttributeInfo(typeof(DescriptionAttribute), new string[0], new object[] { new CodePrimitiveExpression(property.Description) })); } if (!string.IsNullOrEmpty(property.UITypeEditor)) { list.Add(new AttributeInfo(typeof(EditorAttribute), new string[0], new object[] { new CodeTypeOfExpression(property.UITypeEditor), new CodeTypeOfExpression(typeof(UITypeEditor)) })); } list.Add(new AttributeInfo(typeof(BrowsableAttribute), new string[0], new object[] { new CodePrimitiveExpression(property.Browseable) })); list.Add(new AttributeInfo(typeof(DesignerSerializationVisibilityAttribute), new string[0], new object[] { new CodeSnippetExpression(typeof(DesignerSerializationVisibility).Name + "." + property.DesignerSerializationVisibility.ToString()) })); return(list.ToArray()); }
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; }
private static bool ArePropertiesDifferent(CustomProperty property, CustomProperty oldProperty) { if ((((property.Name == oldProperty.Name) && (property.Type == oldProperty.Type)) && ((property.Browseable == oldProperty.Browseable) && (property.Category == oldProperty.Category))) && (((property.Description == oldProperty.Description) && (property.DesignerSerializationVisibility == oldProperty.DesignerSerializationVisibility)) && ((property.Hidden == oldProperty.Hidden) && (property.UITypeEditor == oldProperty.UITypeEditor)))) { return false; } return true; }
private static AttributeInfo[] CreateCustomPropertyAttributeArray(CustomProperty property, IServiceProvider serviceProvider) { if ((property == null) || property.Hidden) { return new AttributeInfo[0]; } List<AttributeInfo> list = new List<AttributeInfo>(); if (property.Category != null) { list.Add(new AttributeInfo(typeof(CategoryAttribute), new string[0], new object[] { new CodePrimitiveExpression(property.Category) })); } if (property.Description != null) { list.Add(new AttributeInfo(typeof(DescriptionAttribute), new string[0], new object[] { new CodePrimitiveExpression(property.Description) })); } if (!string.IsNullOrEmpty(property.UITypeEditor)) { list.Add(new AttributeInfo(typeof(EditorAttribute), new string[0], new object[] { new CodeTypeOfExpression(property.UITypeEditor), new CodeTypeOfExpression(typeof(UITypeEditor)) })); } list.Add(new AttributeInfo(typeof(BrowsableAttribute), new string[0], new object[] { new CodePrimitiveExpression(property.Browseable) })); list.Add(new AttributeInfo(typeof(DesignerSerializationVisibilityAttribute), new string[0], new object[] { new CodeSnippetExpression(typeof(DesignerSerializationVisibility).Name + "." + property.DesignerSerializationVisibility.ToString()) })); return list.ToArray(); }
private static void AddNewProperties(List <CustomProperty> propCollection, Type customActivityType, IServiceProvider serviceProvider, List <CustomProperty> existingProps) { IMemberCreationService memberCreationService = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (memberCreationService == null) { throw new Exception(SR.GetString(SR.General_MissingService, typeof(IMemberCreationService).FullName)); } ITypeProvider typeProvider = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider == null) { throw new Exception(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName)); } try { // foreach (CustomProperty property in propCollection) { bool createNew = (property.oldPropertyName == null || property.oldPropertyType == null); if (!createNew) { if (!property.IsEvent) { createNew = (customActivityType.GetProperty(property.oldPropertyName, typeProvider.GetType(property.oldPropertyType)) == null); } else { createNew = (customActivityType.GetEvent(property.oldPropertyName) == null); } } if (createNew) { AttributeInfo[] attributes = CreateCustomPropertyAttributeArray(property, serviceProvider); if (property.IsEvent) { memberCreationService.CreateEvent(customActivityType.FullName, property.Name, typeProvider.GetType(property.Type), attributes, property.GenerateDependencyProperty); } else { memberCreationService.CreateProperty(customActivityType.FullName, property.Name, typeProvider.GetType(property.Type), attributes, property.GenerateDependencyProperty, false, false, null, false); } } else { // CustomProperty oldProperty = null; foreach (CustomProperty existingProperty in existingProps) { if (existingProperty.Name == property.oldPropertyName && existingProperty.Type == property.oldPropertyType) { oldProperty = existingProperty; } } if (oldProperty == null || ArePropertiesDifferent(property, oldProperty)) { AttributeInfo[] attributes = CreateCustomPropertyAttributeArray(property, serviceProvider); AttributeInfo[] oldAttributes = CreateCustomPropertyAttributeArray(oldProperty, serviceProvider); Type propertyType = typeProvider.GetType(property.Type, false); Type oldPropertyType = typeProvider.GetType(property.oldPropertyType, false); if (propertyType != null) { if (property.IsEvent) { memberCreationService.UpdateEvent(customActivityType.FullName, property.oldPropertyName, oldPropertyType, property.Name, propertyType, attributes, property.GenerateDependencyProperty, false); } else { memberCreationService.UpdateProperty(customActivityType.FullName, property.oldPropertyName, oldPropertyType, property.Name, propertyType, attributes, property.GenerateDependencyProperty, false); } } } } } } finally { // } }
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); }
private static void AddNewProperties(List <CustomProperty> propCollection, System.Type customActivityType, IServiceProvider serviceProvider, List <CustomProperty> existingProps) { IMemberCreationService service = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (service == null) { throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName })); } ITypeProvider provider = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider; if (provider == null) { throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName })); } foreach (CustomProperty property in propCollection) { bool flag = (property.oldPropertyName == null) || (property.oldPropertyType == null); if (!flag) { if (!property.IsEvent) { flag = customActivityType.GetProperty(property.oldPropertyName, provider.GetType(property.oldPropertyType)) == null; } else { flag = customActivityType.GetEvent(property.oldPropertyName) == null; } } if (flag) { AttributeInfo[] attributes = CreateCustomPropertyAttributeArray(property, serviceProvider); if (property.IsEvent) { service.CreateEvent(customActivityType.FullName, property.Name, provider.GetType(property.Type), attributes, property.GenerateDependencyProperty); } else { service.CreateProperty(customActivityType.FullName, property.Name, provider.GetType(property.Type), attributes, property.GenerateDependencyProperty, false, false, null, false); } } else { CustomProperty oldProperty = null; foreach (CustomProperty property3 in existingProps) { if ((property3.Name == property.oldPropertyName) && (property3.Type == property.oldPropertyType)) { oldProperty = property3; } } if ((oldProperty == null) || ArePropertiesDifferent(property, oldProperty)) { AttributeInfo[] infoArray2 = CreateCustomPropertyAttributeArray(property, serviceProvider); CreateCustomPropertyAttributeArray(oldProperty, serviceProvider); System.Type newEventType = provider.GetType(property.Type, false); System.Type type = provider.GetType(property.oldPropertyType, false); if (newEventType != null) { if (property.IsEvent) { service.UpdateEvent(customActivityType.FullName, property.oldPropertyName, type, property.Name, newEventType, infoArray2, property.GenerateDependencyProperty, false); } else { service.UpdateProperty(customActivityType.FullName, property.oldPropertyName, type, property.Name, newEventType, infoArray2, property.GenerateDependencyProperty, false); } } } } } }
public static CustomProperty CreateCustomProperty(IServiceProvider serviceProvider, string customPropertyName, PropertyDescriptor propertyDescriptor, object propertyOwner) { CustomProperty newCustomProperty = new CustomProperty(serviceProvider); newCustomProperty.Name = customPropertyName; if (TypeProvider.IsAssignable(typeof(ActivityBind), propertyDescriptor.PropertyType)) { Type baseType = PropertyDescriptorUtils.GetBaseType(propertyDescriptor, propertyOwner, serviceProvider); if (baseType == null) throw new InvalidOperationException(SR.GetString(SR.Error_CantDeterminePropertyBaseType, propertyDescriptor.Name)); newCustomProperty.Type = baseType.FullName; } else { newCustomProperty.Type = propertyDescriptor.PropertyType.FullName; } if (propertyDescriptor is ActivityBindPropertyDescriptor) { DependencyProperty dependencyProperty = DependencyProperty.FromName(propertyDescriptor.Name, propertyDescriptor.ComponentType); newCustomProperty.IsEvent = (dependencyProperty != null && dependencyProperty.IsEvent); } newCustomProperty.Category = propertyDescriptor.Category; return newCustomProperty; }
private static AttributeInfo[] CreateCustomPropertyAttributeArray(CustomProperty property, IServiceProvider serviceProvider) { // Don't generate these attributes for hidden properties, just let the // attributes that already exist on the property stay if (property == null || property.Hidden) return new AttributeInfo[0]; List<AttributeInfo> attributeList = new List<AttributeInfo>(); if (property.Category != null) attributeList.Add(new AttributeInfo(typeof(CategoryAttribute), new string[] { }, new object[] { new CodePrimitiveExpression(property.Category) })); if (property.Description != null) attributeList.Add(new AttributeInfo(typeof(DescriptionAttribute), new string[] { }, new object[] { new CodePrimitiveExpression(property.Description) })); if (!string.IsNullOrEmpty(property.UITypeEditor)) attributeList.Add(new AttributeInfo(typeof(EditorAttribute), new string[] { }, new object[] { new CodeTypeOfExpression(property.UITypeEditor), new CodeTypeOfExpression(typeof(UITypeEditor)) })); attributeList.Add(new AttributeInfo(typeof(BrowsableAttribute), new string[] { }, new object[] { new CodePrimitiveExpression(property.Browseable) })); attributeList.Add(new AttributeInfo(typeof(DesignerSerializationVisibilityAttribute), new string[] { }, new object[] { new CodeSnippetExpression(typeof(DesignerSerializationVisibility).Name + "." + property.DesignerSerializationVisibility.ToString()) })); return attributeList.ToArray(); }
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; }