Skip to content

Commit

Permalink
Merge branch 'hotfix-2.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonPobiega committed Sep 7, 2017
2 parents f0adf07 + 8d8c058 commit 02c5225
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"TableSuffix": "WithStatementBodyPropertySaga",
"CorrelationProperty": null,
"TransitionalCorrelationProperty": null,
"Name": "SagaDefinitionReaderTest/WithStatementBodyPropertySaga"
}
30 changes: 30 additions & 0 deletions src/ScriptBuilder.Tests/Saga/SagaDefinitionReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,34 @@ protected override void ConfigureMapping(IMessagePropertyMapper mapper)
{
}
}

[Test]
public void WithStatementBodyProperty()
{
var sagaType = module.GetTypeDefinition<WithStatementBodyPropertySaga>();
SagaDefinitionReader.TryGetSqlSagaDefinition(sagaType, out var definition);
ObjectApprover.VerifyWithJson(definition);
}

public class WithStatementBodyPropertySaga : SqlSaga<WithStatementBodyPropertySaga.SagaData>
{
public class SagaData : ContainSagaData
{
}

protected override string CorrelationPropertyName
{
//Explicitly not use expression body
get { return null; }
}

protected override void ConfigureMapping(IMessagePropertyMapper mapper)
{
}
}

public void Dispose()
{
module?.Dispose();
}
}
41 changes: 39 additions & 2 deletions src/ScriptBuilder/CecilExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using NServiceBus.Persistence.Sql;

static class CecilExtensions
Expand Down Expand Up @@ -42,10 +43,22 @@ public static bool TryGetPropertyAssignment(this PropertyDefinition property, ou
{
value = null;
var instructions = property.GetMethod.Body.Instructions;
if (instructions.Count != 2)
if (instructions.Count == 2)
{
return false;
//Ldstr-Ret
return TryGetExpressionBodyPropertyAssignment(instructions, out value);
}
if (instructions.Count == 6)
{
//Nop-Ldstr-Stloc.0-Br.S-Ldloc.0-Ret
return TryGetStatementBodyPropertyAssignment(instructions, out value);
}
return false;
}

static bool TryGetExpressionBodyPropertyAssignment(Collection<Instruction> instructions, out string value)
{
value = null;
if (instructions[1].OpCode != OpCodes.Ret)
{
return false;
Expand All @@ -63,6 +76,30 @@ public static bool TryGetPropertyAssignment(this PropertyDefinition property, ou
return false;
}

static bool TryGetStatementBodyPropertyAssignment(Collection<Instruction> instructions, out string value)
{
value = null;
if (instructions[5].OpCode != OpCodes.Ret
|| instructions[4].OpCode != OpCodes.Ldloc_0
|| instructions[3].OpCode != OpCodes.Br_S
|| instructions[2].OpCode != OpCodes.Stloc_0
|| instructions[0].OpCode != OpCodes.Nop)
{
return false;
}
var first = instructions[1];
if (first.OpCode == OpCodes.Ldstr)
{
value = (string)first.Operand;
return true;
}
if (first.OpCode == OpCodes.Ldnull)
{
return true;
}
return false;
}

public static CustomAttribute GetSingleAttribute(this TypeDefinition type, string attributeName)
{
return type.CustomAttributes.SingleOrDefault(x => x.AttributeType.FullName == attributeName);
Expand Down

0 comments on commit 02c5225

Please sign in to comment.