Browse Source

Cli: Class parsing should support File-Scoped Namespaces

pull/11323/head
Yunus Emre Kalkan 5 years ago
parent
commit
6ec11e1eb5
  1. 10
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/DerivedClassFinder.cs

10
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/DerivedClassFinder.cs

@ -54,8 +54,14 @@ public class DerivedClassFinder : ITransientDependency
protected bool IsDerived(string csFile, string baseClass) protected bool IsDerived(string csFile, string baseClass)
{ {
var root = CSharpSyntaxTree.ParseText(File.ReadAllText(csFile)).GetRoot(); var root = CSharpSyntaxTree.ParseText(File.ReadAllText(csFile)).GetRoot();
var namespaceSyntax = root.DescendantNodes().OfType<NamespaceDeclarationSyntax>().First(); var namespaceSyntax = root.DescendantNodes().OfType<NamespaceDeclarationSyntax>().FirstOrDefault();
var classDeclaration = (namespaceSyntax.DescendantNodes().OfType<ClassDeclarationSyntax>()).First(); var classDeclaration = (namespaceSyntax?.DescendantNodes().OfType<ClassDeclarationSyntax>())?.FirstOrDefault();
if (classDeclaration == null)
{
classDeclaration = root.DescendantNodes().OfType<ClassDeclarationSyntax>().First();
}
var baseTypeList = classDeclaration.BaseList?.Types.Select(t => t.ToString()).ToList(); var baseTypeList = classDeclaration.BaseList?.Types.Select(t => t.ToString()).ToList();
if (baseTypeList == null) if (baseTypeList == null)

Loading…
Cancel
Save