Type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?T2xkQnV0U3RpbGxMZWFybmluZw==?=

    #1

    Type

    I want to use a static method of a class using only the text name of the
    class and the text name of the method.

    The Assembly Name for this Static class is "DALLibrary "
    The Namespace name for the Static Class is "GL.DAL"
    The Class name of the Static class is "GL_ACCOUNT_TBL _DAL"

    I tried to create a "Type" object with the following set of instructions...

    string myclass = "DALLibrary.GL. DAL.GL_ACCOUNT_ TBL_DAL";
    Type myType = Type.GetType(my class);

    This returns "null". What is wrong with how I am constructing my "Type"?


    Thanks in advance for your assistance!!
  • Tom Porterfield

    #2
    Re: Type

    OldButStillLear ning wrote:
    I want to use a static method of a class using only the text name of the
    class and the text name of the method.
    >
    The Assembly Name for this Static class is "DALLibrary "
    The Namespace name for the Static Class is "GL.DAL"
    The Class name of the Static class is "GL_ACCOUNT_TBL _DAL"
    >
    I tried to create a "Type" object with the following set of instructions...
    >
    string myclass = "DALLibrary.GL. DAL.GL_ACCOUNT_ TBL_DAL";
    Type myType = Type.GetType(my class);
    >
    This returns "null". What is wrong with how I am constructing my "Type"?
    As it appears that GL_ACCOUNT_TBL_ DAL is in a different assembly, you
    need to pass the assembly qualified name to your GetType call. That
    format would like similar to:

    TopNamespace.Su bNameSpace.Cont ainingClass+Nes tedClass, MyAssembly,
    Version=1.3.0.0 , Culture=neutral , PublicKeyToken= b17a5c561934e08 9
    --
    Tom Porterfield

    Comment

    • =?Utf-8?B?T2xkQnV0U3RpbGxMZWFybmluZw==?=

      #3
      Re: Type

      As my example shows, I am passing the assembly name...

      Comment

      • Tom Porterfield

        #4
        Re: Type

        OldButStillLear ning wrote:
        As my example shows, I am passing the assembly name...
        And as my reply shows in comparison, you are passing it incorrectly.
        Yours should look something like:

        GL.DAL.GL_ACCOU NT_TBL_DAL, DALLibrary, Version=<assemb ly version>,
        Culture=neutral , PublicKeyToken= <assembly public key>

        Replace <assembly versionwith the version of DALLibrary. Replace the
        neutral culture with the assembly culture if it has one. Replace
        <assembly public keywith the public key token for the assembly, or
        null if it doesn't have one. The basic format is:

        Namespace.Class , Assembly, Version, Culture, PublicKeyToken
        --
        Tom Porterfield

        Comment

        • =?Utf-8?B?T2xkQnV0U3RpbGxMZWFybmluZw==?=

          #5
          Re: Type

          Thanks Tom

          Comment

          Working...