简体   繁体   English

C#:编写具有不同访问器的属性的摘要,用于getter和setter

[英]C#: Writing summary for properties with different accessors for getter and setter

I'm very disciplined in writing detailed summaries of interfaces, classes, properties and methods. 我非常擅长编写接口,类,属性和方法的详细摘要。 It's while I have in focus to share my code to anyone beeing able to read without any expenses in unnecessary explanations. 在此期间,我将重点分享给任何能够阅读而无需任何不必要解释的人。 I'm following a personal code guideline to ensure consistency. 我正在遵循个人代码准则以确保一致性。

Assume following interface ... 假设以下界面...

namespace CarFacility
{
  /// <summary>Represents the interface of all cars.</summary>
  public interface CarInterface
  {
    /// <summary>Gets the car serial number.</summary>
    string CarSerialNumber
    {
      get;
    }
  }
}

Assume following class ... 假设以下课程...

namespace CarFacility
{
  /// <summary>Represents the base class of all cars.</summary>
  public abstract class CarAbstract:
    CarInterface
  {
    /// <summary>Stores the car serial number.</summary>
    private string _carSerialNumber = string.Empty;

    /// <summary>Gets / sets the car serial number.</summary>
    public virtual string CarSerialNumber
    {
      get
      {
        string carSerialNumber = this._carSerialNumber;
        return carSerialNumber;
      }
      private set
      {
        this._carSerialNumber = value;
      }
    }

    /// <summary>Creates a new car with a unique serial number.</summary>
    /// <param name="carSerialNumber">The unique car serial number of the car.</param>
    public CarAbstract( string carSerialNumber )
    {
      this.CarSerialNumber = carSerialNumber;
    }
  }
}
  1. While a car serial number normally mustn't change its setter is private. 虽然汽车序列号​​通常不得更改,但其设置程序是私有的。
  2. While the setter can be accessed in the abstract its documented as settable. 虽然可以以抽象方式访问设置器,但可以将其记录为可设置文件。
  3. Implementing against the interface shows the documentation of the getter only. 针对该接口的实现仅显示吸气剂的文档。
  4. Implementing against the abstract shows the setter too, but this one isn't accessible. 对摘要的实现也显示了二传手,但这一步不可访问。

So my question is how to write proper summaries to not confuse the developers whose are using my libraries. 所以我的问题是如何编写适当的摘要,以免混淆正在使用我的库的开发人员。 I'm interested in your best practices to have a proper solution. 我对您的最佳做法感兴趣,以寻求适当的解决方案。

EDIT 编辑

Car serial number is a translation from german to english for the unique number of the chassis. 汽车序列号​​是底盘唯一编号从德语到英语的翻译。 It may not matches the best translation. 它可能与最佳翻译不匹配。

It's just a close example. 这只是一个接近的例子。 Imagine a new BMW has been produced in the facility and gets its unique serial number. 想象一下,该工厂生产了一辆新宝马,并获得了唯一的序列号。 You derive a class BMW from CarAbstract, create it with an overwritten constructor but by passing the unique car serial number, too. 您可以从CarAbstract派生一个BMW类,并使用一个覆盖的构造函数来创建它,但是还要传递唯一的汽车序列号​​。 By calling the base constructor and passing this number you're using the implementation of the abstract. 通过调用基本构造函数并传递此数字,您就可以使用抽象的实现。

Imagine a use case where you need to access the car serial number in the derived BMW class. 想象一个用例,您需要访问派生的BMW类中的汽车序列号​​。 So the code assist shows you the comment of the property of the CarAbstract class. 因此,代码辅助功能向您显示CarAbstract类的属性的注释。 Someone may be confused to see there should be a setter, but there's not while it's private. 也许有人会迷惑地看到应该有一个二传手,但是它不是私有的。

EDIT 编辑

By having a IList<CarInterface> you could iterate through several cars and read the car serial number. 通过使用IList<CarInterface>您可以迭代几辆汽车并读取汽车序列号​​。 While typecasting to CarInterface the code assist shows you the comment of the interface with a summery of the getter only. 在对CarInterface进行类型转换时,代码辅助仅向您显示接口的注释,仅带有getter的CarInterface

I suggest to use term "immutable". 我建议使用“不可变的”一词。

Immutable usually describes property only set in constructor and not changeable so it seems fit to what you are asking. 不可变通常描述的属性仅是在构造函数中设置的,并且不能更改,因此它似乎适合您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM