CSharpConstructorDeclaration throws exception when handling default constructors of generic abstract classes
pediRAM opened this issue · 3 comments
Issue explanation
The class "CSharpConstructorDeclaration" throws exception when handling default constructors of abstract generic classes like AbstractClass<T>()
due incomplete regular expression syntax (the syntax rule for generic datatype is missing!).
Solution
I could solve this issue by adding (<T>)
to the "ConstructorPattern" as follow:
namespace NClass.CSharp
{
public class CSharpConstructorDeclaration : ICSharpConstructorDeclaration
{
// [<access>] [static] <name>([<args>])
const string ConstructorPattern =
@"^\s*" + CSharpLanguage.AccessPattern + @"(?<static>static\s+)?" +
@"(?<name>" + CSharpLanguage.NamePattern + ")" +
@"(<\w+>)?" + // <-- Add this to solve the issue with default constructors of generic abstract classes <-----<<<
@"\((?(static)|(?<args>.*))\)" + CSharpLanguage.DeclarationEnding;
static readonly Regex constructorRegex =
new Regex(ConstructorPattern, RegexOptions.ExplicitCapture);
private readonly Match match;
public CSharpConstructorDeclaration(Match match)
{
if (!match.Success)
{
// This is the line which throws the exception (because <T> is not recognized). <------<<<
throw new BadSyntaxException(Strings.ErrorInvalidDeclaration);
}
this.match = match;
}
public static CSharpConstructorDeclaration Create(string declaration)
{
var match = constructorRegex.Match(declaration);
return new CSharpConstructorDeclaration(match);
}
// ...
}
Hi,
thank you for reporting this, it is a very good find and your solution makes sense. Do you want to submit a PR or should I directly incorporate your changes?
Hi,
if you think other developers are okay with it, then lets do it directly with "low ceremony". I'm okay with it (directly, no PR).
Something else:
Are there any compiled .net libraries (*.dll) for testing?
I wrote some about 3 years ago to test other software, to test the recognition of program-elements and their relations etc.
I could create a repository and upload the code unter GPL3 if you want... but it take me little bit time to burnish it for GitHub and public use (renaming, commenting, manual).
This would really help to speed up the development.
Hi again,
since it is a one man show, I gladly implemented and committed your proposal, thank you very much once more! :)
As for your question: do you mean whether or not do I have binaries to test the AssemblyImport plugin?
If I understood your question correctly, then - no, I do not have such compiled libs, although I know that the import does not always work properly - for example, you can search for octokit.net on github and you will see, that the main assembly of the project cannot be imported.
If you want to do it, no probs, create your repo, but take your time - I do not want to put any pressure on you. I myself currently do not have a lot of time to work on the project.
Regards