public void MembersWithIgnoreAttributeExcluded() { CustomTypeDescriptor thingType = new CustomTypeDescriptor(typeof(Thing)); PropertyDescriptorCollection properties = thingType.GetProperties(); Assert.AreEqual(4, properties.Count); Assert.IsNull(properties.Find("Field2", true)); Assert.IsNull(properties.Find("Property2", true)); }
public ComponentImporter(Type type, ICustomTypeDescriptor typeDescriptor) : base(type) { if (typeDescriptor == null) { typeDescriptor = new CustomTypeDescriptor(type); } _properties = typeDescriptor.GetProperties(); }
public void IndexerPropertyExcluded() { // // Exercises bug #11675 // http://developer.berlios.de/bugs/?func=detailbug&bug_id=11675&group_id=4638 // CustomTypeDescriptor thingType = new CustomTypeDescriptor(typeof(ThingWithIndexer)); Assert.AreEqual(0, thingType.GetProperties().Count); }
public void GetTypeDescriptor_InvokeTypeObjectWithoutParent_ReturnsExpected(Type objectType, object instance) { var provider = new SubTypeDescriptionProvider(); CustomTypeDescriptor result1 = Assert.IsAssignableFrom <CustomTypeDescriptor>(provider.GetTypeDescriptor(objectType, instance)); Assert.Empty(result1.GetProperties()); // Call again. CustomTypeDescriptor result2 = Assert.IsAssignableFrom <CustomTypeDescriptor>(provider.GetTypeDescriptor(objectType, instance)); Assert.Same(result1, result2); }
public void GetTypeDescriptor_InvokeTypeWithoutParent_CallsTypeObjectOverload_Object(object instance) { var mockProvider = new Mock <TypeDescriptionProvider>(MockBehavior.Strict); mockProvider .Setup(p => p.GetTypeDescriptor(instance.GetType(), instance)) .CallBase(); TypeDescriptionProvider provider = mockProvider.Object; CustomTypeDescriptor result1 = Assert.IsAssignableFrom <CustomTypeDescriptor>(provider.GetTypeDescriptor(instance)); Assert.Empty(result1.GetProperties()); mockProvider.Verify(p => p.GetTypeDescriptor(instance.GetType(), instance), Times.Once()); // Call again. CustomTypeDescriptor result2 = Assert.IsAssignableFrom <CustomTypeDescriptor>(provider.GetTypeDescriptor(instance)); Assert.Same(result1, result2); mockProvider.Verify(p => p.GetTypeDescriptor(instance.GetType(), instance), Times.Exactly(2)); }
public CustomTypeDescriptorTest() { // We set up this as a class property because we use it in almost every test (excepting one) CustomTypeDescription = new CustomTypeDescriptor(typeof(ICustomMappingTable)); }
public void ReadOnlyPropertyWithIncludeAttributeIsIncluded() { CustomTypeDescriptor thingType = new CustomTypeDescriptor(typeof(ThingWithSpecialReadOnlyProperty)); PropertyDescriptorCollection properties = thingType.GetProperties(); Assert.AreEqual(1, properties.Count); }
public void ImmutableClassPropertiesExpected() { CustomTypeDescriptor descriptor = new CustomTypeDescriptor(typeof(ImmutableThing)); PropertyDescriptorCollection properties = descriptor.GetProperties(); Assert.AreEqual(2, properties.Count); Assert.IsNotNull(properties["field"]); Assert.IsNotNull(properties["property"]); }
private IExporter FindCompatibleExporter(Type type) { if (typeof(IJsonExportable).IsAssignableFrom(type)) { return new ExportAwareExporter(type); } if (Reflector.IsConstructionOfNullable(type)) { return new NullableExporter(type); } if (Reflector.IsTupleFamily(type)) { return new TupleExporter(type); } if (type.IsClass && (type != typeof(object))) { IExporter exporter = this.FindBaseExporter(type.BaseType, type); if (exporter != null) { return exporter; } } if (typeof(IDictionary).IsAssignableFrom(type)) { return new DictionaryExporter(type); } if (typeof(IEnumerable).IsAssignableFrom(type)) { return new EnumerableExporter(type); } if ((type.IsPublic || type.IsNestedPublic) && ((!type.IsPrimitive && !type.IsEnum) && (type.IsValueType || (type.GetConstructor(Type.EmptyTypes) != null)))) { if (!type.IsValueType) { return new ComponentExporter(type); } CustomTypeDescriptor descriptor = new CustomTypeDescriptor(type); if (descriptor.GetProperties().Count > 0) { return new ComponentExporter(type, descriptor); } } CustomTypeDescriptor typeDescriptor = CustomTypeDescriptor.TryCreateForAnonymousClass(type); if (typeDescriptor != null) { return new ComponentExporter(type, typeDescriptor); } return new StringExporter(type); }