private void GetActualTypeConverterAndContext(ITypeDescriptorContext currentContext, out TypeConverter realTypeConverter, out ITypeDescriptorContext realContext) { realContext = currentContext; realTypeConverter = null; if ((currentContext != null) && (currentContext.PropertyDescriptor != null)) { realTypeConverter = TypeDescriptor.GetConverter(currentContext.PropertyDescriptor.PropertyType); ActivityBindPropertyDescriptor propertyDescriptor = currentContext.PropertyDescriptor as ActivityBindPropertyDescriptor; if (((propertyDescriptor != null) && (propertyDescriptor.RealPropertyDescriptor != null)) && ((propertyDescriptor.RealPropertyDescriptor.Converter != null) && (propertyDescriptor.RealPropertyDescriptor.Converter.GetType() != typeof(ActivityBindTypeConverter)))) { realTypeConverter = propertyDescriptor.RealPropertyDescriptor.Converter; realContext = new TypeDescriptorContext(currentContext, propertyDescriptor.RealPropertyDescriptor, currentContext.Instance); } } }
private void GetActualTypeConverterAndContext(ITypeDescriptorContext currentContext, out TypeConverter realTypeConverter, out ITypeDescriptorContext realContext) { //The following case covers the scenario where we have users writting custom property descriptors in which they have returned custom type converters //In such cases we should honor the type converter returned by property descriptor only if it is not a ActivityBindTypeConverter //If it is ActivityBindTypeConveter then we should lookup the converter based on Property type //Please be care ful when you change this code as it will break ParameterInfoBasedPropertyDescriptor realContext = currentContext; realTypeConverter = null; if (currentContext != null && currentContext.PropertyDescriptor != null) { realTypeConverter = TypeDescriptor.GetConverter(currentContext.PropertyDescriptor.PropertyType); ActivityBindPropertyDescriptor activityBindPropertyDescriptor = currentContext.PropertyDescriptor as ActivityBindPropertyDescriptor; if (activityBindPropertyDescriptor != null && activityBindPropertyDescriptor.RealPropertyDescriptor != null && activityBindPropertyDescriptor.RealPropertyDescriptor.Converter != null && activityBindPropertyDescriptor.RealPropertyDescriptor.Converter.GetType() != typeof(ActivityBindTypeConverter)) { realTypeConverter = activityBindPropertyDescriptor.RealPropertyDescriptor.Converter; realContext = new TypeDescriptorContext(currentContext, activityBindPropertyDescriptor.RealPropertyDescriptor, currentContext.Instance); } } }
private TypeConverter GetTypeConversionInfoForPropertySegment(WorkflowMarkupSerializationManager serializationManager, Type propertyType, out ITypeDescriptorContext context) { TypeConverter converter = null; context = null; PropertySegmentPropertyInfo propertyInfo = serializationManager.Context[typeof(PropertySegmentPropertyInfo)] as PropertySegmentPropertyInfo; if (propertyInfo.PropertySegment != null) { if (propertyInfo.PropertySegment.PropertyDescriptor != null) { context = new TypeDescriptorContext(propertyInfo.PropertySegment.ServiceProvider, propertyInfo.PropertySegment.PropertyDescriptor, propertyInfo.PropertySegment.Object); converter = propertyInfo.PropertySegment.PropertyDescriptor.Converter; } else if (propertyInfo.PropertySegment.Object != null) { PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(propertyInfo.PropertySegment.Object)[propertyInfo.Name]; if (propertyDescriptor != null) { context = new TypeDescriptorContext(propertyInfo.PropertySegment.ServiceProvider, propertyDescriptor, propertyInfo.PropertySegment.Object); converter = propertyDescriptor.Converter; } } } if (propertyType != null && converter == null) { converter = TypeDescriptor.GetConverter(propertyType); } return converter; }
internal static void MakePropertiesReadOnly(IServiceProvider serviceProvider, object topComponent) { Hashtable visitedComponents = new Hashtable(); Queue nestedComponents = new Queue(); nestedComponents.Enqueue(topComponent); while (nestedComponents.Count > 0) { object component = nestedComponents.Dequeue(); if (visitedComponents[component.GetHashCode()] == null) { visitedComponents[component.GetHashCode()] = component; //add custom readonly type descriptor to the component (to set ForceReadonly flag in the property grid) TypeDescriptor.AddProvider(new ReadonlyTypeDescriptonProvider(TypeDescriptor.GetProvider(component)), component); //now go through all the properties and add custom readonly type descriptor to all composite ones PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(component, new Attribute[] { BrowsableAttribute.Yes }); foreach (PropertyDescriptor property in properties) { if (!property.PropertyType.IsPrimitive) { object component1 = property.GetValue(component); if (component1 != null) { TypeConverter converter = TypeDescriptor.GetConverter(component1); TypeDescriptorContext context = new TypeDescriptorContext(serviceProvider, property, component); if (converter.GetPropertiesSupported(context)) { TypeDescriptor.AddProvider(new ReadonlyTypeDescriptonProvider(TypeDescriptor.GetProvider(component1)), component1); nestedComponents.Enqueue(component1); } } } } } } }