refelection (property)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • csharpula csharp

    refelection (property)


    Hello ,
    I want to get a property object using reflection by passing the string
    name of this property.
    I tried :

    Type objType = asm.GetType(var iableName);
    object var= Activator.Creat eInstance(objTy pe);

    But it's not working.Maybe because i am passing only variable name
    (String) and not the whole path to it. How do I implement this and where
    can I fetch this path if I need it?

    Thank u!


    *** Sent via Developersdex http://www.developersdex.com ***
  • Marc Gravell

    #2
    Re: refelection (property)

    Can you define what you mean by a "property object"? Your code is
    locating a type by name (from the assembly held in "asm"), and then
    creating an instance of that type.

    When looking inside an assembly, you still need to pass the FullName
    (i.e. namespace + name: "System.String" ); or you can use
    AssemblyQualifi edName without having to get the assembly first.

    Marc

    Comment

    • Gaurav Vaish \(a.k.a. MasterGaurav\)

      #3
      Re: refelection (property)

      I want to get a property object using reflection by passing the string
      name of this property.
      I tried :
      >
      Type objType = asm.GetType(var iableName);
      object var= Activator.Creat eInstance(objTy pe);
      >
      But it's not working.Maybe because i am passing only variable name
      (String) and not the whole path to it. How do I implement this and where
      Can you elaborate on "only variable name" and "not the whole path"?
      What is the whole path that you're referring to?

      Try:

      Assembly asm = Assembly.Load(" NameOfAssembly" );
      Type t = asm.GetType("Fu lly.Qualified.N ame.Of.Class");

      object instance = Activator.Creat eInstance(t);
      // -- OR --

      object instance = t.GetConstructo r(Type.EmptyTyp es).Invoke(null );


      --
      Happy Hacking,
      Gaurav Vaish | http://dwt.sourceforge.net
      http://blogs.mastergaurav.com | http://eduzine.edujini-labs.com
      --------------------------------



      Comment

      Working...