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. conditional compilation

conditional compilation

Scheduled Pinned Locked Moved C#
question
9 Posts 5 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.
  • J Offline
    J Offline
    joost versteegen
    wrote on last edited by
    #1

    I have a shared dll (model.dll) and two executables using it. In teh model library i have a property. In the one executable i would like to set [ReadOnlyAttribute(false)] for the property and in the other executable i would like to set [ReadOnlyAttribute(true)]. Using the conditional compilation settings in the respertive project properties does not do the trick. Does anybody have a suggestion for me?

    OriginalGriffO S J 3 Replies Last reply
    0
    • J joost versteegen

      I have a shared dll (model.dll) and two executables using it. In teh model library i have a property. In the one executable i would like to set [ReadOnlyAttribute(false)] for the property and in the other executable i would like to set [ReadOnlyAttribute(true)]. Using the conditional compilation settings in the respertive project properties does not do the trick. Does anybody have a suggestion for me?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Conditional compilation is just that: a compile time operation. If you have two exes using the same DLL, then they will have the same attributes, because the compilation is only done once and the same assembly is being referenced. You can't use it to switch attribute settings at run time! If you want two different attribute settings, then you need to build two separate DLL files - which kinda defeats the point of having it as a DLL in the first place!

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      J 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Conditional compilation is just that: a compile time operation. If you have two exes using the same DLL, then they will have the same attributes, because the compilation is only done once and the same assembly is being referenced. You can't use it to switch attribute settings at run time! If you want two different attribute settings, then you need to build two separate DLL files - which kinda defeats the point of having it as a DLL in the first place!

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        J Offline
        J Offline
        joost versteegen
        wrote on last edited by
        #3

        that's clear! Thanks for the reply. Is there realy no smart alternative you can think of? (I use the propertyGrid control)

        L 1 Reply Last reply
        0
        • J joost versteegen

          I have a shared dll (model.dll) and two executables using it. In teh model library i have a property. In the one executable i would like to set [ReadOnlyAttribute(false)] for the property and in the other executable i would like to set [ReadOnlyAttribute(true)]. Using the conditional compilation settings in the respertive project properties does not do the trick. Does anybody have a suggestion for me?

          S Offline
          S Offline
          Sascha Lefevre
          wrote on last edited by
          #4

          As you stated in your last reply to OriginalGriff that you want to use this for a PropertyGrid: Take a look at this article: PropertyGrid utilities[^] - I saw a similar question on another website where one of the answerers said he solved it with the code from that article.

          If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

          1 Reply Last reply
          0
          • J joost versteegen

            that's clear! Thanks for the reply. Is there realy no smart alternative you can think of? (I use the propertyGrid control)

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            A decorator, or a TypeConverter that returns a specific set of properties depending on the EntryAssembly.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

            1 Reply Last reply
            0
            • J joost versteegen

              I have a shared dll (model.dll) and two executables using it. In teh model library i have a property. In the one executable i would like to set [ReadOnlyAttribute(false)] for the property and in the other executable i would like to set [ReadOnlyAttribute(true)]. Using the conditional compilation settings in the respertive project properties does not do the trick. Does anybody have a suggestion for me?

              J Offline
              J Offline
              John Torjo
              wrote on last edited by
              #6

              Agreed with OriginalGriff and Sascha, but the big question I would ask is: why do you want this? Best, John

              -- Log Wizard - a Log Viewer that is easy and fun to use!

              J 1 Reply Last reply
              0
              • J John Torjo

                Agreed with OriginalGriff and Sascha, but the big question I would ask is: why do you want this? Best, John

                -- Log Wizard - a Log Viewer that is easy and fun to use!

                J Offline
                J Offline
                joost versteegen
                wrote on last edited by
                #7

                the one executable is meant for configution, the other for execution. When executing the operator must not be able to change the properties, but he can observe them.

                J 1 Reply Last reply
                0
                • J joost versteegen

                  the one executable is meant for configution, the other for execution. When executing the operator must not be able to change the properties, but he can observe them.

                  J Offline
                  J Offline
                  John Torjo
                  wrote on last edited by
                  #8

                  Out of the top of my head, I think you should - create some sort of ConfigurationAPI class that resides in your dll - you can even apply some credentials at construction (just throw if credentials aren't right) - then the properties you want to configure can all be "internal set" - this way, in your ConfigurationAPI class you can configure away :) Best, John

                  -- Log Wizard - a Log Viewer that is easy and fun to use!

                  J 1 Reply Last reply
                  0
                  • J John Torjo

                    Out of the top of my head, I think you should - create some sort of ConfigurationAPI class that resides in your dll - you can even apply some credentials at construction (just throw if credentials aren't right) - then the properties you want to configure can all be "internal set" - this way, in your ConfigurationAPI class you can configure away :) Best, John

                    -- Log Wizard - a Log Viewer that is easy and fun to use!

                    J Offline
                    J Offline
                    joost versteegen
                    wrote on last edited by
                    #9

                    i found this: Enabling/disabling properties at runtime in the PropertyGrid[^] thanks for all the replies!

                    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