CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Importing dynamic objects

531 Views
Copy Code Show/Hide Line Numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
 
namespace DynamicObjectContracts
{
    public class Program
    {
        static void Main(string[] args)
        {
            var container = new CompositionContainer(new TypeCatalog(typeof (Foo), typeof (Bar)));
            var bar = container.GetExportedValue<Bar>();
            Console.WriteLine(bar.Foo.Message);
            Console.ReadLine();
            
        }
 
    }
 
    [Export]
    public class Bar
    {
        [Import("Foo")]
        public dynamic Foo { get; set;}
    }
 
    [Export("Foo")]
    public class Foo
    {
        public Foo()
        {
            Message = "I can haz dynamic imports";
        }
        public string Message { get; set; }
 
    }
}
by Glenn Block
  March 17, 2010 @ 9:32am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate