commandlineparser / commandlineparser/commandline

Immutable record types are not treated as immutable

未关闭
#777 2 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C#
星标
4.8k
派生
478
PR 合并指标
30 天内没有已合并 PR

描述

C# 9.0 syntax allows now to declare reference types as 'records' which is a nice syntax sugar for (immutable) data-container classes. There's a way to declare a record type as ['immutable'](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/record#immutability):
```c#
public sealed record MyRecord(
string property1,
int property2,
object propertyEtc
)
{}
```
This would actually generate a following class:
```c#
public sealed class MyRecord
{
public string property1 {get; init;}
public int property2 {get; init;}
public object propertyEtc {get; init}

public MyRecord(string property1, int property2, object propertyEtc)
{
this.property1 = property1;
this.property2 = property2;
this.propertyEtc = propertyEtc;
}
//some other code, like Equals()
}
```

The problem is that `ParseArguments()` would fail with `System.MissingMethodException: No parameterless constructor defined for type 'MyRecord '.` (which there's really none).

While I could declare a prarmeterless constructor for such record, it would be really great to have such classes supported as-is.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。