Brightspace / D2L.CodeStyle

Annotations and analysis tools for D2L C# code style
Apache License 2.0
10 stars 22 forks source link

Allow OnlyVisibleToType on interfaces. #925

Closed TimothyJCowen closed 1 year ago

omsmith commented 1 year ago

This seems likely to make this analyzer quite a bit more expensive.

What benefit are we looking for by blocking ~interacting with the type in any way~ holding a variable of a given interface?

The added tests only show declaring variables, could we use OperationKind.VariableDeclaration?

Edit: Was the goal to block all members without having to explicitly put the attribute on each one? Because this doesn't quite achieve that if so:

[OnlyVisibileToType( typeof( AllowedCaller ) )]
public interface IRestrictedInterface {
  public void NotExplicitlyRestrictedMethod();
}

public static class AllowedCaller {
  public static IRestrictedInterface Prop { get; } = ...;
}

public static class BlockedCaller {
  public static void Foo() {
    // Allowed
    AllowedCalled.Prop.NotExplicitlyRestrictedMethod();
  }
}