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
Remove empty attribute parenthesis and attribute suffix if exists #118
Conversation
I do think literals are escaped but I'll add a test case
|
The problem is nobody forces you to suffix attributes right?
|
This one is going to be hard to explain, but it works in each combination of cases: from input in new[]
{
"[FooAttribute]",
"[FooAttribute()]",
"[FooAttribute(2)]",
"[Foo]",
"[Foo()]",
"[Foo(2)]"
}
select Regex.Replace(input, @"(?<=\[.*)(Attribute)?(\(\)(?=\])|(?=\([^)]+\)\]))?", string.Empty) Output:
|
Regular expressions have always been some sort magic to me. |
It's bad. I documented it and made some changes that seemed important while writing comments: from input in new[]
{
"[FooAttribute]",
"[FooAttribute()]",
"[FooAttribute(2)]",
"[Foo]",
"[Foo()]",
"[Foo(2)]"
}
select Regex.Replace(
input,
@"
(?<=\[[^\]]*) # Require a starting square brace on the same line and any following characters except an ending square brace.
(Attribute)? # Delete this if present.
( # Then require either:
(\(\))?(?=\]) # - Empty parens (to delete) if present, immediately followed by closing square brace (not deleted),
|
(?=\(.+\)\]) # - or non-empty parens immediately followed by closing square brace (not deleted).
)",
string.Empty, // (Replacing with empty string is referred to above as deleting.)
RegexOptions.IgnorePatternWhitespace) |
It's still pretty bad. Don't feel like you have to do anything with it. :D |
e9925c1
to
c1259e5
Compare
What about this? public class Attribute1 : Attribute
{
}
public class Attribute1Attribute : Attribute
{
}
[@Attribute1Attribute]
[@Attribute1]
public class Class1
{
} |
829ded8
to
adc325f
Compare
Honestly, I have no good idea for now how to solve other than tracking all the attributes generated and then find out if a potential clash could be produced and then special name again. Which to me seems super silly for such an edge case. And making everything pluggable and configurable seems overkill as well. Do you guys see this special case as a killer for this feature or should I proceed? |
Nope, I really don't think that situation will really happen in real-world projects. If it does, it won't be hard for the users to figure out what happened since their C# source code that they'll immediately compare with will look so unusual in the first place. |
Nope, but let's leave a note about this special case near to the regex for attributes in |
Cleanup Update src/PublicApiGenerator/CodeNormalizer.cs Co-Authored-By: Joseph Musser <me@jnm2.com> Explanation
24c2a9c
to
02e96c6
Compare
fixes #105