Skip to content

Commit

Permalink
Remove MethodCallCodeFragment constructor accepting a chained call (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
roji authored Sep 8, 2021
1 parent 31e551d commit 0d18566
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,15 @@ public override IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
// ttb => ttb.HasPeriodStart("Start").HasColumnName("ColumnStart")
temporalTableBuilderCalls.Add(
periodStartColumnName != null
? new MethodCallCodeFragment(
_temporalTableHasPeriodStartMethodInfo,
new[] { periodStartProperty.Name },
new MethodCallCodeFragment(_temporalPropertyHasColumnNameMethodInfo, periodStartColumnName))
? new MethodCallCodeFragment(_temporalTableHasPeriodStartMethodInfo, periodStartProperty.Name)
.Chain(new MethodCallCodeFragment(_temporalPropertyHasColumnNameMethodInfo, periodStartColumnName))
: new MethodCallCodeFragment(_temporalTableHasPeriodStartMethodInfo, periodStartProperty.Name));

// ttb => ttb.HasPeriodEnd("End").HasColumnName("ColumnEnd")
temporalTableBuilderCalls.Add(
periodEndColumnName != null
? new MethodCallCodeFragment(
_temporalTableHasPeriodEndMethodInfo,
new[] { periodEndProperty.Name },
new MethodCallCodeFragment(_temporalPropertyHasColumnNameMethodInfo, periodEndColumnName))
? new MethodCallCodeFragment(_temporalTableHasPeriodEndMethodInfo, periodEndProperty.Name)
.Chain(new MethodCallCodeFragment(_temporalPropertyHasColumnNameMethodInfo, periodEndColumnName))
: new MethodCallCodeFragment(_temporalTableHasPeriodEndMethodInfo, periodEndProperty.Name));

// ToTable(tb => tb.IsTemporal(ttb => { ... }))
Expand Down
12 changes: 10 additions & 2 deletions src/EFCore/Design/MethodCallCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ public MethodCallCodeFragment(string method, params object?[] arguments)
/// <param name="methodInfo"> The method's <see cref="MethodInfo" />. </param>
/// <param name="arguments"> The method call's arguments. Can be <see cref="NestedClosureCodeFragment" />. </param>
/// <param name="chainedCall"> The next method call to chain after this. </param>
[Obsolete("Use the constructor without a chained call, and then invoke Chain() on the result", error: true)]
public MethodCallCodeFragment(
MethodInfo methodInfo,
object?[] arguments,
MethodCallCodeFragment chainedCall)
: this(methodInfo, arguments)
=> throw new NotSupportedException();

private MethodCallCodeFragment(
MethodInfo methodInfo,
MethodCallCodeFragment chainedCall,
object?[] arguments)
: this(methodInfo, arguments)
{
Check.NotNull(chainedCall, nameof(chainedCall));

Expand All @@ -89,7 +97,7 @@ public MethodCallCodeFragment(
/// <param name="method"> The method's name. </param>
/// <param name="arguments"> The method call's arguments. Can be <see cref="NestedClosureCodeFragment" />. </param>
/// <param name="chainedCall"> The next method call to chain after this. </param>
[Obsolete("Use the overload accepting a MethodInfo")]
[Obsolete("Use the overload accepting a MethodInfo, and then invoke Chain on the instance for the chained call")]
public MethodCallCodeFragment(
string method,
object?[] arguments,
Expand Down Expand Up @@ -170,6 +178,6 @@ public virtual MethodCallCodeFragment Chain(MethodCallCodeFragment call)
#pragma warning disable 618
? new(_method!, _arguments.ToArray(), ChainedCall?.Chain(call) ?? call)
#pragma warning restore 618
: new(MethodInfo, _arguments.ToArray(), ChainedCall?.Chain(call) ?? call);
: new(MethodInfo, ChainedCall?.Chain(call) ?? call, _arguments.ToArray());
}
}
10 changes: 5 additions & 5 deletions test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ public void Fragment_MethodCallCodeFragment_works_when_chaining()
[ConditionalFact]
public void Fragment_MethodCallCodeFragment_works_when_chaining_on_chain()
{
var method = new MethodCallCodeFragment(
_testFuncMethodInfo, new[] { "One" }, new MethodCallCodeFragment(_testFuncMethodInfo, "Two"))
var method = new MethodCallCodeFragment(_testFuncMethodInfo, "One")
.Chain(new MethodCallCodeFragment(_testFuncMethodInfo, "Two"))
.Chain(_testFuncMethodInfo, "Three");

var result = new CSharpHelper(TypeMappingSource).Fragment(method);
Expand All @@ -346,8 +346,8 @@ public void Fragment_MethodCallCodeFragment_works_when_chaining_on_chain()
[ConditionalFact]
public void Fragment_MethodCallCodeFragment_works_when_chaining_on_chain_with_call()
{
var method = new MethodCallCodeFragment(_testFuncMethodInfo, new[] { "One" }, new MethodCallCodeFragment(_testFuncMethodInfo, "Two"))
.Chain(new MethodCallCodeFragment(_testFuncMethodInfo, new[] { "Three" }, new MethodCallCodeFragment(_testFuncMethodInfo, "Four")));
var method = new MethodCallCodeFragment(_testFuncMethodInfo, "One").Chain(new MethodCallCodeFragment(_testFuncMethodInfo, "Two"))
.Chain(new MethodCallCodeFragment(_testFuncMethodInfo, "Three").Chain(new MethodCallCodeFragment(_testFuncMethodInfo, "Four")));

var result = new CSharpHelper(TypeMappingSource).Fragment(method);

Expand Down Expand Up @@ -379,7 +379,7 @@ public void Fragment_MethodCallCodeFragment_works_with_identifier()
[ConditionalFact]
public void Fragment_MethodCallCodeFragment_works_with_identifier_chained()
{
var method = new MethodCallCodeFragment(_testFuncMethodInfo, new[] { "One"}, new MethodCallCodeFragment(_testFuncMethodInfo));
var method = new MethodCallCodeFragment(_testFuncMethodInfo, "One").Chain(new MethodCallCodeFragment(_testFuncMethodInfo));

var result = new CSharpHelper(TypeMappingSource).Fragment(method, instanceIdentifier: "builder");

Expand Down

0 comments on commit 0d18566

Please sign in to comment.