Skip to content

Instantly share code, notes, and snippets.

View EifelMono's full-sized avatar

Andreas Klapperich EifelMono

View GitHub Profile
@EifelMono
EifelMono / EnumFlag.cs
Created September 8, 2023 14:14
Disable format in code
[Flags]
#pragma warning disable format, RCS1154, RCS1037
public enum EnumFlag
{
Flag1 = 0b0000_0000_0000_0001,
Flag2 = 0b0000_0000_0000_0010
}
#pragma warning restore format, RCS1154, RCS1037
@EifelMono
EifelMono / program.cs
Created August 16, 2023 12:31
CreateLinkedTokenSource
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
public class Program
{
public static void Main()
{
var cs1= new CancellationTokenSource ();
@EifelMono
EifelMono / build.cmd
Created September 7, 2022 06:39
SingleExeSelfContained to artifacts
if exist artifacts rmdir artifacts /s /q
dotnet publish -c Release -r win-x64 --output ./artifacts --self-contained true -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -p:IncludeAllContentForSelfExtract=true -p:CopyOutputSymbolsToPublishDirectory=false -p:EnableCompressionInSingleFile=true -p:DebugSymbols=false -p:DebugType=None
if exist artifacts.7z del artifacts.7z
7z a artifacts artifacts
Console.WriteLine("Anonymous pattern matching");
var text = "Hello";
var person = new PersonRecord("Andreas", "Klapperich", 11);
var output = new { Text = text, Person = person } switch
{
{ Text: { }, Person: null } content => $"{content.Text} Unknown",
@EifelMono
EifelMono / Program.cs
Last active August 5, 2021 21:11
dotnet Core, 5,0, 6.0 Date parsing with 2 year digits ......... 00-29 => 2000-2229 but 30-99=>1930-1999
using System;
using System.Globalization;
class Program
{
static void Main(string[] args)
{
for (var year = 20; year < 40; year++)
if (DateTime.TryParseExact($"{year:00}0101", "yyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var date))
Console.WriteLine($"[{year:00} = {date.Year:0000}] {year:00}0101 = {date:yyyy.MM.dd}");
@EifelMono
EifelMono / Program.cs
Last active May 28, 2021 04:06
Newtonsoft sample
using System;
using Newtonsoft.Json;
using static System.Console;
public class Program
{
public class TestClass
{
public DateTime TimeStamp{get;set;}= DateTime.MinValue;
public DayOfWeek DayOfWeek {get;set;}= DayOfWeek.Monday;
@EifelMono
EifelMono / Program.cs
Created May 21, 2021 06:01
Modulo für Heinz
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
foreach(var calibrationPackageCount in Enumerable.Range(0, 10))
{
@EifelMono
EifelMono / Program.cs
Last active May 6, 2021 05:45
Für Heinz
using System;
public class Program
{
public static void Main()
{
// für Heinz
// hiermit wird nur ein Object erstellt und der Wert ist empty
var a = new Guid();
Console.Write($"a = {a}");
@EifelMono
EifelMono / Program.cs
Last active October 27, 2020 07:22
Test SonarQube "Change this condition so that it does not always evaluate to 'true'; some subsequent code is never executed."
using System;
namespace TestSonarQube
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Test(true));
Console.WriteLine(Test(false));
Console.WriteLine(Test("Hello World"));
using System;
namespace NiceExceptionName
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
M(null);