-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Modernize System.Diagnostics C# snippets #13028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gewarren
wants to merge
5
commits into
main
Choose a base branch
from
gewarren-modernize-system-diagnostics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a27b12
Modernize System.Diagnostics snippets
gewarren 91bf24a
Fix ConditionalAttribute debug listener sample output
Copilot 1c427c6
Fix ConditionalAttribute Debug.WriteLine listener usage
Copilot 7c3205e
respond to feedback
gewarren 62ce013
Merge branch 'main' of github.com:dotnet/dotnet-api-docs into gewarre…
gewarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
snippets/csharp/System.Diagnostics.SymbolStore/ISymbolDocumentWriter/Overview/Project.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
64 changes: 13 additions & 51 deletions
64
...em.Diagnostics.SymbolStore/ISymbolDocumentWriter/Overview/modulebuilder_definedocument.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,18 @@ | ||
| // System.Reflection.Emit.ModuleBuilder.DefineDocument | ||
|
|
||
| /* | ||
| The following example demonstrates the 'DefineDocument' method | ||
| of 'ModuleBuilder' class. | ||
| A dynamic assembly with a module in it is created in 'CodeGenerator' class. | ||
| It gets the object representing the defined document using the method | ||
| 'DefineDocument'. | ||
| */ | ||
| // <Snippet1> | ||
| using System; | ||
| using System; | ||
| using System.Diagnostics.SymbolStore; | ||
| using System.Reflection; | ||
| using System.Reflection.Emit; | ||
| using System.Resources; | ||
| using System.Diagnostics.SymbolStore; | ||
|
|
||
| namespace ILGenServer | ||
| { | ||
| public class CodeGenerator | ||
| { | ||
| ModuleBuilder myModuleBuilder ; | ||
| AssemblyBuilder myAssemblyBuilder ; | ||
|
|
||
| public CodeGenerator() | ||
| { | ||
|
|
||
| // Get the current application domain for the current thread. | ||
| AppDomain currentDomain = AppDomain.CurrentDomain; | ||
| AssemblyName myAssemblyName = new AssemblyName(); | ||
| myAssemblyName.Name = "TempAssembly"; | ||
|
|
||
| // Define a dynamic assembly in the current domain. | ||
| myAssemblyBuilder = | ||
| currentDomain.DefineDynamicAssembly | ||
| (myAssemblyName, AssemblyBuilderAccess.RunAndSave); | ||
| // Define a dynamic module in "TempAssembly" assembly. | ||
| myModuleBuilder = | ||
| myAssemblyBuilder.DefineDynamicModule("TempModule","Resource.mod",true); | ||
| // <Snippet1> | ||
| AssemblyName assemblyName = new("TempAssembly"); | ||
| PersistedAssemblyBuilder assemblyBuilder = new(assemblyName, typeof(object).Assembly); | ||
| ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("TempModule"); | ||
|
|
||
| // Define a document for source.on 'TempModule' module. | ||
| ISymbolDocumentWriter myDocument = | ||
| myModuleBuilder.DefineDocument("RTAsm.il", SymDocumentType.Text, | ||
| SymLanguageType.ILAssembly,SymLanguageVendor.Microsoft); | ||
| ISymbolDocumentWriter document = moduleBuilder.DefineDocument( | ||
| "RTAsm.il", | ||
| SymLanguageType.ILAssembly, | ||
| SymLanguageVendor.Microsoft, | ||
| SymDocumentType.Text); | ||
|
|
||
| Console.WriteLine("The object representing the defined document is:"+myDocument); | ||
| } | ||
| } | ||
| public class CallerClass | ||
| { | ||
| public static void Main() | ||
| { | ||
| CodeGenerator myGenerator = new CodeGenerator(); | ||
| } | ||
| } | ||
| } | ||
| // </Snippet1> | ||
| Console.WriteLine($"The object representing the defined document is:{document}"); | ||
| // </Snippet1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 12 additions & 15 deletions
27
snippets/csharp/System.Diagnostics/BooleanSwitch/Enabled/source.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,24 @@ | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Windows.Forms; | ||
|
|
||
| public class Form1 : Form | ||
| public class Form1 | ||
| { | ||
| protected TextBox textBox1; | ||
| // <Snippet1> | ||
| //Class level declaration. | ||
| /* Create a BooleanSwitch for data.*/ | ||
| static BooleanSwitch dataSwitch = new BooleanSwitch("Data", "DataAccess module"); | ||
| // Class-level declaration. | ||
| // Create a BooleanSwitch for data. | ||
| private static readonly BooleanSwitch s_dataSwitch = new("Data", "DataAccess module"); | ||
|
|
||
| static public void MyMethod(string location) | ||
| public static void MyMethod(string location) | ||
| { | ||
| //Insert code here to handle processing. | ||
| if (dataSwitch.Enabled) | ||
| Console.WriteLine("Error happened at " + location); | ||
| // Insert code here to handle processing. | ||
| if (s_dataSwitch.Enabled) | ||
| { | ||
| Console.WriteLine($"Error happened at {location}"); | ||
| } | ||
| } | ||
|
|
||
| public static void Main(string[] args) | ||
| { | ||
| //Run the method that writes an error message specifying the location of the error. | ||
| MyMethod("in Main"); | ||
| } | ||
| // Run the method that writes an error message specifying the location of the error. | ||
| public static void Main() => MyMethod("in Main"); | ||
|
|
||
| // </Snippet1> | ||
| } |
2 changes: 2 additions & 0 deletions
2
snippets/csharp/System.Diagnostics/BooleanSwitch/Overview/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| SomeClass.Run(); | ||
| Form1.Run(args); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 12 additions & 15 deletions
27
snippets/csharp/System.Diagnostics/BooleanSwitch/Overview/source.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,24 @@ | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Windows.Forms; | ||
|
|
||
| public class Form1 : Form | ||
| public class Form1 | ||
| { | ||
| protected TextBox textBox1; | ||
| // <Snippet1> | ||
| // Class level declaration. | ||
| /* Create a BooleanSwitch for data.*/ | ||
| static BooleanSwitch dataSwitch = new BooleanSwitch("Data", "DataAccess module"); | ||
| // Class-level declaration. | ||
| // Create a BooleanSwitch for data. | ||
| private static readonly BooleanSwitch s_dataSwitch = new("Data", "DataAccess module"); | ||
|
|
||
| static public void MyMethod(string location) | ||
| public static void MyMethod(string location) | ||
| { | ||
| //Insert code here to handle processing. | ||
| if (dataSwitch.Enabled) | ||
| Console.WriteLine("Error happened at " + location); | ||
| // Insert code here to handle processing. | ||
| if (s_dataSwitch.Enabled) | ||
| { | ||
| Console.WriteLine($"Error happened at {location}"); | ||
| } | ||
| } | ||
|
|
||
| public static void Main(string[] args) | ||
| { | ||
| //Run the method which writes an error message specifying the location of the error. | ||
| MyMethod("in Main"); | ||
| } | ||
| // Run the method, which writes an error message specifying the location of the error. | ||
| public static void Run(string[] args) => MyMethod("in Main"); | ||
|
|
||
| // </Snippet1> | ||
| } |
6 changes: 6 additions & 0 deletions
6
snippets/csharp/System.Diagnostics/ConditionalAttribute/Overview/Project.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| </PropertyGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
snippets/csharp/System.Diagnostics/ConsoleTraceListener/Overview/Project.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
snippets/csharp/System.Diagnostics/CorrelationManager/Overview/Project.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
snippets/csharp/System.Diagnostics/CorrelationManager/Overview/program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
snippets/csharp/System.Diagnostics/CounterCreationData/.ctor/Project.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.