Skip to content

Commit

Permalink
Merge pull request #1147 from Particular/commandline-net7
Browse files Browse the repository at this point in the history
Make CLI work on .NET 7
  • Loading branch information
kbaley authored Feb 17, 2023
2 parents 28c1486 + 7ef46e1 commit b720d9c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<ToolCommandName>sql-persistence</ToolCommandName>
<PackAsTool>True</PackAsTool>
Expand Down
7 changes: 2 additions & 5 deletions src/ScriptBuilder/Saga/InstructionAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ static InstructionAnalyzer()

public static IList<Instruction> GetConfigureHowToFindSagaInstructions(TypeDefinition sagaTypeDefinition)
{
var configureMethod = sagaTypeDefinition.Methods.FirstOrDefault(m => m.Name == "ConfigureHowToFindSaga");
if (configureMethod == null)
{
throw new ErrorsException("Saga does not contain a ConfigureHowToFindSaga method.");
}
var configureMethod = sagaTypeDefinition.Methods.FirstOrDefault(m => m.Name == "ConfigureHowToFindSaga")
?? throw new ErrorsException("Saga does not contain a ConfigureHowToFindSaga method.");

return configureMethod.Body.Instructions;
}
Expand Down
8 changes: 2 additions & 6 deletions src/ScriptBuilder/Saga/SagaDefinitionReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,8 @@ static CorrelationProperty BuildConstraintProperty(TypeDefinition sagaDataTypeDe
return null;
}

var propertyDefinition = sagaDataTypeDefinition.FindInTypeHierarchy(t => t.Properties.SingleOrDefault(x => x.Name == propertyName));

if (propertyDefinition == null)
{
throw new ErrorsException($"Expected type '{sagaDataTypeDefinition.FullName}' to contain a property named '{propertyName}'.");
}
var propertyDefinition = sagaDataTypeDefinition.FindInTypeHierarchy(t => t.Properties.SingleOrDefault(x => x.Name == propertyName))
?? throw new ErrorsException($"Expected type '{sagaDataTypeDefinition.FullName}' to contain a property named '{propertyName}'.");
if (propertyDefinition.SetMethod == null)
{
throw new ErrorsException($"The type '{sagaDataTypeDefinition.FullName}' has a constraint property '{propertyName}' that is read-only.");
Expand Down
7 changes: 2 additions & 5 deletions src/SqlPersistence/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,8 @@ public static async Task<Guid> GetGuidAsync(this DbDataReader reader, int positi

internal static Func<T, object> GetPropertyAccessor<T>(this Type sagaDataType, string propertyName)
{
var propertyInfo = sagaDataType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (propertyInfo == null)
{
throw new Exception($"Expected '{sagaDataType.FullName}' to contain a gettable property named '{propertyName}'.");
}
var propertyInfo = sagaDataType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
?? throw new Exception($"Expected '{sagaDataType.FullName}' to contain a gettable property named '{propertyName}'.");
return data => propertyInfo.GetValue(data);
}

Expand Down
9 changes: 3 additions & 6 deletions src/SqlPersistence/Saga/SagaPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ static void AddTransitionalParameter(IContainSagaData sagaData, RuntimeSagaInfo
{
return;
}
var transitionalId = sagaInfo.TransitionalAccessor(sagaData);
if (transitionalId == null)
{
//TODO: validate non default for value types
throw new Exception($"Null transitionalCorrelationProperty is not allowed. SagaDataType: {sagaData.GetType().FullName}.");
}

//TODO: validate non default for value types if TransitionalAccessor returns null
var transitionalId = sagaInfo.TransitionalAccessor(sagaData) ?? throw new Exception($"Null transitionalCorrelationProperty is not allowed. SagaDataType: {sagaData.GetType().FullName}.");
command.AddParameter("TransitionalCorrelationId", transitionalId);
}

Expand Down

0 comments on commit b720d9c

Please sign in to comment.