Skip to content

Instantly share code, notes, and snippets.

View badcel's full-sized avatar

Marcel Tiede badcel

View GitHub Profile
@badcel
badcel / TypeResolver.txt
Created September 22, 2024 08:39
TypeResolver
F: Object, T: Known = Known Type
F: Known, T: Object = Known Type
@badcel
badcel / Program.cs
Created August 1, 2021 07:05
Conditional pattern matching
using System;
public class Program
{
static void Main()
{
var obj = new Program();
if (obj.GetType() is {Name: "Program"})
{
Console.WriteLine("Pattern found");
@badcel
badcel / Program.cs
Created October 31, 2020 12:40
Struct inside struct serialization
using System;
using System.Runtime.InteropServices;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
Console.WriteLine(Marshal.SizeOf<Test1>() + "-" + Marshal.SizeOf<Test2>() + "-" + (Marshal.SizeOf<Test2>() == Marshal.SizeOf<Test2>()));
#nullable enable
using System;
namespace test
{
public class Test : Base
{
//Why does the flow analysies does not catch this warning?
//Warning: Non-nullable property 'MyProperty' is uninitialized. Consider declaring the property as nullable.
public string MyProperty { get; set; }
@badcel
badcel / SwitchExpression.cs
Created May 27, 2020 12:58
Why does uncommenting line 20 produces a possible null to non nullable type conversion error?
using System;
namespace switchexpression
{
public interface IData
{
string? Text{get;}
}
public class Data : IData
{