C# 12.0 - Experimental Attribute
نویسنده: وحید نصیری
تاریخ: ۱۴۰۲/۰۹/۰۸ ۱۵:۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
using System.Diagnostics.CodeAnalysis;
namespace CS8Tests;
[Experimental(diagnosticId: "Test001")]
public class ExperimentalAttributeDemo
{
public void Print()
{
Console.WriteLine("Hello Experimental Attribute");
}
} var experimentalAttributeDemo = new ExperimentalAttributeDemo();
error Test001: 'CS8Tests.ExperimentalAttributeDemo' is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>Test001</NoWarn>
</PropertyGroup>
</Project> #pragma warning disable Test001 var demo = new ExperimentalAttributeDemo(); #pragma warning restore Test001
using System.Diagnostics.CodeAnalysis;
namespace CS8Tests;
[Experimental(diagnosticId: "Test001")]
public class ExperimentalAttributeDemo
{
[Experimental(diagnosticId: "Test002")]
public void Print()
{
Console.WriteLine("Hello Experimental Attribute");
}
} var demo = new ExperimentalAttributeDemo(); demo.Print();
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>Test001,Test002</NoWarn>
</PropertyGroup>
</Project> #pragma warning disable Test001,Test002 var demo = new ExperimentalAttributeDemo(); demo.Print(); #pragma warning restore Test001,Test002
[Experimental("SPC101", UrlFormat = "https://www.example.com/diagnostics/{0}.html")]
public static void TestMethod(string path)