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. How to use variable in property (attribute)

How to use variable in property (attribute)

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 3 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.
  • A Offline
    A Offline
    A Wegierski
    wrote on last edited by
    #1

    I want to use a variable (or constant) in following class property: [EventTrackingEnabled(true),ObjectPooling(true,1,50)] public class Aktualizacje : ServicedComponent {... instead of number 50 in many classes in many projects of one solution. Is it possible? Thx in adv Hi, AW

    H L A 3 Replies Last reply
    0
    • A A Wegierski

      I want to use a variable (or constant) in following class property: [EventTrackingEnabled(true),ObjectPooling(true,1,50)] public class Aktualizacje : ServicedComponent {... instead of number 50 in many classes in many projects of one solution. Is it possible? Thx in adv Hi, AW

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You can declare constants and use those in your attributes, but not variables. Since attributes are metadata, the values must be defined at compile-time, not at runtime.

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      • A A Wegierski

        I want to use a variable (or constant) in following class property: [EventTrackingEnabled(true),ObjectPooling(true,1,50)] public class Aktualizacje : ServicedComponent {... instead of number 50 in many classes in many projects of one solution. Is it possible? Thx in adv Hi, AW

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

        Just overload the constructor, very handy with attributes. Remember attributes are readonly because they are stored in metadata, and hence, can be changed at runtime.

        top secret AdvancedTextBox

        1 Reply Last reply
        0
        • A A Wegierski

          I want to use a variable (or constant) in following class property: [EventTrackingEnabled(true),ObjectPooling(true,1,50)] public class Aktualizacje : ServicedComponent {... instead of number 50 in many classes in many projects of one solution. Is it possible? Thx in adv Hi, AW

          A Offline
          A Offline
          A Wegierski
          wrote on last edited by
          #4

          Thx for all Hi, AW

          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