简体   繁体   中英

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. 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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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