Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
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>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

</Project>
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>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SomeClass.Run();
Form1.Run(args);
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<StartupObject>SomeClass</StartupObject>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
public class SomeClass
{
// <Snippet2>
private static BooleanSwitch boolSwitch = new BooleanSwitch("mySwitch",
private static readonly BooleanSwitch s_boolSwitch = new("mySwitch",
"Switch in config file");

public static void Main()
public static void Run()
{
//...
Console.WriteLine("Boolean switch {0} configured as {1}",
boolSwitch.DisplayName, boolSwitch.Enabled.ToString());
if (boolSwitch.Enabled)
Console.WriteLine($"Boolean switch {s_boolSwitch.DisplayName} configured as {s_boolSwitch.Enabled}");
if (s_boolSwitch.Enabled)
{
//...
}
Expand Down
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>
}
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>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ static void Main()
Method2();

Console.WriteLine("Using the Debug class");
Debug.Listeners.Add(new ConsoleTraceListener());
Debug.WriteLine("DEBUG is defined");
#if DEBUG
ConsoleTraceListener listener = new();
Trace.Listeners.Add(listener);
try
{
Debug.WriteLine("DEBUG is defined");
}
finally
{
Trace.Listeners.Remove(listener);
}
#endif
}

//<snippet8>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ public static void WriteEnvironmentInfoToTrace()
string methodName = "WriteEnvironmentInfoToTrace";

Trace.Indent();
Trace.WriteLine(DateTime.Now.ToString() + " - Start of " + methodName);
Trace.WriteLine($"{DateTime.Now} - Start of {methodName}");
Trace.Indent();

// Write details on the executing environment to the trace output.
Trace.WriteLine("Operating system: " + System.Environment.OSVersion.ToString());
Trace.WriteLine("Computer name: " + System.Environment.MachineName);
Trace.WriteLine("User name: " + System.Environment.UserName);
Trace.WriteLine("CLR runtime version: " + System.Environment.Version.ToString());
Trace.WriteLine("Command line: " + System.Environment.CommandLine);
Trace.WriteLine($"Operating system: {Environment.OSVersion}");
Trace.WriteLine($"Computer name: {Environment.MachineName}");
Trace.WriteLine($"User name: {Environment.UserName}");
Trace.WriteLine($"CLR runtime version: {Environment.Version}");
Trace.WriteLine($"Command line: {Environment.CommandLine}");

// Enumerate the trace listener collection and
// display details about each configured trace listener.
Trace.WriteLine("Number of configured trace listeners = " + Trace.Listeners.Count.ToString());
Trace.WriteLine($"Number of configured trace listeners = {Trace.Listeners.Count}");

foreach (TraceListener tl in Trace.Listeners)
{
Trace.WriteLine("Trace listener name = " + tl.Name);
Trace.WriteLine(" type = " + tl.GetType().ToString());
Trace.WriteLine($"Trace listener name = {tl.Name}");
Trace.WriteLine($" type = {tl.GetType()}");
}

Trace.Unindent();
Trace.WriteLine(DateTime.Now.ToString() + " - End of " + methodName);
Trace.WriteLine($"{DateTime.Now} - End of {methodName}");
Trace.Unindent();
}

Expand All @@ -50,7 +50,7 @@ public static void Main(string[] CmdArgs)
{

// Write a trace message to all configured trace listeners.
Trace.WriteLine(DateTime.Now.ToString()+" - Start of Main");
Trace.WriteLine($"{DateTime.Now} - Start of Main");

// <Snippet2>
// Define a trace listener to direct trace output from this method
Expand All @@ -59,9 +59,9 @@ public static void Main(string[] CmdArgs)

// Check the command line arguments to determine which
// console stream should be used for trace output.
if ((CmdArgs.Length>0)&&(CmdArgs[0].ToString().ToLower().Equals("/stderr")))
// Initialize the console trace listener to write
// trace output to the standard error stream.
if (CmdArgs.Length > 0 && CmdArgs[0].ToLower().Equals("/stderr"))
// Initialize the console trace listener to write
// trace output to the standard error stream.
{
consoleTracer = new ConsoleTraceListener(true);
}
Expand All @@ -76,7 +76,7 @@ public static void Main(string[] CmdArgs)
consoleTracer.Name = "mainConsoleTracer";

// Write the initial trace message to the console trace listener.
consoleTracer.WriteLine(DateTime.Now.ToString()+" ["+consoleTracer.Name+"] - Starting output to trace listener.");
consoleTracer.WriteLine($"{DateTime.Now} [{consoleTracer.Name}] - Starting output to trace listener.");

// Add the new console trace listener to
// the collection of trace listeners.
Expand All @@ -88,7 +88,7 @@ public static void Main(string[] CmdArgs)
WriteEnvironmentInfoToTrace();

// Write the final trace message to the console trace listener.
consoleTracer.WriteLine(DateTime.Now.ToString()+" ["+consoleTracer.Name+"] - Ending output to trace listener.");
consoleTracer.WriteLine($"{DateTime.Now} [{consoleTracer.Name}] - Ending output to trace listener.");

// Flush any pending trace messages, remove the
// console trace listener from the collection,
Expand All @@ -98,7 +98,7 @@ public static void Main(string[] CmdArgs)
consoleTracer.Close();

// Write a final trace message to all trace listeners.
Trace.WriteLine(DateTime.Now.ToString()+" - End of Main");
Trace.WriteLine($"{DateTime.Now} - End of Main");

// Close all other configured trace listeners.
Trace.Close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//<Snippet1>
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Text;
using System.Threading;

namespace CorrlationManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net10.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading
Loading