none
"bind the type to an existing object", what's it mean? RRS feed

  • Question

  • Hello,

    In this documentation (http://msdn.microsoft.com/en-us/library/f7ykdhsy.aspx), the third paragraph, it says -- 

    Assemblies contain modules, modules contain types, and types contain members. Reflection provides objects that encapsulate assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object.

    What's it mean? Anyone can explain it in detail or with code?

    Thanks,

    Showching

    Thursday, April 28, 2011 6:08 AM

Answers

  • Hi,

    I think what is meant here is that you can cast an object to a type:

    dim x as sometype = ctype(someobjectinstance, sometype)


    Regards, Nico
    • Proposed as answer by eryang Thursday, May 5, 2011 7:51 AM
    • Marked as answer by eryang Wednesday, May 11, 2011 6:37 AM
    Thursday, April 28, 2011 7:27 AM
  • Or, something like:

                string str = "this is a string";

     

                // Get a Type object of String;

                Type t = typeof(string);

                MethodInfo mi = t.GetMethod("ToUpperInvariant");

     

                // Bind method information to a string object.

                string result = mi.Invoke(str, null) as string;

     

                Console.WriteLine(result);


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by eryang Wednesday, May 11, 2011 6:37 AM
    Thursday, April 28, 2011 7:38 AM

All replies

  • Hi,

    I think what is meant here is that you can cast an object to a type:

    dim x as sometype = ctype(someobjectinstance, sometype)


    Regards, Nico
    • Proposed as answer by eryang Thursday, May 5, 2011 7:51 AM
    • Marked as answer by eryang Wednesday, May 11, 2011 6:37 AM
    Thursday, April 28, 2011 7:27 AM
  • Or, something like:

                string str = "this is a string";

     

                // Get a Type object of String;

                Type t = typeof(string);

                MethodInfo mi = t.GetMethod("ToUpperInvariant");

     

                // Bind method information to a string object.

                string result = mi.Invoke(str, null) as string;

     

                Console.WriteLine(result);


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by eryang Wednesday, May 11, 2011 6:37 AM
    Thursday, April 28, 2011 7:38 AM