Skip to content

Instantly share code, notes, and snippets.

@kolosovpetro
Created March 20, 2021 11:25
Show Gist options
  • Save kolosovpetro/0e199ec8edcaf618b020b5119792c495 to your computer and use it in GitHub Desktop.
Save kolosovpetro/0e199ec8edcaf618b020b5119792c495 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
public class C {
public void Main()
{
var str = new DisposableStruct();
using(str) {
Console.WriteLine(str.isDisposed);
}
}
}
struct DisposableStruct : IDisposable {
public bool isDisposed;
public void Dispose() { isDisposed = true; }
}
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
public class C
{
public void Main()
{
DisposableStruct disposableStruct = default(DisposableStruct);
DisposableStruct disposableStruct2 = disposableStruct;
try
{
Console.WriteLine(disposableStruct.isDisposed);
}
finally
{
((IDisposable)disposableStruct2).Dispose();
}
}
}
internal struct DisposableStruct : IDisposable
{
public bool isDisposed;
public void Dispose()
{
isDisposed = true;
}
}
{
"version": 1,
"target": "C#",
"mode": "Debug"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment