Skip to content

Create RockAttribute And Obsolete Attributes #323

@JasonBock

Description

@JasonBock

Describe the solution you'd like
As I shore up the 9.0.0 release, I'm thinking with the work on disallowing closed generics and supporting static abstract members a new approach with the attributes is warranted. Therefore, I'll do two things.

First, create a new attribute, RockAttribute:

[Flags]
public enum MockKind
{
  Create = 1,
  Make = 2
}

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class RockAttribute
  : Attribute
{
  public RockAttribute(Type mockType, MockKind kind = MockKind.Create)
  {
    if (mockType.IsGenericTypeDefinition)
    {
      throw new ArgumentException("Mock types cannot be closed generics.");
    }

    this.MockType = mockType;
    this.Kind = kind;
  }

  public MockKind Kind { get; }
  public Type MockType { get; }
}

Since the majority of mock types will be "create", the default for kind is MockKind.Create (I'm still debating this as I think it would "read" better in code to be explicit with the kind you want). Also, we can check to disallow closed generics here, which would address this issue. Also, the only place to define them is at the assembly level. I've discovered that there's really no need to allow them at the type or method level as well. Just have one file that houses the mock attribute declarations.

The other attributes, RockCreateAttribute and RockMakeAttribute, both the generic and non-generic versions, will be declared as obsolete, being removed in 9.0.0. Users will be directed to start using RockAttribute.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions