从属性继承

Inherit from Attribute

public class BsonObjectAttribute: BsonRepresentationAttribute
{
    public BsonObjectAttribute(BsonType representation)
    {
        base(representation);
    }
}

我正在尝试从 BsonRepresentationAttribute 创建属性。但是我收到两个编译错误如下

There is no argument given that corresponds to the required formal parameter 'representation' of BsonRepresentationAttribute.BsonRepresentationAttribute(BsonType)

Use of keyword 'base' is not valid in this context

这不是特定于属性的——您只是没有使用正确的语法从一个构造函数链接到一个基本构造函数。应该是:

public BsonObjectAttribute(BsonType representation) : base(representation)
{
}