public void DualContainers() { var container1 = new CompositionContainer(); TypeDescriptorServices dat1 = new TypeDescriptorServices(); CompositionBatch batch = new CompositionBatch(); batch.AddPart(dat1); container1.Compose(batch); MetadataStore.AddAttribute( typeof(DynamicMetadataTestClass), (type, attributes) => Enumerable.Concat( attributes, new Attribute[] { new TypeConverterAttribute(typeof(DynamicMetadataTestClassConverter)) } ), container1 ); var container2 = new CompositionContainer(); CompositionBatch batch2 = new CompositionBatch(); TypeDescriptorServices dat2 = new TypeDescriptorServices(); batch2.AddPart(dat2); container2.Compose(batch2); DynamicMetadataTestClass val = DynamicMetadataTestClass.Get("42"); var attached1 = dat1.GetConverter(val.GetType()); Assert.True(attached1.CanConvertFrom(typeof(string)), "The new type converter for DynamicMetadataTestClass should support round tripping"); var attached2 = dat2.GetConverter(val.GetType()); Assert.False(attached2.CanConvertFrom(typeof(string)), "The default type converter for DynamicMetadataTestClass shouldn't support round tripping"); }
public void SimpleAttachment() { MetadataStore.Container = new CompositionContainer(); DynamicMetadataTestClass val = DynamicMetadataTestClass.Get("42"); var notYetAttached = TypeDescriptor.GetConverter(val); Assert.False(notYetAttached.CanConvertFrom(typeof(string)), "The default type converter for DynamicMetadataTestClass shouldn't support round tripping"); MetadataStore.AddAttribute( typeof(DynamicMetadataTestClass), (type, attributes) => Enumerable.Concat( attributes, new Attribute[] { new TypeConverterAttribute(typeof(DynamicMetadataTestClassConverter)) } ) ); var attached = TypeDescriptor.GetConverter(val); Assert.True(attached.CanConvertFrom(typeof(string)), "The new type converter for DynamicMetadataTestClass should support round tripping"); }