-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
609 additions
and
1,129 deletions.
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 was deleted.
Oops, something went wrong.
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,8 @@ | ||
using System; | ||
|
||
namespace Rop.ControllerGenerator.Annotations; | ||
|
||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
public class ControllerAttribute : Attribute | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
Rop.ControllerGenerator.Annotations/InsertControllersAttribute.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,10 @@ | ||
using System; | ||
|
||
namespace Rop.ControllerGenerator.Annotations | ||
{ | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
public class InsertControllersAttribute : Attribute | ||
{ | ||
} | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
Rop.ControllerGenerator.Annotations/Rop.ControllerGenerator.Annotations.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Rop.GeneratorHelper; | ||
using Rop.Generators.Shared; | ||
|
||
namespace Rop.Winforms7.ControllerGenerator | ||
{ | ||
public class ControllerToInclude | ||
{ | ||
public string ControllerName { get; } | ||
public string DesiredInstanceName { get; private set; } = ""; | ||
public ClassDeclarationSyntax Cds { get; } | ||
public INamedTypeSymbol NamedTypeSymbol { get; private set; } = null; | ||
public string ControllerFor { get; private set; }=""; | ||
public string ControllerNamesPace { get; private set; } | ||
public ControllerToInclude(ClassDeclarationSyntax cds) | ||
public string DesiredInstanceName { get; } | ||
public INamedTypeSymbol NamedTypeSymbol { get; } | ||
public string ControllerFor { get;} | ||
public string ControllerNamesPace { get; } | ||
|
||
private ControllerToInclude(INamedTypeSymbol namedTypeSymbol, string controllerName, string desiredInstanceName, string controllerFor, string controllerNamesPace) | ||
{ | ||
ControllerName = cds.Identifier.Text; | ||
Cds=cds; | ||
ControllerNamesPace = cds.SyntaxTree.GetNamespace(); | ||
NamedTypeSymbol = namedTypeSymbol; | ||
ControllerName = controllerName; | ||
DesiredInstanceName = desiredInstanceName; | ||
ControllerFor = controllerFor; | ||
ControllerNamesPace = controllerNamesPace; | ||
} | ||
|
||
public bool IsControllerFor(string name, Compilation contextCompilation) | ||
public static ControllerToInclude Factory(ClassDeclarationSyntax controller, Compilation contextCompilation) | ||
{ | ||
if (NamedTypeSymbol == null) | ||
{ | ||
var candidatos=contextCompilation.GetSymbolsWithName(s => s.EndsWith(ControllerName), SymbolFilter.Type); | ||
NamedTypeSymbol = candidatos.FirstOrDefault() as INamedTypeSymbol; | ||
var baseType = NamedTypeSymbol?.BaseType; | ||
if (baseType?.IsGenericType??false) | ||
{ | ||
ControllerFor = baseType.TypeArguments[0].Name; | ||
} | ||
DesiredInstanceName = ControllerName.StartsWith(ControllerFor) ? ControllerName.Substring(ControllerFor.Length) : ControllerName; | ||
} | ||
return ControllerFor == name; | ||
var controllerName = controller.Identifier.Text; | ||
var controllerNamesPace = controller.SyntaxTree.GetNamespace(); | ||
if (string.IsNullOrEmpty(controllerNamesPace)) return null; | ||
var namedtypesymbol = contextCompilation.GetSymbolsWithName(s => s.EndsWith(controllerName), SymbolFilter.Type) | ||
.OfType<INamedTypeSymbol>().FirstOrDefault(); | ||
if (namedtypesymbol == null) return null; | ||
var baseType = namedtypesymbol.BaseType; | ||
if (baseType == null) return null; | ||
if (!baseType.IsGenericType) return null; | ||
var controllerFor = baseType.TypeArguments[0].Name; | ||
var desiredInstanceName = controllerName.StartsWith(controllerFor) ? controllerName.Substring(controllerFor.Length) : controllerName; | ||
return new ControllerToInclude(namedtypesymbol, controllerName, desiredInstanceName, controllerFor, controllerNamesPace); | ||
} | ||
} | ||
} |
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
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.