Re: [Conditional] question

From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 01/10/05


Date: Mon, 10 Jan 2005 09:53:12 -0500

Marc,

    You aren't going to be able to do this. The reason is that the
Conditional attribute is evaluated at compile-time, not run-time. It is
strictly for pre-processor values, not environment values.

    If you want to do something based on the environment, you are going to
have to write code that will detect the environment you are in, and then
make the appropriate calls.

    Hope this helps.

-- 
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com
"Marc Jennings" <MarcJennings@community.nospam> wrote in message 
news:p745u05eq7lb92iapt3loivsacpv3gh05e@4ax.com...
> Hi there,
>
> I am trying to get some conditional functionality into some of my
> apps.  I can use the format :
>
> [Conditional("DEBUG")]
> private void doStuff()
> {
>  //do something
> }
>
> as expected, but I would like to makr it a little more useful in a
> multi-machine environment.
>
> I want to make tweaks to an application based up whether it is running
> on my development laptop, the stage server or the live server, and
> conditionals seem to be the most efficient way forward.  However, I am
> not sure how to go about defining an environment variable to trigger
> the consitional method.
>
> Here's what I *think* I want to do...
>> **snip unnecessary stuff**
>>
>> string outputMessage;
>> string productionServer;
>>
>> private string statusMessage()
>> {
>> outputMessage = "This application is running on " + Environment.HostName 
>> + ".  ";
>> productionServer = "This is the production server.  ";
>> isDevBox();
>> return outputMessage + productionServer;
>> }
>>
>> [Conditional( ***HERE IS WHERE I AM COMING UNSTUCK****)]
>> private void checkIsDevBox()
>> {
>>   //reset things like connection strings, data table names, development 
>> queries, and whatever else I need
>>   productionServer = "This is one of the development of stage servers. 
>> ";
>> }
>> **snip unnecessary stuff**
>
> It seems that I need to check if Environment.Hostname matches one of
> my two development server names, and if so, set a flag that
> [Conditional] can work with.  It's all very well to know this is what
> I need to do, but I have not the first clue about how to go about that
> bit.
>
> Can anyone help, please?
>
> Thanks
> Marc. 


Relevant Pages

  • Re: [Conditional] question
    ... I dont think that will work, you are detecting the environment at runtime, ... > on my development laptop, the stage server or the live server, and ... > conditionals seem to be the most efficient way forward. ... >> string productionServer; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A more structured approach
    ... For the purpose of a "string compare" routine that'll be ... you might care. ... some assembly language, you don't. ... But I would then pass that as a parameter to my "find environment ...
    (alt.lang.asm)
  • Re: GenEnvironmentVariable and CreateProcess failures under XP
    ... environment variable was not found in the environment block. ... If you first call GetEnvironmentVariable with a 0-length string, ... It does not affect the "system environment" that other ... CreateProcess to launch Notepad or other Win32 executables. ...
    (microsoft.public.vb.winapi)
  • Complex XML Serialization
    ... I've been reading Keith Pijanowski's article - Enrich Your XML Serialization With Schema Providers In The .NET Framework - on how to do custom serialization of objects. ... private string _administratorPassword; ... //foreach (Environment environment in this.Environments) ...
    (microsoft.public.dotnet.xml)
  • Re: A more structured approach
    ... For the purpose of a "string compare" routine that'll be ... you might care. ... But I would then pass that as a parameter to my "find environment ...
    (alt.lang.asm)