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. attributes

attributes

Scheduled Pinned Locked Moved C#
ai-modelsdebuggingquestion
1 Posts 1 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.
  • M Offline
    M Offline
    matt cole
    wrote on last edited by
    #1

    Hi, I've defined an attribute type which is used on classes. I've written code that loads an assembly, iterates all the types defined in the assembly and search for types that have that attribute. This all works fine and in the debugger i can see that it is finding the attribute on the class. However I can't cast it from a generic System.Attribute to my own custom attribute type. If I use the Type.GetCustomAttributes overload that takes an attribute type as an argument and pass it my custom attribute type it doesn't find any. The debugger shows the attributes that I'm finding as being my custom type when i call GetCustomAttributes with no type. Any ideas? Code snippet: attributes = type.GetCustomAttributes(false); if(attributes.Length != 0) { // check to see if it's what we are after foreach(System.Attribute attribute in attributes) { Transformer transformer = attribute as Transformer; if(transformer != null) transformers.Add(new DataTransformer(transformer.ID,transformer.DisplayName,transformer.FileExtension,assembly,type)); } } any explicit casts also fail. Transformer is my custom attribute type and the debugger shows the attribute to be of that type.

    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