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");
        }
Пример #2
0
        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.IsTrue(attached1.CanConvertFrom(typeof(string)), "The new type converter for DynamicMetadataTestClass should support round tripping");

            var attached2 = dat2.GetConverter(val.GetType());
            Assert.IsFalse(attached2.CanConvertFrom(typeof(string)), "The default type converter for DynamicMetadataTestClass shouldn't support round tripping");
        }
        public static TypeDescriptorServices GetTypeDescriptorServicesForContainer(CompositionContainer container)
        {
            if (container != null)
            {
                var result = container.GetExportedValueOrDefault <TypeDescriptorServices>();
                if (result == null)
                {
                    var v = new TypeDescriptorServices();
                    CompositionBatch batch = new CompositionBatch();
                    batch.AddPart(v);
                    container.Compose(batch);
                    return(v);
                }

                return(result);
            }
            return(null);
        }
            internal static Dictionary <Type, TypeDescriptionProvider> GetRedirect(CompositionContainer container)
            {
                TypeDescriptorServices v = GetTypeDescriptorServicesForContainer(container);

                return(v != null ? v.Providers : null);
            }
Пример #5
0
 public static TypeDescriptorServices GetTypeDescriptorServicesForContainer(CompositionContainer container)
 {
     if (container != null)
     {
         var result = container.GetExportedValueOrDefault<TypeDescriptorServices>();
         if (result == null)
         {
             var v = new TypeDescriptorServices();
             CompositionBatch batch = new CompositionBatch();
             batch.AddPart(v);
             container.Compose(batch);
             return v;
         }
         
         return result;
     }
     return null;
 }