-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from gman-au/2-is-primarykey-ok
#2 added builder for primary key
- Loading branch information
Showing
6 changed files
with
94 additions
and
8 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
13 changes: 13 additions & 0 deletions
13
src/6.0/Siren.Infrastructure.AssemblyLoad/Builders/IKeyBuilder.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,13 @@ | ||
using System.Collections.Generic; | ||
using Mono.Cecil.Cil; | ||
using Siren.Infrastructure.AssemblyLoad.Domain; | ||
|
||
namespace Siren.Infrastructure.AssemblyLoad.Builders | ||
{ | ||
public interface IKeyBuilder | ||
{ | ||
public bool IsApplicable(Instruction instr); | ||
|
||
public void Process(Instruction instr, IEnumerable<ExtractedProperty> properties); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/6.0/Siren.Infrastructure.AssemblyLoad/Builders/KeyBuilder.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,46 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Mono.Cecil; | ||
using Mono.Cecil.Cil; | ||
using Siren.Infrastructure.AssemblyLoad.Domain; | ||
using Siren.Infrastructure.AssemblyLoad.Extensions; | ||
|
||
namespace Siren.Infrastructure.AssemblyLoad.Builders | ||
{ | ||
public class KeyBuilder : IKeyBuilder | ||
{ | ||
private const string KeyMethodName = "HasKey"; | ||
|
||
public bool IsApplicable(Instruction instr) | ||
{ | ||
if (instr.OpCode != OpCodes.Callvirt) return false; | ||
|
||
if (instr.Operand is not MethodReference mr) return false; | ||
|
||
return mr.Name == KeyMethodName; | ||
} | ||
|
||
public void Process(Instruction instr, IEnumerable<ExtractedProperty> properties) | ||
{ | ||
var currInstr = | ||
instr | ||
.StepPrevious(2); | ||
|
||
if (currInstr.OpCode != OpCodes.Ldstr) return; | ||
|
||
var propertyName = | ||
currInstr | ||
.Operand | ||
.ToString(); | ||
|
||
var matchingProperty = | ||
properties | ||
.FirstOrDefault(o => o.PropertyName == propertyName); | ||
|
||
if (matchingProperty != null) | ||
{ | ||
matchingProperty.IsPrimaryKey = true; | ||
} | ||
} | ||
} | ||
} |
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