如何禁用自动实现的 属性 的 NotImplementedException?
How to disable the NotImplementedException for the auto-implemented property?
每当我生成自动实现的属性时,我在使用 C# 自动实现 'NotImplementedException' 时遇到问题。
这是界面 class :
public interface IPerson
{
string Name {get;set;}
int Age {get; set;}
char Gender {get; set;}
string Email {get;set;}
string Address {get;set;}
}
这是派生的class。每当我尝试实现派生的 class.
接口时,它都会自动实现 'NotImplementedException' 方法
public class Student : IPerson
{
public Student()
{
}
public string Name { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int Age { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public char Gender { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string Email { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string Address { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}
有没有办法让 Student class 中的访问器方法在我从 IPerson 接口实现和生成成员时不使用 'NotImplementedException' 自动实现?
选择 prefer auto properties
将在仅具有 get
或 set
的接口中实现属性,而不是抛出 NotImplementedException
s
这是 VS 2022 中的设置
每当我生成自动实现的属性时,我在使用 C# 自动实现 'NotImplementedException' 时遇到问题。
这是界面 class :
public interface IPerson
{
string Name {get;set;}
int Age {get; set;}
char Gender {get; set;}
string Email {get;set;}
string Address {get;set;}
}
这是派生的class。每当我尝试实现派生的 class.
接口时,它都会自动实现 'NotImplementedException' 方法public class Student : IPerson
{
public Student()
{
}
public string Name { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int Age { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public char Gender { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string Email { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string Address { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}
有没有办法让 Student class 中的访问器方法在我从 IPerson 接口实现和生成成员时不使用 'NotImplementedException' 自动实现?
选择 prefer auto properties
将在仅具有 get
或 set
的接口中实现属性,而不是抛出 NotImplementedException
s
这是 VS 2022 中的设置