You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the analyzers that look for attributes such as: GenerateSerializerAttribute, IdAttribute make use of the SyntaxHelpers.HasAttribute method. This calls into IsAttribute() which does the following:
It uses the TryGetTypeName method to extract the name of the attribute as a string. This assumes that attributeSyntax represents a well-formed attribute.
It checks if the extracted attribute name matches the provided attributeName in a case-sensitive manner using string.Equals. If it's a direct match, the method returns true.
If there is no direct match, it checks if the attribute name starts with attributeName, ends with "Attribute", and has a total length equal to attributeName.Length + Attribute.Length. If these conditions are met, the method also returns true.
IMO we should not rely on the attribute name only, as users may define a similar attribute in their codebase which has the same name. For example the user may have their own: IdAttribute or it may come from 3rd-party packages (Id is a very common name).
We should rely on checking the attribute via its Fully Qualified Name, this removes potential ambiguities.
NOTE: Feel free to mark this a closed in case it is irrelevant to the source generator which XAttribute it is, as long as there is one with the proper (short)name.
The text was updated successfully, but these errors were encountered:
We've moved this issue to the Backlog. This means that it is not going to be worked on for the coming release. We review items in the backlog at the end of each milestone/release and depending on the team's priority we may reconsider this issue for the following milestone.
@ReubenBond Sure no problem, but I'd rather wait until: #8643 , #8662 , #8664, #8672 are merged into main so I don't disrupt it. Afterwards I can change this and will apply to all analyzers (even the once not list in the PRs above).
Currently the analyzers that look for attributes such as:
GenerateSerializerAttribute
,IdAttribute
make use of theSyntaxHelpers.HasAttribute
method. This calls intoIsAttribute()
which does the following:It uses the
TryGetTypeName
method to extract the name of the attribute as a string. This assumes thatattributeSyntax
represents a well-formed attribute.It checks if the extracted attribute name matches the provided
attributeName
in a case-sensitive manner usingstring.Equals
. If it's a direct match, the method returns true.If there is no direct match, it checks if the attribute name starts with
attributeName
, ends with "Attribute", and has a total length equal toattributeName.Length
+Attribute.Length
. If these conditions are met, the method also returns true.IMO we should not rely on the attribute name only, as users may define a similar attribute in their codebase which has the same name. For example the user may have their own:
IdAttribute
or it may come from 3rd-party packages (Id is a very common name).We should rely on checking the attribute via its Fully Qualified Name, this removes potential ambiguities.
NOTE: Feel free to mark this a closed in case it is irrelevant to the source generator which
XAttribute
it is, as long as there is one with the proper (short)name.The text was updated successfully, but these errors were encountered: