protected virtual void Initialize() { if (_commonEntityBaseTypeDescriptionProvider == null) { _commonEntityBaseTypeDescriptionProvider = new FieldsToPropertiesTypeDescriptionProvider(typeof(object)); } }
public void RegisterTemmplate(ISupportDefaultPropertyValues template) { if (propertiesForTemplateType.ContainsKey(template.Id)) { return; } Type templateType = template.GetType( ); TypeDescriptionProvider typeProvider = TypeDescriptor.GetProvider(templateType); HashSet <PropertyDescriptor> props = new HashSet <PropertyDescriptor>(propertyComparer); var propDescriptors = typeProvider.GetTypeDescriptor(typeof(ObjectType)).GetProperties( ).Cast <PropertyDescriptor>( ); TypeDescriptionProvider templateTypeProvider = TypeDescriptor.GetProvider(templateType); var templatePropDescriptors = templateTypeProvider.GetTypeDescriptor(templateType, template).GetProperties( ).Cast <PropertyDescriptor>( ); var propertyInfos = templatePropDescriptors.Where(p => !p.IsReadOnly); PopulateHashSet(props, propDescriptors); PopulateHashSet(props, propertyInfos); propertiesForTemplateType.Add(template.Id, props); }
ICollection IComponentDiscoveryService.GetComponentTypes(IDesignerHost designerHost, System.Type baseType) { Hashtable hashtable = new Hashtable(); ToolboxItemCollection toolboxItems = ((IToolboxService)this).GetToolboxItems(); if (toolboxItems != null) { System.Type type = typeof(IComponent); TypeDescriptionProviderService service = null; TypeDescriptionProvider provider = null; if (designerHost != null) { service = designerHost.GetService(typeof(TypeDescriptionProviderService)) as TypeDescriptionProviderService; } foreach (ToolboxItem item in toolboxItems) { System.Type c = item.GetType(designerHost); if (((c != null) && type.IsAssignableFrom(c)) && ((baseType == null) || baseType.IsAssignableFrom(c))) { if (service != null) { provider = service.GetProvider(c); if ((provider != null) && !provider.IsSupportedType(c)) { continue; } } hashtable[c] = c; } } } return(hashtable.Values); }
public FilterTypeDescriptionProvider(T target) : base(TypeDescriptor.GetProvider(target)) { _target = target; _baseProvider = TypeDescriptor.GetProvider(target); }
public void GetFullComponentName_InvokeWithCustomTypeDescriptor_ReturnsExpected(object component, string result) { var mockCustomTypeDescriptor = new Mock <ICustomTypeDescriptor>(MockBehavior.Strict); mockCustomTypeDescriptor .Setup(d => d.GetComponentName()) .Returns(result) .Verifiable(); var mockProvider = new Mock <TypeDescriptionProvider>(MockBehavior.Strict); mockProvider .Setup(p => p.GetTypeDescriptor(component.GetType(), component)) .Returns(mockCustomTypeDescriptor.Object) .Verifiable(); mockProvider .Setup(p => p.GetFullComponentName(component)) .CallBase(); TypeDescriptionProvider provider = mockProvider.Object; Assert.Same(result, provider.GetFullComponentName(component)); mockProvider.Verify(p => p.GetTypeDescriptor(component.GetType(), component), Times.Once()); mockCustomTypeDescriptor.Verify(d => d.GetComponentName(), Times.Once()); // Call again. Assert.Same(result, provider.GetFullComponentName(component)); mockProvider.Verify(p => p.GetTypeDescriptor(component.GetType(), component), Times.Exactly(2)); mockCustomTypeDescriptor.Verify(d => d.GetComponentName(), Times.Exactly(2)); }
public DescriptorBase(ShapeProvider provider, ICustomTypeDescriptor parentdescriptor, Type objectType) : base(parentdescriptor) { this.provider = provider; this.type = objectType; mProperties = new PropertyDescriptorCollection(null); }
public static void Add(Type type) { //Avoid some base types!!!!!! if (type.FullName == "System.Object" || type.FullName == "System.String" || type.FullName == "System.DateTime" || type.IsPrimitive || type.IsValueType || !type.IsClass ) { return; } int hc = type.GetHashCode(); bool doRegister = false; lock (_registeredTypes) { if (!_registeredTypes.ContainsKey(hc)) { _registeredTypes.Add(hc, type); doRegister = true; } } if (doRegister) { TypeDescriptionProvider parent = TypeDescriptor.GetProvider(type); TypeDescriptor.AddProvider(new HyperTypeDescriptionProvider(parent), type); } }
public DescriptorBase(TypeDescriptionProvider provider, Type objectType) : base() { this.provider = provider; this.type = objectType; mProperties = new PropertyDescriptorCollection(null); }
public void AddProviderToTypeAndInstance() { var instance = new Base(); // Before adding TDPs var props = TypeDescriptor.GetProperties(instance).Cast <PropertyDescriptor>(). Select(p => p.Name).ToArray(); CollectionAssert.AreEquivalent(new[] { "A", "B" }, props); TypeDescriptionProvider typeProvider = null; TypeDescriptionProvider instanceProvider = null; try { typeProvider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Base)); TypeDescriptor.AddProvider(typeProvider, typeof(Base)); instanceProvider = new TestTypeDescriptionProvider(instance); TypeDescriptor.AddProvider(instanceProvider, instance); // After adding TDPs props = TypeDescriptor.GetProperties(instance).Cast <PropertyDescriptor>(). Select(p => p.Name).ToArray(); CollectionAssert.AreEquivalent(new[] { "A", "B", "CustomProperty1", "CustomProperty2" }, props); } finally { // Ensure we remove the providers we attached. TypeDescriptor.RemoveProvider(typeProvider, typeof(Base)); TypeDescriptor.RemoveProvider(instanceProvider, instance); } }
public void AddProviderToBaseType_GetPropertiesOfDerivedType() { // Before adding TDP var props = TypeDescriptor.GetProperties(typeof(Base)).Cast <PropertyDescriptor>(). Select(p => p.Name).ToArray(); CollectionAssert.AreEquivalent(new[] { "A", "B" }, props); props = TypeDescriptor.GetProperties(typeof(Derived)).Cast <PropertyDescriptor>(). Select(p => p.Name).ToArray(); CollectionAssert.AreEquivalent(new[] { "A", "B", "C" }, props); TypeDescriptionProvider provider = null; try { provider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Base)); TypeDescriptor.AddProvider(provider, typeof(Base)); // After adding TDP props = TypeDescriptor.GetProperties(typeof(Base)).Cast <PropertyDescriptor>(). Select(p => p.Name).ToArray(); CollectionAssert.AreEquivalent(new[] { "A", "B" }, props); props = TypeDescriptor.GetProperties(typeof(Derived)).Cast <PropertyDescriptor>(). Select(p => p.Name).ToArray(); CollectionAssert.AreEquivalent(new[] { "A", "B", "C" }, props); } finally { // Ensure we remove the provider we attached. TypeDescriptor.RemoveProvider(provider, typeof(Base)); } }
public void MetadataInheritance() { TypeDescriptionProvider baseProvider = null; TypeDescriptionProvider derivedProvider = null; TypeDescriptionProvider derivedNoMetadataProvider = null; try { baseProvider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Base)); TypeDescriptor.AddProvider(baseProvider, typeof(Base)); derivedProvider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Derived)); TypeDescriptor.AddProvider(derivedProvider, typeof(Derived)); derivedNoMetadataProvider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(DerivedNoMetadata)); TypeDescriptor.AddProvider(derivedNoMetadataProvider, typeof(DerivedNoMetadata)); var attrs = TypeDescriptor.GetProperties(typeof(Base))["A"].Attributes.Cast <Attribute>(). Select(a => a.GetType().Name).ToArray(); CollectionAssert.IsSubsetOf(new[] { "DescriptionAttribute" }, attrs); attrs = TypeDescriptor.GetProperties(typeof(Derived))["A"].Attributes.Cast <Attribute>(). Select(a => a.GetType().Name).ToArray(); CollectionAssert.IsSubsetOf(new[] { "DescriptionAttribute", "CategoryAttribute" }, attrs); attrs = TypeDescriptor.GetProperties(typeof(DerivedNoMetadata))["A"].Attributes.Cast <Attribute>(). Select(a => a.GetType().Name).ToArray(); CollectionAssert.IsSubsetOf(new[] { "DescriptionAttribute" }, attrs); } finally { // Ensure we remove the providers we attached. TypeDescriptor.RemoveProvider(baseProvider, typeof(Base)); TypeDescriptor.RemoveProvider(derivedProvider, typeof(Derived)); TypeDescriptor.RemoveProvider(derivedNoMetadataProvider, typeof(DerivedNoMetadata)); } }
private void InitializeCBMTDPBridge(TypeDescriptionProvider typeDescriptionProvider) { if (typeDescriptionProvider != null) { this._cbmTdpBridge = new ClientBuildManagerTypeDescriptionProviderBridge(typeDescriptionProvider); } }
/// <summary> /// Initializes a new instance of <see cref="DummyValueInsteadOfNullTypeDescriptionProvider"/>. /// </summary> public DummyValueInsteadOfNullTypeDescriptionProvider(TypeDescriptionProvider existingProvider, string propertyName, object dummyValue) : base(existingProvider) { this._propertyName = propertyName; this._dummyValue = dummyValue; }
static Foo() { // initializes the custom provider (the attribute-based approach doesn't allow // access to the original provider) TypeDescriptionProvider basic = TypeDescriptor.GetProvider(typeof(Foo)); FooTypeDescriptionProvider custom = new FooTypeDescriptionProvider(basic); TypeDescriptor.AddProvider(custom, typeof(Foo)); }
public InterfacePropertiesTypeDescriptionProvider(Type t) { if (!t.IsInterface) { throw new ArgumentException("This provider is meant to be used on interface types only"); } baseProvider = TypeDescriptor.GetProvider(t); }
public FilterTypeDescriptionProvider(T target) : base(TypeDescriptor.GetProvider(target)) { _target = target; // pick up the default provider _baseProvider = TypeDescriptor.GetProvider(target); }
/// <summary> /// Initializes a new instance of the <see cref="XmlDrivenCustomTypeDescriptor"/> class. /// </summary> /// <param name="parent">The parent provider.</param> /// <param name="propertyDescriptors">The property descriptors for this type.</param> internal XmlDrivenCustomTypeDescriptionProvider(TypeDescriptionProvider parent, IEnumerable <PropertyDescriptor> propertyDescriptors) : base(parent) { if (propertyDescriptors != null) { this.propertyDescriptors.AddRange(propertyDescriptors); } }
public MyTypeDescriptionProvider(TypeDescriptionProvider parent) : base(parent) { }
public void Dispose() { if (descriptionProvider != null) { TypeDescriptor.RemoveProvider(descriptionProvider, targetType); descriptionProvider = null; } }
/// <summary> /// Extends CreateInstance so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// typedescriptionprovider.CreateInstance<int>(provider, argTypes, args); /// </example> /// </summary> public static T CreateInstance <T>(this TypeDescriptionProvider typedescriptionprovider, IServiceProvider provider, Type[] argTypes, Object[] args) { if (typedescriptionprovider == null) { throw new ArgumentNullException("typedescriptionprovider"); } return((T)typedescriptionprovider.CreateInstance(provider, typeof(T), argTypes, args)); }
static PropertyBag() { props = new PropertyDescriptorCollection(new PropertyDescriptor[0], true); // init the provider; I'm avoiding TypeDescriptionProviderAttribute so that we // can exploit the default implementation for fun and profit TypeDescriptionProvider defaultProvider = TypeDescriptor.GetProvider(typeof(PropertyBag)), customProvider = new PropertyBagTypeDescriptionProvider(defaultProvider); TypeDescriptor.AddProvider(customProvider, typeof(PropertyBag)); }
public TypeConverterManager(Type targetType, string converterTypeName, UnityTypeResolver typeResolver) { this.targetType = targetType; if (!string.IsNullOrEmpty(converterTypeName)) { Type converterType = typeResolver.ResolveType(converterTypeName); descriptionProvider = TypeDescriptor.AddAttributes(targetType, new Attribute[] { new TypeConverterAttribute(converterType) }); } }
public RuntimeAttributeTypeDescriptorProvider(TypeDescriptionProvider pd, Dictionary <string, List <Attribute> > propAttrsMap) : base(pd) { if (propAttrsMap == null) { throw new ArgumentNullException("propAttrsMap"); } this.PropAttrsMap = propAttrsMap; }
internal static bool IsSupportedType(Type type) { TypeDescriptionProvider targetFrameworkProvider = GetTargetFrameworkProvider(type); if (targetFrameworkProvider == null) { targetFrameworkProvider = TypeDescriptor.GetProvider(type); } return(targetFrameworkProvider.IsSupportedType(type)); }
/// <summary> /// Creates a new instance of the <see cref="FontProviderTypeDescriptorProvider"/> class. /// </summary> /// <param name="owner">The object for which this provider is to provide a type descriptor.</param> /// <param name="parent">The existing type descriptor provider for the given component.</param> public FontProviderTypeDescriptorProvider(object owner, TypeDescriptionProvider parent) : base(parent) { if (owner == null) { throw new ArgumentNullException("owner"); } Owner = owner; }
/// <summary> /// Returns a new <see cref="DynamicTypeDescriptor"/> instance that will supply /// dynamic custom type information for the specified object. /// </summary> /// <typeparam name="T"> /// The type of the object for which dynamic custom type information will be supplied. /// </typeparam> /// <param name="instance"> /// The object for which dynamic custom type information will be supplied. /// </param> /// <returns> /// A new <see cref="DynamicTypeDescriptor"/> instance that will supply dynamic /// custom type information for the specified object. /// </returns> public static DynamicTypeDescriptor CreateFromInstance <T>(T instance) { if (instance == null) { throw new ArgumentNullException("instance", "instance should not be null."); } TypeDescriptionProvider provider = TypeDescriptor.GetProvider(instance); ICustomTypeDescriptor descriptor = provider.GetTypeDescriptor(instance); return(new DynamicTypeDescriptor(descriptor)); }
// The JITer enforces CAS. By creating a separate method we can avoid getting SecurityExceptions // when we weren't going to really call TypeDescriptor.AddProvider. internal static void RegisterCustomTypeDescriptor(TypeDescriptionProvider tdp, Type type) { // Check if we already registered provider with the specified type. var existingProviders = TypeDescriptionProviderMap.GetOrAdd(type, t => new HashSet <Type>()); if (existingProviders.Contains(tdp.GetType())) { return; } TypeDescriptor.AddProviderTransparent(tdp, type); existingProviders.Add(tdp.GetType()); }
protected override void Initialize() { // TypeDescriptor.AddProvider(_commonEntityBaseTypeDescriptionProvider, typeof (object)); if (_entityFieldsTypeDescriptionProvider == null) { _entityFieldsTypeDescriptionProvider = new FieldsToPropertiesTypeDescriptionProvider(typeof(EntityFields)); } TypeDescriptor.AddProvider(_entityFieldsTypeDescriptionProvider, typeof(EntityFields)); propertyGrid1.PropertyTabs.RemoveTabType(typeof(RawMemberTab)); propertyGrid1.PropertyTabs.AddTabType(typeof(RawLLBLMemberTab), PropertyTabScope.Static); }
private static MethodInfo ChooseMethodByType(TypeDescriptionProvider provider, List <MethodInfo> methods, ICollection values) { MethodInfo info = null; Type c = null; foreach (object obj2 in values) { Type reflectionType = provider.GetReflectionType(obj2); MethodInfo info2 = null; Type type3 = null; if ((info == null) || ((c != null) && !c.IsAssignableFrom(reflectionType))) { foreach (MethodInfo info3 in methods) { ParameterInfo info4 = info3.GetParameters()[0]; if (info4 != null) { Type type4 = info4.ParameterType.IsArray ? info4.ParameterType.GetElementType() : info4.ParameterType; if ((type4 != null) && type4.IsAssignableFrom(reflectionType)) { if (info != null) { if (!type4.IsAssignableFrom(c)) { continue; } info = info3; c = type4; break; } if (info2 == null) { info2 = info3; type3 = type4; } else { bool flag = type3.IsAssignableFrom(type4); info2 = flag ? info3 : info2; type3 = flag ? type4 : type3; } } } } } if (info == null) { info = info2; c = type3; } } return(info); }
private PropertyDescriptor GetPropertyDescriptorFromITypedList(ITypedList iTypedList) { if (string.IsNullOrEmpty(this.RelationName) == true) { return(null); } Type objectType = null; ICustomTypeDescriptor customTypeDescriptor = null; PropertyDescriptorCollection properties = null; PropertyDescriptor relationDescriptor = null; TypeDescriptionProvider typeDescriptionProvider = null; if (iTypedList != null) { properties = iTypedList.GetItemProperties(null); if ((properties != null) && (properties.Count > 0)) { relationDescriptor = properties[this.RelationName]; } else { string listName = iTypedList.GetListName(null); if (string.IsNullOrEmpty(listName) == false) { objectType = Type.GetType(listName, false, false); if (objectType != null) { typeDescriptionProvider = TypeDescriptor.GetProvider(objectType); if (typeDescriptionProvider != null) { customTypeDescriptor = typeDescriptionProvider.GetTypeDescriptor(objectType); if (customTypeDescriptor != null) { properties = customTypeDescriptor.GetProperties(); if ((properties != null) && (properties.Count > 0)) { relationDescriptor = properties[this.RelationName]; } } } } } } } return(relationDescriptor); }
public static void RemoveProvider(TypeDescriptionProvider provider, Type type) { }
public FieldsToPropertiesTypeDescriptionProvider(Type t) { _baseProvider = TypeDescriptor.GetProvider(t); }
public TestTypeDescriptionProvider(object instance) { _baseProvider = TypeDescriptor.GetProvider(instance); }
public TestTypeDescriptionProvider(Type type) { _baseProvider = TypeDescriptor.GetProvider(type); }
public static void AddProvider(TypeDescriptionProvider provider, Type type) { }
public static void AddProvider(TypeDescriptionProvider provider, object instance) { }
internal ClientBuildManagerTypeDescriptionProviderBridge(TypeDescriptionProvider typeDescriptionProvider) { _targetFrameworkProvider = typeDescriptionProvider; }