-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added PoC tests for adding OnlyVisibleToType to interfaces. #928
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/D2L.CodeStyle.Annotations/Contract/ReleaseVisibilityConstraintsAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
|
||
namespace D2L.CodeStyle.Annotations.Contract { | ||
|
||
[AttributeUsage( | ||
validOn: AttributeTargets.Class | AttributeTargets.Interface, | ||
AllowMultiple = true, | ||
Inherited = false | ||
)] | ||
public sealed class ReleaseVisibilityConstraintsAttribute : Attribute { | ||
|
||
/// <summary> | ||
/// Removes any restrictions to the visibility of the object | ||
/// which were imposed on the specified base type. | ||
/// </summary> | ||
/// <param name="type">The non-generic type or the generic type definition (e.g. System.Span<>) of the base which holds constraints to visibility.</param> | ||
public ReleaseVisibilityConstraintsAttribute( Type type ) | ||
: this( type.FullName, type.Assembly.GetName().Name ) { | ||
} | ||
|
||
/// <summary> | ||
/// Removes any restrictions to the visibility of the object | ||
/// which were imposed on the specified base type. | ||
/// </summary> | ||
/// <param name="fullyQualifiedTypeName">The non-generic type or the generic type definition (e.g. System.Span`1) of the base which holds constraints to visibility.</param> | ||
/// <param name="assemblyName">The name of the assembly containing the base type.</param> | ||
public ReleaseVisibilityConstraintsAttribute( string fullyQualifiedTypeName, string assemblyName ) { | ||
FullyQualifiedTypeName = fullyQualifiedTypeName; | ||
AssemblyName = assemblyName; | ||
} | ||
|
||
public string FullyQualifiedTypeName { get; } | ||
public string AssemblyName { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel think this feature becomes a pretty big footgun? If I'm restricting a type, I'm not too worried about what properties/methods I'm adding to it, but then something else might be re-exposing those down the road.
Do we have an example of when we'd use this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up pivoting from having a secondary attribute for precisely this reason - I've created a whole new PoC which leaves it up to the original definition to decide which restrictions are inherited by derived types (all, by default) and which only apply to the class/interface that the restriction was explicitly added to.
As far as an example, yes. This would be used to create a "bridge" between the
OrgUnitFileType
andUserFileType
in the form of an interface (IFileType
) which can only be used by explicitly specified consumers. Essentially it is a way for Storageable code to handle files at the very base level without caring about the different entity types (and having to implement code for each type separately). We still want consumers up the chain to be able to use the separate...FileType
classes however, including referencing properties on them that originate from the interface itself, so we don't want the restrictions to be inherited by them.