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. C#
  4. Reading custom attributes in ReflectionOnly mode

Reading custom attributes in ReflectionOnly mode

Scheduled Pinned Locked Moved C#
question
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.
  • D Offline
    D Offline
    Daniel Grunwald
    wrote on last edited by
    #1

    Does anyone know a way to get the type names of custom attributes applied to a class when the assembly is loaded in ReflectionOnly mode? The only method to get custom attributes that I know is Type.GetCustomAttributes; but since that returns attribute instances and not just the type name, it can't be used in ReflectionOnly mode. I just want to make sure I'm not overlooking something before sending a suggestion to Microsoft.

    L 1 Reply Last reply
    0
    • D Daniel Grunwald

      Does anyone know a way to get the type names of custom attributes applied to a class when the assembly is loaded in ReflectionOnly mode? The only method to get custom attributes that I know is Type.GetCustomAttributes; but since that returns attribute instances and not just the type name, it can't be used in ReflectionOnly mode. I just want to make sure I'm not overlooking something before sending a suggestion to Microsoft.

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Daniel Grunwald wrote: but since that returns attribute instances and not just the type name, it can't be used in ReflectionOnly mode. It returns instances of the attributes. You can think attributes being instantiated at compile time. You can always call object.GetType() on those returned instances. And what is ReflectionOnly mode? :confused: xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

      D 1 Reply Last reply
      0
      • L leppie

        Daniel Grunwald wrote: but since that returns attribute instances and not just the type name, it can't be used in ReflectionOnly mode. It returns instances of the attributes. You can think attributes being instantiated at compile time. You can always call object.GetType() on those returned instances. And what is ReflectionOnly mode? :confused: xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

        D Offline
        D Offline
        Daniel Grunwald
        wrote on last edited by
        #3

        ReflectionOnly mode means the type is loaded in "inspection context". That is a .NET 2.0 feature to load assembly if you just want to reflect on them without creating types. It's faster, doesn't lock the assembly file etc... But you can't get instances from ReflectionOnly assemblies, so GetCustomAttributes() always results in an exception. But I just found the solution myself: CustomAttributeData.GetCustomAttributes(type)[^] gets information about the attributes in a ReflectionOnly compatible way.

        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