Scrigroup - Documente si articole

     

HomeDocumenteUploadResurseAlte limbi doc
AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

The BooleanSwitch Class

c



+ Font mai mare | - Font mai mic



The BooleanSwitch Class

Using this class in the traced code, you can decide to activate/deactivate messages by simply changing a value in the application configuration file. The WriteLineIf( and WriteIf() methods will be useful to write messages depending on the Enabled property provided by the BooleanSwitch class. In order to add switches to your application you have to follow these few steps:



Add an application configuration file either manually, or by selecting Add New Item from the Project menu within Visual Studio .NET, and choosing the Text File template from the dialog box choosing the App.config filename.

Open the configuration file in order to insert the necessary XML tags to inform the application about the switch name and value. Specifying a value equal to 0 will deactivate tracing functionality, and a value of activate it:

<?xml version='1.0' encoding='utf-8' ?>

<configuration>

<system.diagnostics>

<switches>

<add name='MySwitch' value='1' />

</switches>

</system.diagnostics>

</configuration>

Create a new BooleanSwitch object in the code that has the same name as that specified in the configuration file. You could also use the Enabled property in conjunction with the Trace static methods. Let's continue our Debugging example, by declaring a global BooleanSwitch object in order to use it everywhere in the code:

BooleanSwitch bs;

static void Main(string[] args)

In the Main method we create the object, specifying the same name used in the configuration file plus a brief description. The WriteLineIf( method will write the message only if the Enabled property has been set to in the configuration file.



Politica de confidentialitate | Termeni si conditii de utilizare



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 563
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved