public static void Main()
    {
        MyConstructorBuilder myConstructorBuilder = new MyConstructorBuilder();
        Type myType1 = myConstructorBuilder.MyTypeProperty;

        if (null != myType1)
        {
            Console.WriteLine("Instantiating the new type...");
            Object[]   myObject     = { "hello" };
            object     myObject1    = Activator.CreateInstance(myType1, myObject, null);
            MethodInfo myMethodInfo = myType1.GetMethod("HelloWorld");
            if (null != myMethodInfo)
            {
                Console.WriteLine("Invoking dynamically created HelloWorld method...");
                myMethodInfo.Invoke(myObject1, null);
            }
            else
            {
                Console.WriteLine("Could not locate HelloWorld method");
            }
        }
        else
        {
            Console.WriteLine("Could not access Type.");
        }
    }
Exemplo n.º 2
0
    public static void Main()
    {
        MyConstructorBuilder myConstructorBuilder1 = new MyConstructorBuilder();
        Type myTypeProperty = myConstructorBuilder1.MyTypeProperty;

        if (null != myTypeProperty)
        {
            Object[]   myObject     = { "Hello" };
            object     myObject1    = Activator.CreateInstance(myTypeProperty, myObject, null);
            MethodInfo myMethodInfo = myTypeProperty.GetMethod("HelloWorld");

            if (null != myMethodInfo)
            {
                myMethodInfo.Invoke(myObject1, null);
            }
            else
            {
                Console.WriteLine("Could not locate HelloWorld method");
            }
        }
        else
        {
            Console.WriteLine("Could not access Type.");
        }
    }