我使用.editorconfig文件在 .Net 5 解决方案中定义代码样式规则。是否可以在 中定义所需的类成员顺序.editorconfig?例如,公共成员应出现在私有之前,非静态成员应出现在静态之前,方法应出现在属性之前。
private struct Maybe<T>
{
private readonly T value;
private readonly bool hasValue;
private Maybe(T value)
{
this.value = value;
hasValue = true;
}
public static implicit operator Maybe<T>(T value) =>
value == null ? new Maybe<T>() : new Maybe<T>(value);
}
private static Maybe<byte> OK()
{
return 5;
}
private static Maybe<IEnumerable<byte>> NotOK()
{
var e = new[] { 1, 2, 3 }.Select(x => (byte)x);
Console.WriteLine(e.GetType().Name);
return e;
}
Run Code Online (Sandbox Code Playgroud)
小提琴(不要使用):https : //dotnetfiddle.net/NxAw9l
更新小提琴:https : //dotnetfiddle.net/NrARTl
在上面的代码中,某些泛型类型无法进行隐式转换。请参阅Ok()和NotOk() …