Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Reflection-[Waiting for 2 days ]

Reflection-[Waiting for 2 days ]

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpdatabase
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sendilkumar M
    wrote on last edited by
    #1

    :confused: Hi! I am developing a mulititier application. I created some value classes with custom attributes specification.And i have seperate query builder class.This query builder class will construct the query based on the valueobject.Internally the query builder using reflection reads all propertie's name and custome attributes.Upto that there is no problem.If i try to fetch the value of a property then the runtime error will occurs.For fetching the value i am using PropertyInfo.GetValue method. So please any on help me to resolve this problem.. Type type=Obj.GetType(); foreach(PropertyInfo f in type.GetProperties()) { foreach(Attribute attr in Attribute.GetCustomAttributes(f)) { if(attr.GetType()==typeof(DefaultValueAttribute)) { str+=":"+f.Name+":"+((ColumnMappingAttribute)attr).Name; str+=f.GetValue(null,null); --This line shows error } } } Please help me to solove the problem M.Sendilkumar Senior Software Engineer TVS Infotech Chennai,TamilNadu,India. 98413 27002

    R 1 Reply Last reply
    0
    • S Sendilkumar M

      :confused: Hi! I am developing a mulititier application. I created some value classes with custom attributes specification.And i have seperate query builder class.This query builder class will construct the query based on the valueobject.Internally the query builder using reflection reads all propertie's name and custome attributes.Upto that there is no problem.If i try to fetch the value of a property then the runtime error will occurs.For fetching the value i am using PropertyInfo.GetValue method. So please any on help me to resolve this problem.. Type type=Obj.GetType(); foreach(PropertyInfo f in type.GetProperties()) { foreach(Attribute attr in Attribute.GetCustomAttributes(f)) { if(attr.GetType()==typeof(DefaultValueAttribute)) { str+=":"+f.Name+":"+((ColumnMappingAttribute)attr).Name; str+=f.GetValue(null,null); --This line shows error } } } Please help me to solove the problem M.Sendilkumar Senior Software Engineer TVS Infotech Chennai,TamilNadu,India. 98413 27002

      R Offline
      R Offline
      Roman Rodov
      wrote on last edited by
      #2

      If you would have read teh documentation for PropertyInfo.GetValue you would have seen that the first parameter to it is the "The object whose property value will be returned.". If you read the Remarks section there, it says "Because static properties belong to the type, not individual objects, get static properties by passing a null reference (Nothing) as the object argument." But since you're trying to retrieve a non-static property that line should look like this: str+=f.GetValue(obj,null); So next time instead of "Waiting for 2 days" try "Reading the documentation for 5 minutes"

      S 1 Reply Last reply
      0
      • R Roman Rodov

        If you would have read teh documentation for PropertyInfo.GetValue you would have seen that the first parameter to it is the "The object whose property value will be returned.". If you read the Remarks section there, it says "Because static properties belong to the type, not individual objects, get static properties by passing a null reference (Nothing) as the object argument." But since you're trying to retrieve a non-static property that line should look like this: str+=f.GetValue(obj,null); So next time instead of "Waiting for 2 days" try "Reading the documentation for 5 minutes"

        S Offline
        S Offline
        Sendilkumar M
        wrote on last edited by
        #3

        :)HI Roman Rodov Thanks for direct me to have a correct solutions.I tried it, it is working fine. M.Sendilkumar Senior Software Engineer TVS Infotech Chennai,TamilNadu,India. 98413 27002

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups