简体   繁体   English

C# 不强制 class 实现公共接口

[英]C# not forcing class to implement public interface

I'm creating a class that implements an interface found in aws-cdk library but my class is not being forced to implement the properties defined on the interface.我正在创建一个 class 实现在aws-cdk库中找到的接口,但我的 class 没有被迫实现在接口上定义的属性。 I'm very confused about how this is even possible but would really like to find a solution to force my class to implement the interface.我对这怎么可能感到非常困惑,但我真的很想找到一个解决方案来强制我的 class 实现接口。 Any ideas?有任何想法吗?

namespace MyProject
{
    /// <summary>
    /// MyClass
    /// </summary>
    public class MyClass : Amazon.CDK.AWS.Lambda.IFunctionOptions
    {
    }
}

在此处输入图像描述

This looks like C# 8 code, which includes nullable reference types and a new way to provide default implementations for interfaces.这看起来像 C# 8 代码,其中包括可为空的引用类型和为接口提供默认实现的新方法。

This can make interface properties/methods optional:这可以使接口属性/方法成为可选的:

  interface IInterface
  {
    public void MyMethod()
    {
      // do default thing
    }
  }

  class MyClass : IInterface
  {
  }

You can still just add your own implementations of these methods.您仍然可以添加您自己的这些方法的实现。

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

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