Exemplo n.º 1
0
        public void ResolveFieldTest()
        {
            Container c = new Container();

            c.AddSingleton(() => new TypeWithField());
            c.AddSingleton(() => new GuessableType());
            TypeWithField t = c.GetInstance <TypeWithField>();

            Assert.NotNull(t.gt);
        }
        static void Main()
        {
            TypeWithField <int> .field      = "First";
            TypeWithField <string> .field   = "Second";
            TypeWithField <DateTime> .field = "Third";

            TypeWithField <int> .PrintField();

            TypeWithField <string> .PrintField();

            TypeWithField <DateTime> .PrintField();
        }
Exemplo n.º 3
0
        public static void Demo()
        {
            TypeWithField <int> .field      = "First";
            TypeWithField <string> .field   = "Second";
            TypeWithField <DateTime> .field = "Third";

            TypeWithField <int> .PrintField();

            TypeWithField <string> .PrintField();

            TypeWithField <DateTime> .PrintField();

            Outer <int> .Inner <string, DateTime> .DummyMethod();

            Outer <string> .Inner <int, int> .DummyMethod();

            Outer <object> .Inner <string, object> .DummyMethod();

            Outer <string> .Inner <string, object> .DummyMethod();

            Outer <object> .Inner <object, string> .DummyMethod();

            //the next line will not product a console statement, as the static class already executed, and static constructor for any closed type is only executed once
            Outer <string> .Inner <int, int> .DummyMethod();

            Console.WriteLine("");
            CountingEnumerable counter = new CountingEnumerable();

            foreach (int x in counter)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("");
            DemonstrateTypeOf <int>();

            Console.WriteLine("");
            RetrievingGenericType();

            Console.WriteLine("");
            Type       type       = typeof(AdvancedGenerics);
            MethodInfo definition = type.GetMethod("PrintTypeParameter");

            MethodInfo constructed = definition.MakeGenericMethod(typeof(string));

            constructed.Invoke(null, null);
        }
 static void Main()
 {
     TypeWithField <int> .field = "First";
     TypeWithField <int> .PrintField();
 }