-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RDS: add option if generated code should be for a single or multiple …
…inputs
- Loading branch information
Showing
24 changed files
with
380 additions
and
177 deletions.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
sources/RevitDBExplorer/Domain/DataModel/Accessors/IAccessorWithCodeGeneration.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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md | ||
|
||
using RevitDBExplorer.Domain.RevitDatabaseScripting; | ||
|
||
namespace RevitDBExplorer.Domain.DataModel.Accessors | ||
{ | ||
internal interface IAccessorWithCodeGeneration : IAccessor | ||
{ | ||
string GenerateInvocationForScript(); | ||
string GenerateInvocationForScript(TemplateInputsKind inputsKind); | ||
} | ||
} |
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
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
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
63 changes: 63 additions & 0 deletions
63
sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocationTemplateSelector.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,63 @@ | ||
using System; | ||
using System.Reflection; | ||
using NSourceGenerators; | ||
|
||
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md | ||
|
||
namespace RevitDBExplorer.Domain.RevitDatabaseScripting | ||
{ | ||
public enum TemplateCmdKind { Select, Update }; | ||
public enum TemplateInputsKind { Single, Multiple }; | ||
|
||
internal class MemberInvocationTemplateSelector | ||
{ | ||
public string Evaluate(MethodInfo getMethod, string invocation, TemplateInputsKind inputsKind) | ||
{ | ||
invocation ??= getMethod.GenerateInvocation(); | ||
var cmdkind = getMethod.ReturnType == typeof(void) ? TemplateCmdKind.Update : TemplateCmdKind.Select; | ||
|
||
return Evaluate(getMethod.DeclaringType, invocation, cmdkind, inputsKind); | ||
} | ||
public string Evaluate(Type type, string invocation, TemplateCmdKind cmdkind, TemplateInputsKind inputsKind) | ||
{ | ||
var template = GetTemplateType(cmdkind, inputsKind); | ||
|
||
return Evaluate(template, type, invocation); | ||
} | ||
private Type GetTemplateType(TemplateCmdKind cmdKind, TemplateInputsKind inputsKind) | ||
{ | ||
if ((inputsKind == TemplateInputsKind.Single) && (cmdKind == TemplateCmdKind.Select)) | ||
{ | ||
return typeof(MemberInvocation_SelectSingle_Template); | ||
} | ||
if ((inputsKind == TemplateInputsKind.Single) && (cmdKind == TemplateCmdKind.Update)) | ||
{ | ||
return typeof(MemberInvocation_UpdateSingle_Template); | ||
} | ||
if ((inputsKind == TemplateInputsKind.Multiple) && (cmdKind == TemplateCmdKind.Select)) | ||
{ | ||
return typeof(MemberInvocation_SelectMultiple_Template); | ||
} | ||
if ((inputsKind == TemplateInputsKind.Multiple) && (cmdKind == TemplateCmdKind.Update)) | ||
{ | ||
return typeof(MemberInvocation_UpdateMultiple_Template); | ||
} | ||
|
||
throw new NotImplementedException(); | ||
} | ||
|
||
|
||
|
||
private string Evaluate(System.Type templateType, System.Type type, string invocation) | ||
{ | ||
var template = CodeToStringRepo.GetText(templateType.Name, true); | ||
var result = template.ReplaceMany(new[] | ||
{ | ||
("TypePlaceholder", type.GetCSharpName()), | ||
("MethodPlaceholder()", invocation) | ||
}); | ||
|
||
return result; | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocationTemplates.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,57 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Autodesk.Revit.DB; | ||
using NSourceGenerators; | ||
using RevitDBExplorer.Domain.RevitDatabaseScripting.Dummies; | ||
|
||
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md | ||
|
||
namespace RevitDBExplorer.Domain.RevitDatabaseScripting | ||
{ | ||
internal class MemberInvocation_SelectMultiple_Template | ||
{ | ||
[CodeToString(nameof(MemberInvocation_SelectMultiple_Template))] | ||
IEnumerable<object> Select(Document document, IEnumerable<TypePlaceholder> inputs) | ||
{ | ||
foreach (var item in inputs) | ||
{ | ||
yield return item.MethodPlaceholder(); | ||
} | ||
} | ||
} | ||
|
||
|
||
internal class MemberInvocation_SelectSingle_Template | ||
{ | ||
[CodeToString(nameof(MemberInvocation_SelectSingle_Template))] | ||
object Select(Document document, IEnumerable<TypePlaceholder> inputs) | ||
{ | ||
var input = inputs.FirstOrDefault(); | ||
return input.MethodPlaceholder(); | ||
} | ||
} | ||
|
||
|
||
internal class MemberInvocation_UpdateMultiple_Template | ||
{ | ||
[CodeToString(nameof(MemberInvocation_UpdateMultiple_Template))] | ||
void Update(Document document, IEnumerable<TypePlaceholder> inputs) | ||
{ | ||
foreach (var item in inputs) | ||
{ | ||
item.MethodPlaceholder(); | ||
} | ||
} | ||
} | ||
|
||
|
||
internal class MemberInvocation_UpdateSingle_Template | ||
{ | ||
[CodeToString(nameof(MemberInvocation_UpdateSingle_Template))] | ||
void Update(Document document, IEnumerable<TypePlaceholder> inputs) | ||
{ | ||
var input = inputs.FirstOrDefault(); | ||
input.MethodPlaceholder(); | ||
} | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocation_SelectTemplate.cs
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocation_UpdateTemplate.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.