예제 #1
0
    public void Setup()
    {
        var code =
            @"using System;

class Class
{
	void Method1()
	{
		Console.WriteLine(""GOTO Considered Harmful"");
	}

	void Method2()
	{
	Label:
		Console.WriteLine(""GOTO Considered Harmful"");
		goto Label;
	}

	void Method3(int number)
	{
		switch (number)
		{
			case 1:
				Console.WriteLine(""goto case 2"");
				goto case 2;
			case 2:
				Console.WriteLine(""goto case 1"");
				goto case 1;
			default:
				Console.WriteLine(""break"");
				break;
		}
	}

	void Method4(int number)
	{
		switch (number)
		{
			case 0:
				Console.WriteLine(""goto default"");
				goto default;
			default:
				Console.WriteLine(""break"");
				break;
		}
	}
}";

        benchmark.Initialize(code, LanguageVersion.Latest);
    }
    public void Setup()
    {
        var code =
            @"using System;

record Record(int Number, string Text);
record class RecordClass(int Number, string Text);
record struct RecordStruct(int Number, string Text);
readonly record struct ReadonlyRecordStruct(int Number, string Text);

[Obsolete]
sealed record @record<T> : IDisposable where T : notnull
{
	public T Property { get; init; }

	public void Dispose() => throw new NotImplementedException();
}
";

        benchmark.Initialize(code, LanguageVersion.Latest);
    }
    public void Setup()
    {
        var code =
            @"using System;

record Record();

class Class
{
	void Method(Record instance)
	{
		_ = instance is null;
		_ = instance is not null;

		_ = instance == null;
		_ = null != instance;

		_ = (object)instance == null;
		_ = null != (object)instance;
	}
}";

        benchmark.Initialize(code, LanguageVersion.Latest);
    }