یک نکتهی تکمیلی: امکان استفادهی از records و init-only properties در نگارشهای پیشین دات نت
فقط اگر از NET 5x. به عنوان Target Framework استفاده کنید،
زبان تنظیم شدهی پیشفرض آن سیشارپ 9 است. اما اگر برای مثال بخواهید این زبان را در پروژههای مبتنی بر net standard 2.1 که زبان پیشفرض آنها C# 8.0 است نیز فعال کنید، اینکار با بازنویسی صریح شماره نگارش زبان آن در فایل csproj ممکن است:
<LangVersion>9.0</LangVersion>
اما پس از آن به یک مشکل برخواهید خورد: برای کار با records و init-only properties، نوع جدید IsExternalInit باید به کامپایلر معرفی شود که این نوع، جزئی از NET 5x SDK. هست. بنابراین برای سایر SDKها، نیاز است قطعه کد زیر را به صورت دستی به پروژهی خود اضافه کنید:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Reserved to be used by the compiler for tracking metadata.
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit
{
}
}