I found out about this instruction today and wanted to try it out. Sadly, ILASM doesn't seem to recognize it. That's why I decided to manually patch the generated assembly to add in the instruction. I ...
I find myself occasionally annoyed by the empty constructor of C# struct types. Unlike classes, there's no way enforce that struct fields are initialized to non-default values, since all structs have ...
In a program I'm writing, I'm faced with a recursive type that I want to go through recursively (it seems necessary). Out of curiosity, I wanted to try and write a tail recursive version of my code, ...
According to boxing on structs when calling ToString(), calling an unoverridden method on a C# struct causes it to be boxed. This is ultimately because of how the constrained callvirt IL instruction ...
I'm working with VS 17.11, and MAUI 8.
There are a lot of articles about "dependency injection", including on a platform basis.
But something like this seems possible too:
#if IOS
...
When I was conducting the following benchmark test, the benchmark information indicated that there was no additional memory allocation. However, doesn't converting a struct to an interface involve ...
I'm trying to use Mono.Cecil to weave in some instrumentation code into existing methods - basically just a log before all the sequence points. This is simple, I can iterate over all of the sequence ...
In the preceding C# code, I'm creating a dynamic method and adding a few IL instructions to it, and then invoking the dynamic method:
var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new(&...
In C# one can make a positive int negative using the minus sign - like so:
var positiveInt = 5;
var negativeInt = -positiveInt;
Is there an extra operation taking place under the hood when doing this ...
I used ILSpy on my code from curiosity, and I noticed that if (1 == 0) empty instructions were added around return x switch statements.
Here is an example of this behavior:
public static string ...
This question is a follow up on Unhandled exception: System.IO.FileNotFoundException: The file or assembly "System.Private.CoreLib" could not be found in custom generated assmbly.
I ...
I have this IL code from Expert .NET 2.0 IL Assembler by Serge Lidin:
This is in a file called CilTest.il:
//----------- Program header
.assembly extern mscorlib { auto }
.assembly OddOrEven { }
....
We have a C#/.NET application running as a Windows Service. Infrequently, it logs several entries of the following form in the Windows Event Viewer.
Log Name: Application
Source: Windows Error ...
I have been using the following method to redirect a C# method into another at runtime:
public class Injection
{
public static void install(MethodInfo methodToReplace, ...
When writing my library, I used a series of ternary expressions:
public INumber Level1()
{
INumber number = Level2();
Next();
return
txt == "-" ?
new Subtraction(number, Level1(...