Exemple #1
0
        public void LocalContainer()
        {
            var container1               = new CompositionContainer();
            TypeDescriptorServices dat   = new TypeDescriptorServices();
            CompositionBatch       batch = new CompositionBatch();

            batch.AddPart(dat);
            container1.Compose(batch);
            MetadataStore.AddAttribute(
                typeof(DynamicMetadataTestClass),
                (type, attributes) =>
                Enumerable.Concat(
                    attributes,
                    new Attribute[] { new TypeConverterAttribute(typeof(DynamicMetadataTestClassConverter)) }
                    ),
                container1
                );
            DynamicMetadataTestClass val = DynamicMetadataTestClass.Get("42");

            var notYetAttached = TypeDescriptor.GetConverter(val.GetType());

            Assert.IsFalse(notYetAttached.CanConvertFrom(typeof(string)), "The default type converter for DynamicMetadataTestClass shouldn't support round tripping");

            var attached = dat.GetConverter(val.GetType());

            Assert.IsTrue(attached.CanConvertFrom(typeof(string)), "The new type converter for DynamicMetadataTestClass should 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");
        }