コード例 #1
0
        public void ReceiveMetadataByCustomType()
        {
            ContainerConfiguration   cfg = new ContainerConfiguration().WithAssembly(Assembly.GetExecutingAssembly());
            ReflectionAndComposition r   = new ReflectionAndComposition();

            using (CompositionHost container = cfg.CreateContainer())
            {
                container.SatisfyImports(r);
            }
            ImportMetadata meta = r.CurPlayer.Metadata;

            Console.WriteLine($"{nameof(ImportMetadata.MaxTracks)}:" +
                              $"{meta.MaxTracks}\n{nameof(ImportMetadata.Skin)}:" +
                              $"{meta.Skin}");
        }
コード例 #2
0
        public void ExportMetadata()
        {
            ContainerConfiguration   cfg = new ContainerConfiguration().WithAssembly(Assembly.GetExecutingAssembly());
            ReflectionAndComposition r   = new ReflectionAndComposition();

            using (CompositionHost container = cfg.CreateContainer())
            {
                container.SatisfyImports(r);
            }
            TestOne t = r.ComposObject.Value;

            t.Run();
            IDictionary <string, object> metas = r.ComposObject.Metadata;

            foreach (var kv in metas)
            {
                Console.WriteLine($"Key:{kv.Key}, value: {kv.Value}");
            }
        }
コード例 #3
0
        public void EncapsulateMetadata()
        {
            ContainerConfiguration   cfg = new ContainerConfiguration().WithAssembly(Assembly.GetExecutingAssembly());
            ReflectionAndComposition r   = new ReflectionAndComposition();
            TestCompos cps = new TestCompos();

            using (var host = cfg.CreateContainer())
            {
                host.SatisfyImports(cps);
            }
            foreach (var c in cps.ImportedCompoents)
            {
                ITest obj = c.Value;
                IDictionary <string, object> meta = c.Metadata;
                Console.WriteLine("Meta:");
                foreach (var it in meta)
                {
                    Console.WriteLine($"  {it.Key}: {it.Value}");
                }
                Console.WriteLine($"call {obj.GetType().Name}\n");
                obj.RunTask();
                Console.WriteLine("----------------------------------\n");
            }
        }