From ca2f5223a73ee14a40a2072922bdb5565b817dd0 Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Fri, 20 Nov 2026 14:11:50 -0600 Subject: [PATCH 1/4] #5046 Dispatch inherited operation methods in generated data portal code The generated IDataPortalOperationMapping/IDataPortalOperationNamedMapping code only covered operation methods the class declares, so operations on a base class (a project base class or CSLA's own, such as BusinessBase.Child_Create) threw DataPortalOperationNotSupportedException from generated code before the data portal fell back to reflection. Concrete classes now include the accessible, non-private operation methods they inherit. Selection follows reflection-based dispatch: a method closer to the class wins (scored as injected parameters less inheritance depth), overrides without the attribute are called virtually at the override's level, and an inherited method whose name the class reuses is called through base. Methods that could bind to the wrong overload, or that reflection could resolve differently, are still left to reflection. Extension methods and the CSLADP002/CSLADP009 analyzers still cover only declared methods. Co-Authored-By: Claude Opus 5.5 --- ...ncrementalDataPortalExtensionsGenerator.cs | 4 +- .../DataPortalOperationsAnalyzer.cs | 3 +- .../DataPortalOperationsBuilder.cs | 62 ++++-- .../Models/OperationMethodModel.cs | 16 ++ .../Models/OperationTypeModel.cs | 6 + .../OperationDiscovery.cs | 136 ++++++++++++- .../DataPortalExtensionsGeneratorTests.cs | 27 +++ ...sonEdit.DataPortalExtensions.g.verified.cs | 34 ++++ .../DataPortalOperationsGeneratorTests.cs | 188 +++++++++++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...ineItem.DataPortalOperations.g.verified.cs | 4 +- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 19 +- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 105 ++++++++++ ...InheritedOperationNameScoring.verified.txt | 4 + ...pBase_1.DataPortalOperations.g.verified.cs | 28 +++ ...ustomer.DataPortalOperations.g.verified.cs | 192 ++++++++++++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 127 ++++++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 130 ++++++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 130 ++++++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 115 +++++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 4 +- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- .../DataPortal/DataPortalExtensionsTests.cs | 15 +- .../InheritedOperationDispatchTests.cs | 192 ++++++++++++++++++ docs/data-portal-operations-generator.md | 37 ++++ releasenotes.md | 1 + 45 files changed, 2219 insertions(+), 53 deletions(-) create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/Snapshots/DataPortalExtensionsGeneratorTests.InheritedOperations#TestApp.PersonEdit.DataPortalExtensions.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring#TestApp.PersonEdit.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring.verified.txt create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationsFromGenericBase#TestApp.AppBase_1.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationsFromGenericBase#TestApp.Customer.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByDerived#TestApp.PersonEdit.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByIntermediate#TestApp.PersonEdit.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverriddenWithoutAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/csla.netcore.test/DataPortal/InheritedOperationDispatchTests.cs diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalExtensions/IncrementalDataPortalExtensionsGenerator.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalExtensions/IncrementalDataPortalExtensionsGenerator.cs index 144c729cd2..dd45afb06d 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalExtensions/IncrementalDataPortalExtensionsGenerator.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalExtensions/IncrementalDataPortalExtensionsGenerator.cs @@ -68,9 +68,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context) if (type is null) return null; + // Extension methods are generated for the operation methods a type + // declares, not for those it inherits. return new ExtensionGenerationModel( type, - new EquatableArray(operationType.Methods.Where(m => SupportedKinds.Contains(m.Kind))), + new EquatableArray(operationType.Methods.Where(m => !m.IsInherited && SupportedKinds.Contains(m.Kind))), options); } } diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsAnalyzer.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsAnalyzer.cs index 88fbc9954c..20ee8ca9ac 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsAnalyzer.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsAnalyzer.cs @@ -60,7 +60,8 @@ private static void AnalyzeType(SymbolAnalysisContext context, Dictionary !m.IsInherited)); foreach (var collision in collisions) { context.ReportDiagnostic(Diagnostic.Create( diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs index ccff75a627..9c42a58e02 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs @@ -96,15 +96,16 @@ public static string Build(OperationTypeModel model) /// Selects the method used for each operation name in generated /// dispatch. Like the runtime method resolution, when several methods /// share an operation name (they differ only in injected parameters) - /// the one with the most injected parameters wins. When several methods - /// tie for the most injected parameters the runtime reports an ambiguous + /// each scores one point per injected parameter, less one point per + /// level of inheritance, and the highest score wins. When several + /// methods tie for the highest score the runtime reports an ambiguous /// match, so none of them is selected and the call is left to /// reflection-based dispatch; the first declared of them is reported as /// the winner of an ambiguous collision. Returns the selected methods /// and any collisions. /// public static (List Selected, List Collisions) - SelectNamedDispatchMethods(EquatableArray methods) + SelectNamedDispatchMethods(IEnumerable methods) { var selected = new List(); var collisions = new List(); @@ -114,16 +115,18 @@ public static (List Selected, List Col var winner = ordered[0]; foreach (var candidate in ordered.Skip(1)) { - if (candidate.InjectCount > winner.InjectCount) + if (Score(candidate) > Score(winner)) winner = candidate; } - var isAmbiguous = ordered.Count(m => m.InjectCount == winner.InjectCount) > 1; + var isAmbiguous = ordered.Count(m => Score(m) == Score(winner)) > 1; if (!isAmbiguous) selected.Add(winner); foreach (var loser in ordered.Where(m => !ReferenceEquals(m, winner))) collisions.Add(new OperationCollision(winner, loser, isAmbiguous)); } return (selected, collisions); + + static int Score(OperationMethodModel method) => method.InjectCount - method.InheritanceDepth; } /// @@ -164,7 +167,9 @@ private static Dictionary GetInterfaceMemberNames( private static void AppendOperationsInterface(IndentedTextWriter writer, OperationTypeModel model, Dictionary memberNames) { writer.WriteLine("/// "); - writer.WriteLine("/// Data portal operation methods declared by this type."); + writer.WriteLine(model.Methods.Any(m => m.IsInherited) + ? "/// Data portal operation methods declared or inherited by this type." + : "/// Data portal operation methods declared by this type."); writer.WriteLine("/// Generated by CSLA .NET so the methods are statically referenced."); writer.WriteLine("/// "); writer.WriteLine("[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]"); @@ -181,7 +186,8 @@ private static void AppendExplicitImplementations(IndentedTextWriter writer, Ope foreach (var method in model.Methods) { var arguments = string.Join(", ", method.Parameters.Select(p => ArgumentPrefix(p) + p.Name)); - writer.WriteLine($"{method.ReturnTypeDisplay} {OperationDiscovery.OperationsInterfaceName}.{memberNames[method]}({FormatParameters(method)}) => {method.MethodName}({arguments});"); + var target = method.CallThroughBase ? "base." + method.MethodName : method.MethodName; + writer.WriteLine($"{method.ReturnTypeDisplay} {OperationDiscovery.OperationsInterfaceName}.{memberNames[method]}({FormatParameters(method)}) => {target}({arguments});"); } } @@ -198,28 +204,44 @@ private static void AppendInvokeOperationAsync(IndentedTextWriter writer, Operat var (_, collisions) = SelectNamedDispatchMethods(model.Methods); var excluded = GetExcludedFromDispatch(collisions); var dispatchable = model.Methods.Where(m => m.CanDispatch && !excluded.Contains(m)).ToList(); - if (dispatchable.Count > 0) + + // When several methods of a kind take the same number of criteria, + // require exact runtime types so a less specific overload cannot + // capture the call. Reflection-based dispatch scores a method lower + // for each level of inheritance, so an inherited method is dispatched + // only when every method closer to the type with that criteria count + // takes criteria that match exact types only (value types and sealed + // types); otherwise reflection might prefer the closer method through + // a less specific match, and the call falls back to reflection. + var byKind = new List<(string Kind, List<(OperationMethodModel Method, bool RequireExactTypes)> Methods)>(); + foreach (var kind in OperationDiscovery.OperationKinds) + { + var ofKind = dispatchable.Where(m => m.Kind == kind).ToList(); + var methods = new List<(OperationMethodModel, bool)>(); + foreach (var method in ofKind) + { + var sameShape = ofKind.Where(m => m.CriteriaCount == method.CriteriaCount).ToList(); + // Methods left out of generated dispatch still compete in reflection-based dispatch. + var closer = model.Methods.Where(m => m.Kind == kind && m.CriteriaCount == method.CriteriaCount && m.InheritanceDepth < method.InheritanceDepth); + if (closer.All(m => m.CriteriaParameters.All(p => p.IsExactTypeMatch))) + methods.Add((method, sameShape.Count > 1)); + } + if (methods.Count > 0) + byKind.Add((kind, methods)); + } + + if (byKind.Count > 0) writer.WriteLine($"var {OperationsLocal} = ({OperationDiscovery.OperationsInterfaceName})this;"); var candidateIndex = 0; var isFirst = true; - foreach (var kind in OperationDiscovery.OperationKinds) + foreach (var (kind, methods) in byKind) { - var methods = dispatchable.Where(m => m.Kind == kind).ToList(); - if (methods.Count == 0) - continue; - writer.WriteLine($"{(isFirst ? "if" : "else if")} (operationType == typeof(global::Csla.{kind}Attribute))"); isFirst = false; OpenBlock(writer); - foreach (var method in methods) - { - // When several methods of this kind take the same number of criteria, - // require exact runtime types so a less specific overload declared - // first cannot capture the call; anything else falls back to reflection. - var requireExactTypes = methods.Count(m => m.CriteriaCount == method.CriteriaCount) > 1; + foreach (var (method, requireExactTypes) in methods) AppendDispatch(writer, method, memberNames[method], candidateIndex++, byName: false, requireExactTypes); - } CloseBlock(writer); } diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs index cfffac2c03..e387a1d84a 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs @@ -48,6 +48,22 @@ internal sealed record OperationMethodModel public LocationInfo? Location { get; init; } + /// + /// How far up the inheritance chain the method is declared: 0 for a + /// method declared by the type, 1 for one inherited from its base type, + /// and so on. Like reflection-based dispatch, a method closer to the + /// type is preferred. + /// + public int InheritanceDepth { get; init; } + + /// + /// The generated code calls the inherited method as base.Method(...) + /// because the type declares another member with the same name. + /// + public bool CallThroughBase { get; init; } + + public bool IsInherited => InheritanceDepth > 0; + public IEnumerable CriteriaParameters => Parameters.Where(p => !p.IsInjected); public int CriteriaCount => Parameters.Count(p => !p.IsInjected); diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationTypeModel.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationTypeModel.cs index 59ab46b958..daad3cfb50 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationTypeModel.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationTypeModel.cs @@ -69,6 +69,12 @@ internal sealed record OperationTypeHeader /// The type has the NoDataPortalExtension attribute. public bool NoExtensions { get; init; } + + /// + /// Operation methods inherited from base types that the generated + /// dispatch of a concrete type can call, nearest base type first. + /// + public EquatableArray InheritedMethods { get; init; } } /// diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs index 105d6e6f4f..43b167c730 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs @@ -148,7 +148,8 @@ internal static class OperationDiscovery /// /// Groups discovered operation methods by type so a partial class - /// spread across several files yields one model. + /// spread across several files yields one model. The methods a type + /// declares come first, followed by the operation methods it inherits. /// public static EquatableArray GroupByType(IEnumerable entries, CancellationToken ct) { @@ -161,7 +162,8 @@ public static EquatableArray GroupByType(IEnumerable e.Method) .OrderBy(m => m.Location?.FilePath ?? string.Empty, StringComparer.Ordinal) .ThenBy(m => m.Location?.TextSpan.Start ?? 0) - .ThenBy(m => Array.IndexOf(OperationKinds, m.Kind)); + .ThenBy(m => Array.IndexOf(OperationKinds, m.Kind)) + .Concat(header.InheritedMethods); result.Add(new OperationTypeModel(header, new EquatableArray(methods))); } return new EquatableArray(result); @@ -211,10 +213,138 @@ private static OperationTypeHeader BuildHeader(INamedTypeSymbol type, SyntaxNode Visibility = GetVisibility(type), HasExtensionsAttribute = extensionsAttribute is not null, ExtensionsPrefix = GetPrefix(extensionsAttribute), - NoExtensions = HasAttribute(type, NoDataPortalExtensionAttributeName) + NoExtensions = HasAttribute(type, NoDataPortalExtensionAttributeName), + InheritedMethods = GetInheritedMethods(type, compilation) }; } + /// + /// The operation methods a concrete type inherits that its generated + /// dispatch can call, nearest base type first. Like reflection-based + /// dispatch, private base methods are not included, and a virtual + /// method overridden without an operation attribute is treated as + /// declared at the level of its most derived override, because the + /// attribute is inherited. A method is left to reflection-based dispatch + /// when the generated code could not call it without binding to another + /// method of the same name. + /// + private static EquatableArray GetInheritedMethods(INamedTypeSymbol type, Compilation compilation) + { + if (type.TypeKind != TypeKind.Class || type.IsAbstract) + return EquatableArray.Empty; + + var result = new List(); + // The type and the base types already walked, nearest first; the index is the inheritance depth. + var chain = new List { type }; + for (var baseType = type.BaseType; baseType is not null && baseType.SpecialType != SpecialType.System_Object; baseType = baseType.BaseType) + { + foreach (var method in baseType.GetMembers().OfType()) + { + if (!IsCandidateMethod(method) + || method.DeclaredAccessibility == Accessibility.Private + || method.Parameters.Any(p => p.RefKind is RefKind.Ref or RefKind.Out)) + continue; + + var kinds = GetOperationKinds(method); + if (kinds.Count == 0 || !compilation.IsSymbolAccessibleWithin(method, type, type)) + continue; + + // An override declaring the same operation attribute is discovered on its own. + var overrides = FindOverrides(chain, method); + kinds.RemoveAll(kind => overrides.Any(o => GetOperationKinds(o.Method).Contains(kind))); + if (kinds.Count == 0) + continue; + + if (!TryGetCallForm(chain, method, out var callThroughBase)) + continue; + + var depth = overrides.Count > 0 ? overrides.Min(o => o.Depth) : chain.Count; + foreach (var kind in kinds) + result.Add(BuildMethod(method, kind) with { InheritanceDepth = depth, CallThroughBase = callThroughBase }); + } + chain.Add(baseType); + } + + // Stable: methods at the same depth keep declaration order. + return new EquatableArray(result.OrderBy(m => m.InheritanceDepth)); + } + + /// + /// The overrides of a base method declared by the types in the chain, + /// with the inheritance depth of each. + /// + private static List<(IMethodSymbol Method, int Depth)> FindOverrides(List chain, IMethodSymbol method) + { + var result = new List<(IMethodSymbol, int)>(); + if (!method.IsVirtual && !method.IsAbstract && !method.IsOverride) + return result; + + for (var depth = 0; depth < chain.Count; depth++) + { + foreach (var candidate in chain[depth].GetMembers(method.Name).OfType()) + { + for (var overridden = candidate.OverriddenMethod; overridden is not null; overridden = overridden.OverriddenMethod) + { + if (SymbolEqualityComparer.Default.Equals(overridden.OriginalDefinition, method.OriginalDefinition)) + { + result.Add((candidate, depth)); + break; + } + } + } + } + return result; + } + + /// + /// Decides how the type calls an inherited method. C# prefers an + /// applicable method declared in a more derived type, so the method is + /// called by name only when no type between the type and the declaring + /// type declares another member of that name. When only the type itself + /// does, and does not override the method, the call goes through + /// base. Otherwise the method is left to reflection-based dispatch. + /// + private static bool TryGetCallForm(List chain, IMethodSymbol method, out bool callThroughBase) + { + callThroughBase = false; + var hidingDepths = new List(); + for (var depth = 0; depth < chain.Count; depth++) + { + if (chain[depth].GetMembers(method.Name).Any(m => m is not IMethodSymbol { IsOverride: true })) + hidingDepths.Add(depth); + } + + if (hidingDepths.Count == 0) + return true; + + if (hidingDepths.Count == 1 && hidingDepths[0] == 0 && FindOverrides([chain[0]], method).Count == 0) + { + callThroughBase = true; + return true; + } + + return false; + } + + /// + /// The operation kinds of the operation attributes on a method, in attribute order. + /// + private static List GetOperationKinds(IMethodSymbol method) + { + var result = new List(); + foreach (var attribute in method.GetAttributes()) + { + if (IsOperationAttribute(attribute.AttributeClass)) + { + var name = attribute.AttributeClass!.Name; + var kind = name.Substring(0, name.Length - "Attribute".Length); + if (!result.Contains(kind)) + result.Add(kind); + } + } + return result; + } + /// /// The Prefix set by a DataPortalExtensions attribute, or null when it is not set. /// diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/DataPortalExtensionsGeneratorTests.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/DataPortalExtensionsGeneratorTests.cs index 7a07590b55..84caa445de 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/DataPortalExtensionsGeneratorTests.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/DataPortalExtensionsGeneratorTests.cs @@ -69,6 +69,33 @@ private void LoadChild(int id, string name) { } await Verify(source); } + [TestMethod("Inherited operation methods get no extensions")] + public async Task InheritedOperations() + { + var source = """ + using Csla; + + namespace TestApp + { + public abstract class PersonBase : BusinessBase + where T : PersonBase + { + [Fetch] + protected void Load(int id) { } + } + + [DataPortalExtensions] + public partial class PersonEdit : PersonBase + { + [Create] + private void New() { } + } + } + """; + + await Verify(source); + } + [TestMethod("Execute operation on a command object")] public async Task ExecuteCommand() { diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/Snapshots/DataPortalExtensionsGeneratorTests.InheritedOperations#TestApp.PersonEdit.DataPortalExtensions.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/Snapshots/DataPortalExtensionsGeneratorTests.InheritedOperations#TestApp.PersonEdit.DataPortalExtensions.g.verified.cs new file mode 100644 index 0000000000..7042e2d81f --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/Snapshots/DataPortalExtensionsGeneratorTests.InheritedOperations#TestApp.PersonEdit.DataPortalExtensions.g.verified.cs @@ -0,0 +1,34 @@ +//HintName: TestApp.PersonEdit.DataPortalExtensions.g.cs +// +#nullable enable + +namespace TestApp +{ + /// + /// Strongly typed data portal extension methods for . + /// + public static partial class PersonEditDataPortalExtensions + { + /// + /// Invokes the New() Create operation of . + /// + [global::Csla.GeneratedDataPortalExtension("CreateAsync")] + public static global::System.Threading.Tasks.Task NewAsync(this global::Csla.IDataPortal portal) + { + if (portal is global::Csla.IDataPortalOperationInvoker __invoker) + return __invoker.CreateByOperationAsync("Create", false, global::System.Array.Empty()); + return portal.CreateAsync(); + } + + /// + /// Invokes the New() Create operation of . + /// + [global::Csla.GeneratedDataPortalExtension("Create")] + public static global::TestApp.PersonEdit New(this global::Csla.IDataPortal portal) + { + if (portal is global::Csla.IDataPortalOperationInvoker __invoker) + return __invoker.CreateByOperation("Create", false, global::System.Array.Empty()); + return portal.Create(); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs index fded39fbe1..b1c62b0aaf 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs @@ -435,6 +435,194 @@ private void Fetch(string name) { } await TestHelperVerify(source); } + [TestMethod("Derived class dispatches operation methods inherited from a generic base class")] + public async Task InheritedOperationsFromGenericBase() + { + var source = """ + using Csla; + + namespace TestApp + { + public class MyCriteria { } + + public abstract partial class AppBase : Csla.BusinessBase + where T : AppBase + { + [Create, RunLocal] + protected virtual void Create(MyCriteria criteria) { } + + [InsertChild] + protected virtual void InsertChild() { } + + [UpdateChild] + protected virtual void UpdateChild() { } + + [Fetch] + private void Fetch(int id) { } + } + + public partial class Customer : AppBase + { + [Update] + protected void Update() { } + } + } + """; + + await TestHelperVerify(source); + } + + [TestMethod("Inherited method with the name of a method declared by the type is called through base")] + public async Task InheritedOverloadHiddenByDerived() + { + var source = """ + using Csla; + + namespace TestApp + { + public abstract class PersonBase : Csla.BusinessBase + where T : PersonBase + { + [Fetch] + protected void Fetch(int id) { } + } + + public partial class PersonEdit : PersonBase + { + [Fetch] + private void Fetch(string name) { } + } + } + """; + + await TestHelperVerify(source); + } + + [TestMethod("Inherited method hidden by a member of an intermediate class is left to reflection")] + public async Task InheritedOverloadHiddenByIntermediate() + { + var source = """ + using Csla; + + namespace TestApp + { + public abstract class PersonBase : Csla.BusinessBase + where T : PersonBase + { + [Fetch] + protected void Fetch(int id) { } + + [Delete] + protected void Delete(int id) { } + } + + public abstract class PersonMiddle : PersonBase + where T : PersonMiddle + { + protected void Fetch(System.Guid id) { } + } + + public partial class PersonEdit : PersonMiddle + { + [Create] + private void Create() { } + } + } + """; + + await TestHelperVerify(source); + } + + [TestMethod("Inherited method overridden without the attribute is called virtually at the level of the override")] + public async Task InheritedOverriddenWithoutAttribute() + { + var source = """ + using Csla; + + namespace TestApp + { + public abstract class PersonBase : Csla.BusinessBase + where T : PersonBase + { + [Fetch] + protected virtual void Fetch(int id) { } + } + + public partial class PersonEdit : PersonBase + { + protected override void Fetch(int id) { } + + protected override void Child_Create() { } + + [Create] + private void Create() { } + } + } + """; + + await TestHelperVerify(source); + } + + [TestMethod("Inherited method with the criteria count of a method declared by the type is left to reflection")] + public async Task InheritedSameShapeAcrossLevels() + { + var source = """ + using Csla; + + namespace TestApp + { + public abstract class PersonBase : Csla.BusinessBase + where T : PersonBase + { + [Fetch] + protected void Load(int id) { } + } + + public partial class PersonEdit : PersonBase + { + [Fetch] + private void Fetch(object value) { } + } + } + """; + + await TestHelperVerify(source); + } + + [TestMethod("Inherited and declared methods with the same operation name are scored like reflection")] + public async Task InheritedOperationNameScoring() + { + var source = """ + using Csla; + + namespace TestApp + { + public interface IDal { } + + public abstract class PersonBase : Csla.BusinessBase + where T : PersonBase + { + [Fetch] + protected void Load(int id, [Inject] IDal dal) { } + + [Delete] + protected void Remove(int id) { } + } + + public partial class PersonEdit : PersonBase + { + [Fetch] + private void Fetch(int id) { } + + [Delete] + private void Delete(int id) { } + } + } + """; + + await DataPortalOperationsTestHelper.VerifyWithDiagnostics(source); + } + [TestMethod("Generic business object excludes type parameter criteria from name dispatch")] public async Task GenericBusinessObject() { diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOperationName#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOperationName#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 60bf1357c6..713b12bd49 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOperationName#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOperationName#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -17,11 +17,13 @@ internal interface IDataPortalOperations void Fetch__Int32(int id, global::TestApp.IDal dal); void Fetch__Int32_2(int id, global::TestApp.IDal dal); void Fetch__String(string name); + void CreateChild(); } void IDataPortalOperations.Fetch__Int32(int id, global::TestApp.IDal dal) => Fetch(id, dal); void IDataPortalOperations.Fetch__Int32_2(int id, global::TestApp.IDal dal) => Load(id, dal); void IDataPortalOperations.Fetch__String(string name) => Fetch(name); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -42,6 +44,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -65,6 +82,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 027119f4c2..8a6aba0985 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -17,11 +17,13 @@ internal interface IDataPortalOperations void Fetch__Object(object value); void Fetch__Criteria(global::TestApp.Criteria criteria); void Fetch__Int32(int id); + void CreateChild(); } void IDataPortalOperations.Fetch__Object(object value) => Fetch(value); void IDataPortalOperations.Fetch__Criteria(global::TestApp.Criteria criteria) => Fetch(criteria); void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -66,6 +68,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -117,6 +134,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ArrayNullableGenericCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ArrayNullableGenericCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 5c2dee87fd..9b924a9e2d 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ArrayNullableGenericCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ArrayNullableGenericCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -19,6 +19,7 @@ internal interface IDataPortalOperations void Fetch__List_1_Int32(global::System.Collections.Generic.List ids); void Fetch__ValueTuple_2_Int32_String((int Id, string Name) key); void Fetch__Dictionary_2_String_List_1_Nullable_1_Int32Array(global::System.Collections.Generic.Dictionary>[] map); + void CreateChild(); } void IDataPortalOperations.Fetch__Int32Array(int[] ids) => Fetch(ids); @@ -26,6 +27,7 @@ internal interface IDataPortalOperations void IDataPortalOperations.Fetch__List_1_Int32(global::System.Collections.Generic.List ids) => Fetch(ids); void IDataPortalOperations.Fetch__ValueTuple_2_Int32_String((int Id, string Name) key) => Fetch(key); void IDataPortalOperations.Fetch__Dictionary_2_String_List_1_Nullable_1_Int32Array(global::System.Collections.Generic.Dictionary>[] map) => Fetch(map); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -94,6 +96,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -173,6 +190,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AsyncMethod#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AsyncMethod#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 292debe11f..790710879a 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AsyncMethod#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AsyncMethod#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,16 +8,18 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal interface IDataPortalOperations { global::System.Threading.Tasks.Task Fetch__Int32(int id); + void CreateChild(); } global::System.Threading.Tasks.Task IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -39,6 +41,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -63,6 +80,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ChildOperations#TestApp.LineItem.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ChildOperations#TestApp.LineItem.DataPortalOperations.g.verified.cs index 278a334932..383438da6a 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ChildOperations#TestApp.LineItem.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ChildOperations#TestApp.LineItem.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class LineItem : global::TestApp.LineItem.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -19,6 +19,7 @@ internal interface IDataPortalOperations global::System.Threading.Tasks.Task InsertChild(global::TestApp.IDal dal); global::System.Threading.Tasks.Task UpdateChild(global::TestApp.IDal dal); global::System.Threading.Tasks.Task DeleteSelfChild(global::TestApp.IDal dal); + void CreateChild_2(); } void IDataPortalOperations.CreateChild() => CreateChild(); @@ -26,6 +27,7 @@ internal interface IDataPortalOperations global::System.Threading.Tasks.Task IDataPortalOperations.InsertChild(global::TestApp.IDal dal) => InsertChild(dal); global::System.Threading.Tasks.Task IDataPortalOperations.UpdateChild(global::TestApp.IDal dal) => UpdateChild(dal); global::System.Threading.Tasks.Task IDataPortalOperations.DeleteSelfChild(global::TestApp.IDal dal) => DeleteSelfChild(dal); + void IDataPortalOperations.CreateChild_2() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.CompleteCrud#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.CompleteCrud#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index f5673b76b8..cb71c31da5 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.CompleteCrud#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.CompleteCrud#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -19,6 +19,7 @@ internal interface IDataPortalOperations global::System.Threading.Tasks.Task Insert(global::TestApp.IDal dal); global::System.Threading.Tasks.Task Update(global::TestApp.IDal dal); global::System.Threading.Tasks.Task DeleteSelf(global::TestApp.IDal dal); + void CreateChild(); } void IDataPortalOperations.Create() => Create(); @@ -26,6 +27,7 @@ internal interface IDataPortalOperations global::System.Threading.Tasks.Task IDataPortalOperations.Insert(global::TestApp.IDal dal) => Insert(dal); global::System.Threading.Tasks.Task IDataPortalOperations.Update(global::TestApp.IDal dal) => Update(dal); global::System.Threading.Tasks.Task IDataPortalOperations.DeleteSelf(global::TestApp.IDal dal) => DeleteSelf(dal); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -112,6 +114,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -197,6 +214,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DeleteWithCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DeleteWithCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index d98d640ff5..1587551d0e 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DeleteWithCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DeleteWithCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,16 +8,18 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal interface IDataPortalOperations { void Delete__Int32(int id); + void CreateChild(); } void IDataPortalOperations.Delete__Int32(int id) => Delete(id); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -38,6 +40,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -61,6 +78,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DerivedFromBaseWithOperations#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DerivedFromBaseWithOperations#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index b1a9ebee86..71380cb576 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DerivedFromBaseWithOperations#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DerivedFromBaseWithOperations#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,16 +8,18 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal new interface IDataPortalOperations { void Fetch__String(string name); + void CreateChild(); } void IDataPortalOperations.Fetch__String(string name) => Fetch(name); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -38,6 +40,21 @@ partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, glo return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -61,6 +78,20 @@ partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, glo return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DuplicateOperationName#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DuplicateOperationName#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index ba756baa31..59781d0fcf 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DuplicateOperationName#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DuplicateOperationName#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -17,11 +17,13 @@ internal interface IDataPortalOperations void Fetch__Int32(int id); void Fetch__Int32(int id, global::TestApp.IDal dal); void Fetch__Int32_2(int id); + void CreateChild(); } void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); void IDataPortalOperations.Fetch__Int32(int id, global::TestApp.IDal dal) => Fetch(id, dal); void IDataPortalOperations.Fetch__Int32_2(int id) => Load(id); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -43,6 +45,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -67,6 +84,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ExistingNamedMapping#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ExistingNamedMapping#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 30791f457c..2537ae3e44 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ExistingNamedMapping#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ExistingNamedMapping#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,16 +8,18 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal interface IDataPortalOperations { void Fetch__Int32(int id); + void CreateChild(); } void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -38,6 +40,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.FileScopedNamespace#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.FileScopedNamespace#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index fcf69747ae..32b54bd89d 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.FileScopedNamespace#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.FileScopedNamespace#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -16,10 +16,12 @@ internal interface IDataPortalOperations { void Create(); void Fetch__Int32(int id); + void CreateChild(); } void IDataPortalOperations.Create() => Create(); void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -55,6 +57,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -92,6 +109,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InCriteriaAndNullableInject#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InCriteriaAndNullableInject#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index febe36be00..88509d1209 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InCriteriaAndNullableInject#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InCriteriaAndNullableInject#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -16,10 +16,12 @@ internal interface IDataPortalOperations { void Fetch__String_Int32(in string? name, in int id); void Create(int? count, global::TestApp.IDal? dal); + void CreateChild(); } void IDataPortalOperations.Fetch__String_Int32(in string? name, in int id) => Fetch(in name, in id); void IDataPortalOperations.Create(int? count, global::TestApp.IDal? dal) => Create(count, dal); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -57,6 +59,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -97,6 +114,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring#TestApp.PersonEdit.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..801876b012 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -0,0 +1,105 @@ +//HintName: TestApp.PersonEdit.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void Fetch__Int32(int id); + void Delete__Int32(int id); + void Fetch__Int32(int id, global::TestApp.IDal dal); + void Delete__Int32_2(int id); + void CreateChild(); + } + + void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.Delete__Int32(int id) => Delete(id); + void IDataPortalOperations.Fetch__Int32(int id, global::TestApp.IDal dal) => Load(id, dal); + void IDataPortalOperations.Delete__Int32_2(int id) => Remove(id); + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.DeleteAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is int __c0p0) + { + try + { + __operations.Delete__Int32(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Delete", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "Delete__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c0p0) + { + try + { + __operations.Delete__Int32(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Delete", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring.verified.txt b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring.verified.txt new file mode 100644 index 0000000000..98c1405475 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring.verified.txt @@ -0,0 +1,4 @@ +{ + target: null, + Diagnostics: [] +} \ No newline at end of file diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationsFromGenericBase#TestApp.AppBase_1.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationsFromGenericBase#TestApp.AppBase_1.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..3f50261ef8 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationsFromGenericBase#TestApp.AppBase_1.DataPortalOperations.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: TestApp.AppBase_1.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class AppBase : global::TestApp.AppBase.IDataPortalOperations + { + /// + /// Data portal operation methods declared by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void Create__MyCriteria_1_T(global::TestApp.MyCriteria criteria); + void InsertChild(); + void UpdateChild(); + void Fetch__Int32(int id); + } + + void IDataPortalOperations.Create__MyCriteria_1_T(global::TestApp.MyCriteria criteria) => Create(criteria); + void IDataPortalOperations.InsertChild() => InsertChild(); + void IDataPortalOperations.UpdateChild() => UpdateChild(); + void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationsFromGenericBase#TestApp.Customer.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationsFromGenericBase#TestApp.Customer.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..87f8663c17 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationsFromGenericBase#TestApp.Customer.DataPortalOperations.g.verified.cs @@ -0,0 +1,192 @@ +//HintName: TestApp.Customer.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class Customer : global::TestApp.Customer.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal new interface IDataPortalOperations + { + void Update(); + void Create__MyCriteria_1_Customer(global::TestApp.MyCriteria criteria); + void InsertChild(); + void UpdateChild(); + void CreateChild(); + } + + void IDataPortalOperations.Update() => Update(); + void IDataPortalOperations.Create__MyCriteria_1_Customer(global::TestApp.MyCriteria criteria) => Create(criteria); + void IDataPortalOperations.InsertChild() => InsertChild(); + void IDataPortalOperations.UpdateChild() => UpdateChild(); + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.CreateAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is global::TestApp.MyCriteria __c0p0) + { + try + { + __operations.Create__MyCriteria_1_Customer(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Create", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.UpdateAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.Update(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Update", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.InsertChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.InsertChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "InsertChild", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.UpdateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.UpdateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "UpdateChild", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "Update": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.Update(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Update", __ex); + } + return; + } + break; + case "Create__MyCriteria_1_Customer": + if (criteria is { Length: 1 } && (criteria[0] is null || criteria[0] is global::TestApp.MyCriteria)) + { + try + { + __operations.Create__MyCriteria_1_Customer((global::TestApp.MyCriteria)criteria[0]!); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Create", __ex); + } + return; + } + break; + case "InsertChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.InsertChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "InsertChild", __ex); + } + return; + } + break; + case "UpdateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.UpdateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "UpdateChild", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByDerived#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByDerived#TestApp.PersonEdit.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..14abc30989 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByDerived#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -0,0 +1,127 @@ +//HintName: TestApp.PersonEdit.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void Fetch__String(string name); + void Fetch__Int32(int id); + void CreateChild(); + } + + void IDataPortalOperations.Fetch__String(string name) => Fetch(name); + void IDataPortalOperations.Fetch__Int32(int id) => base.Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.FetchAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is string __c0p0) + { + try + { + __operations.Fetch__String(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Fetch__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "Fetch__String": + if (criteria is { Length: 1 } && (criteria[0] is null || criteria[0] is string)) + { + try + { + __operations.Fetch__String((string)criteria[0]!); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + break; + case "Fetch__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Fetch__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByIntermediate#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByIntermediate#TestApp.PersonEdit.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..feb63cc21f --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByIntermediate#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -0,0 +1,130 @@ +//HintName: TestApp.PersonEdit.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void Create(); + void Delete__Int32(int id); + void CreateChild(); + } + + void IDataPortalOperations.Create() => Create(); + void IDataPortalOperations.Delete__Int32(int id) => Delete(id); + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.CreateAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.Create(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Create", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.DeleteAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Delete__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Delete", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "Create": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.Create(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Create", __ex); + } + return; + } + break; + case "Delete__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Delete__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Delete", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverriddenWithoutAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverriddenWithoutAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..98c55ac3ec --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverriddenWithoutAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -0,0 +1,130 @@ +//HintName: TestApp.PersonEdit.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void Create(); + void Fetch__Int32(int id); + void CreateChild(); + } + + void IDataPortalOperations.Create() => Create(); + void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.CreateAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.Create(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Create", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.FetchAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Fetch__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "Create": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.Create(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Create", __ex); + } + return; + } + break; + case "Fetch__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Fetch__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..107b536890 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -0,0 +1,115 @@ +//HintName: TestApp.PersonEdit.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void Fetch__Object(object value); + void Fetch__Int32(int id); + void CreateChild(); + } + + void IDataPortalOperations.Fetch__Object(object value) => Fetch(value); + void IDataPortalOperations.Fetch__Int32(int id) => Load(id); + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.FetchAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is object __c0p0 && __c0p0.GetType() == typeof(object)) + { + try + { + __operations.Fetch__Object(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "Fetch__Object": + if (criteria is { Length: 1 } && (criteria[0] is null || criteria[0] is object)) + { + try + { + __operations.Fetch__Object((object)criteria[0]!); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + break; + case "Fetch__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Fetch__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Load", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InjectBeforeCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InjectBeforeCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 85c75718ea..c8ebb96ac4 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InjectBeforeCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InjectBeforeCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,16 +8,18 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal interface IDataPortalOperations { void Fetch__Int32_String(global::TestApp.IDal dal, int id, global::TestApp.IDal? backup, string name); + void CreateChild(); } void IDataPortalOperations.Fetch__Int32_String(global::TestApp.IDal dal, int id, global::TestApp.IDal? backup, string name) => Fetch(dal, id, backup, name); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -40,6 +42,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -65,6 +82,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.KeyedInject#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.KeyedInject#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 83860fee03..5620e7b254 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.KeyedInject#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.KeyedInject#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -16,10 +16,12 @@ internal interface IDataPortalOperations { void Fetch__Int32(int id, global::TestApp.IDal dal, global::TestApp.IDal? secondary); void Create(global::TestApp.IDal dal, global::TestApp.IDal other); + void CreateChild(); } void IDataPortalOperations.Fetch__Int32(int id, global::TestApp.IDal dal, global::TestApp.IDal? secondary) => Fetch(id, dal, secondary); void IDataPortalOperations.Create(global::TestApp.IDal dal, global::TestApp.IDal other) => Create(dal, other); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -59,6 +61,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -100,6 +117,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.MultipleOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.MultipleOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index f8c7a1e844..616a112ae3 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.MultipleOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.MultipleOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -16,10 +16,12 @@ internal interface IDataPortalOperations { void Fetch__String(string name); void Fetch__Int32(int id); + void CreateChild(); } void IDataPortalOperations.Fetch__String(string name) => Fetch(name); void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -52,6 +54,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -89,6 +106,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.NestedClass#TestApp.Outer.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.NestedClass#TestApp.Outer.PersonEdit.DataPortalOperations.g.verified.cs index fe4459a3d8..1b73b5686c 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.NestedClass#TestApp.Outer.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.NestedClass#TestApp.Outer.PersonEdit.DataPortalOperations.g.verified.cs @@ -10,16 +10,18 @@ partial class Outer partial class PersonEdit : global::TestApp.Outer.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal interface IDataPortalOperations { void Fetch__Int32(int id); + void CreateChild(); } void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -40,6 +42,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -63,6 +80,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.OperationWithInjectAllowNull#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.OperationWithInjectAllowNull#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 3d662c9cd2..3d7ea72eb3 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.OperationWithInjectAllowNull#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.OperationWithInjectAllowNull#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,16 +8,18 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal interface IDataPortalOperations { global::System.Threading.Tasks.Task Fetch__Int32(int id, global::TestApp.ILogger? logger); + void CreateChild(); } global::System.Threading.Tasks.Task IDataPortalOperations.Fetch__Int32(int id, global::TestApp.ILogger? logger) => Fetch(id, logger); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -40,6 +42,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -65,6 +82,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.OperationWithInjectParam#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.OperationWithInjectParam#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 9f7d9f1205..39e5c5e331 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.OperationWithInjectParam#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.OperationWithInjectParam#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,16 +8,18 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal interface IDataPortalOperations { global::System.Threading.Tasks.Task Insert(global::TestApp.IDal dal); + void CreateChild(); } global::System.Threading.Tasks.Task IDataPortalOperations.Insert(global::TestApp.IDal dal) => Insert(dal); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -40,6 +42,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -65,6 +82,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ParamsArrayAndKeywordNames#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ParamsArrayAndKeywordNames#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 3640bcbb8c..63dc381c50 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ParamsArrayAndKeywordNames#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ParamsArrayAndKeywordNames#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -16,10 +16,12 @@ internal interface IDataPortalOperations { void Fetch__ObjectArray(object[] values); void Create__Int32_String(int @class, string @event); + void CreateChild(); } void IDataPortalOperations.Fetch__ObjectArray(object[] values) => Fetch(values); void IDataPortalOperations.Create__Int32_String(int @class, string @event) => Create(@class, @event); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -40,6 +42,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -63,6 +80,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PartialClassAcrossFiles#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PartialClassAcrossFiles#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index fcf69747ae..32b54bd89d 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PartialClassAcrossFiles#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PartialClassAcrossFiles#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -16,10 +16,12 @@ internal interface IDataPortalOperations { void Create(); void Fetch__Int32(int id); + void CreateChild(); } void IDataPortalOperations.Create() => Create(); void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -55,6 +57,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -92,6 +109,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.RootAndChildAttributes#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.RootAndChildAttributes#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 5b03d2a0df..dc9b0a854e 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.RootAndChildAttributes#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.RootAndChildAttributes#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -16,10 +16,12 @@ internal interface IDataPortalOperations { void Create(); void CreateChild(); + void CreateChild_2(); } void IDataPortalOperations.Create() => Create(); void IDataPortalOperations.CreateChild() => Create(); + void IDataPortalOperations.CreateChild_2() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.RunLocalAndValueTask#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.RunLocalAndValueTask#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 47b41957bd..c098843ca1 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.RunLocalAndValueTask#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.RunLocalAndValueTask#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -17,11 +17,13 @@ internal interface IDataPortalOperations void Create(); global::System.Threading.Tasks.ValueTask Fetch__Int32(int id); global::System.Threading.Tasks.ValueTask Fetch__String(string name); + void CreateChild(); } void IDataPortalOperations.Create() => Create(); global::System.Threading.Tasks.ValueTask IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); global::System.Threading.Tasks.ValueTask IDataPortalOperations.Fetch__String(string name) => Fetch(name); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -71,6 +73,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -124,6 +141,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.SingleCreateNoParams#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.SingleCreateNoParams#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index b534c5a5a4..378c1ccefe 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.SingleCreateNoParams#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.SingleCreateNoParams#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,16 +8,18 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal interface IDataPortalOperations { void Create(); + void CreateChild(); } void IDataPortalOperations.Create() => Create(); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -38,6 +40,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -61,6 +78,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.SingleFetchWithCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.SingleFetchWithCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index fc9b8a3a20..2fa9b65686 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.SingleFetchWithCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.SingleFetchWithCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,16 +8,18 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal interface IDataPortalOperations { void Fetch__Int32(int id); + void CreateChild(); } void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) @@ -38,6 +40,21 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); } @@ -61,6 +78,20 @@ internal interface IDataPortalOperations return; } break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; } throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); } diff --git a/Source/tests/csla.netcore.test/DataPortal/DataPortalExtensionsTests.cs b/Source/tests/csla.netcore.test/DataPortal/DataPortalExtensionsTests.cs index c3ac0e16cd..582c246b9b 100644 --- a/Source/tests/csla.netcore.test/DataPortal/DataPortalExtensionsTests.cs +++ b/Source/tests/csla.netcore.test/DataPortal/DataPortalExtensionsTests.cs @@ -399,10 +399,17 @@ public void GeneratedInterfaceMemberNames_MatchRuntimeOperationNames() var attributeType = typeof(FetchAttribute).Assembly.GetType($"Csla.{kind}Attribute", throwOnError: true)!; var memberParameters = member.GetParameters().Select(p => p.ParameterType).ToArray(); - var method = type - .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly) - .Single(m => m.GetCustomAttributes(attributeType, false).Any() - && m.GetParameters().Select(p => p.ParameterType).SequenceEqual(memberParameters)); + // The interface also names operation methods inherited from base + // types; find the nearest declaration, as the data portal does. + System.Reflection.MethodInfo method = null; + for (var declaringType = type; method is null && declaringType is not null; declaringType = declaringType.BaseType) + { + method = declaringType + .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly) + .SingleOrDefault(m => m.GetCustomAttributes(attributeType, true).Any() + && m.GetParameters().Select(p => p.ParameterType).SequenceEqual(memberParameters)); + } + method.Should().NotBeNull($"{type.Name}.{member.Name} should name an operation method"); var expected = (string)typeof(DataPortalOperationNameHelper) .GetMethod(nameof(DataPortalOperationNameHelper.ComputeOperationName), BindingFlags.Static | BindingFlags.NonPublic)! diff --git a/Source/tests/csla.netcore.test/DataPortal/InheritedOperationDispatchTests.cs b/Source/tests/csla.netcore.test/DataPortal/InheritedOperationDispatchTests.cs new file mode 100644 index 0000000000..8c447b8687 --- /dev/null +++ b/Source/tests/csla.netcore.test/DataPortal/InheritedOperationDispatchTests.cs @@ -0,0 +1,192 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) Marimer LLC. All rights reserved. +// Website: https://cslanet.com +// +// Generated dispatch of operation methods inherited from a base class +//----------------------------------------------------------------------- +using System.Runtime.ExceptionServices; +using Csla.Server; +using Csla.Testing; +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Csla.Test.DataPortal +{ + /// + /// Operation methods declared on a base class are dispatched by the + /// derived class's generated mapping, so the data portal does not throw + /// DataPortalOperationNotSupportedException before falling back to + /// reflection. + /// + [TestClass] + public class InheritedOperationDispatchTests + { + private static CslaTestHost _testHost = default!; + private int _notSupportedCount; + + [ClassInitialize] + public static void ClassSetup(TestContext context) + { + _ = context; + _testHost = CslaTestHost.Create(); + } + + [ClassCleanup] + public static void ClassCleanup() + { + _testHost?.Dispose(); + } + + [TestInitialize] + public void Setup() + { + InheritedOperationLog.Calls.Clear(); + _notSupportedCount = 0; + AppDomain.CurrentDomain.FirstChanceException += OnFirstChanceException; + } + + [TestCleanup] + public void Cleanup() + { + AppDomain.CurrentDomain.FirstChanceException -= OnFirstChanceException; + } + + private void OnFirstChanceException(object sender, FirstChanceExceptionEventArgs e) + { + if (e.Exception is DataPortalOperationNotSupportedException) + Interlocked.Increment(ref _notSupportedCount); + } + + [TestMethod] + public void CreateCallsInheritedMethodWithoutFallback() + { + var portal = _testHost.GetDataPortal(); + + var root = portal.Create(42); + + root.Seed.Should().Be(42); + InheritedOperationLog.Calls.Should().Equal("Base.Create"); + _notSupportedCount.Should().Be(0); + } + + [TestMethod] + public void FetchCallsInheritedOverloadThroughBase() + { + var portal = _testHost.GetDataPortal(); + + portal.Fetch(7); + portal.Fetch("name"); + + InheritedOperationLog.Calls.Should().Equal("Base.Fetch(int)", "Root.Fetch(string)"); + _notSupportedCount.Should().Be(0); + } + + [TestMethod] + public void SaveCallsInheritedRootAndChildMethodsWithoutFallback() + { + var portal = _testHost.GetDataPortal(); + var root = portal.Create(1); + root.Children.AddNew(); + root.Children.AddNew(); + + root = root.Save(); + root.Children[0].Name = "changed"; + root.Children[1].Name = "changed"; + root.Save(); + + InheritedOperationLog.Calls.Should().Equal( + "Base.Create", + "ChildBase.Insert", "ChildBase.Insert", "Base.Insert", + "ChildBase.Update", "ChildBase.Update", "Base.Update"); + _notSupportedCount.Should().Be(0); + } + } + + internal static class InheritedOperationLog + { + public static List Calls { get; } = []; + } + + public abstract partial class InheritedOpsRootBase : BusinessBase + where T : InheritedOpsRootBase + { + public static readonly PropertyInfo SeedProperty = RegisterProperty(nameof(Seed)); + public int Seed + { + get => GetProperty(SeedProperty); + private set => LoadProperty(SeedProperty, value); + } + + [Create, RunLocal] + protected virtual void Create(int seed) + { + InheritedOperationLog.Calls.Add("Base.Create"); + Seed = seed; + OnCreated(); + } + + protected virtual void OnCreated() { } + + [Fetch] + protected void Fetch(int id) => InheritedOperationLog.Calls.Add("Base.Fetch(int)"); + + [Insert] + protected virtual void Insert() + { + FieldManager.UpdateChildren(); + InheritedOperationLog.Calls.Add("Base.Insert"); + } + + [Update] + protected virtual void Update() + { + FieldManager.UpdateChildren(); + InheritedOperationLog.Calls.Add("Base.Update"); + } + } + + public partial class InheritedOpsRoot : InheritedOpsRootBase + { + public static readonly PropertyInfo ChildrenProperty = RegisterProperty(nameof(Children)); + public InheritedOpsChildList Children + { + get => GetProperty(ChildrenProperty); + private set => LoadProperty(ChildrenProperty, value); + } + + protected override void OnCreated() + { + var childPortal = ApplicationContext.GetRequiredService>(); + Children = childPortal.CreateChild(); + } + + [Fetch] + private void Fetch(string name) => InheritedOperationLog.Calls.Add("Root.Fetch(string)"); + } + + public abstract partial class InheritedOpsChildBase : BusinessBase + where T : InheritedOpsChildBase + { + public static readonly PropertyInfo NameProperty = RegisterProperty(nameof(Name)); + public string Name + { + get => GetProperty(NameProperty); + set => SetProperty(NameProperty, value); + } + + [InsertChild] + protected virtual void InsertChild() => InheritedOperationLog.Calls.Add("ChildBase.Insert"); + + [UpdateChild] + protected virtual void UpdateChild() => InheritedOperationLog.Calls.Add("ChildBase.Update"); + } + + public partial class InheritedOpsChild : InheritedOpsChildBase + { + [FetchChild] + private void FetchChild(string name) => LoadProperty(NameProperty, name); + } + + public class InheritedOpsChildList : BusinessListBase; +} diff --git a/docs/data-portal-operations-generator.md b/docs/data-portal-operations-generator.md index ff53f22d0e..af130be0b7 100644 --- a/docs/data-portal-operations-generator.md +++ b/docs/data-portal-operations-generator.md @@ -47,6 +47,43 @@ The data portal dispatches an operation in this order: The generated code resolves `[Inject]` parameters and reports errors the same way as reflection-based dispatch. An exception thrown by an operation method is wrapped in a `CallMethodException`, as before. +## Inherited operation methods + +The generated dispatch of a concrete class also calls the operation methods it inherits, so operation methods can live on a shared base class: + +```csharp +public abstract partial class AppBase : BusinessBase + where T : AppBase +{ + [Create, RunLocal] + protected virtual void Create(MyCriteria criteria) { } + + [InsertChild] + protected virtual void InsertChild() { } +} + +public partial class Customer : AppBase +{ + [Update] + private void Update() { } +} +``` + +The generated code for `Customer` calls `Create`, `InsertChild` and `Update` directly, along with operation methods inherited from CSLA's base classes, such as `BusinessBase.Child_Create`. It chooses between methods the same way reflection-based dispatch does: + +* Private methods of a base class are not included. +* A method declared closer to the class is preferred over one declared further up the inheritance chain. +* An override is called virtually, even when it does not repeat the operation attribute. +* If the class declares a member with the same name as an inherited operation method, the generated code calls the inherited method through `base`. + +In a few cases the generated code leaves an inherited method to reflection-based dispatch, which still calls it as before: + +* An intermediate base class declares another member with the same name, which would hide the method from the generated code. +* A method closer to the class takes the same number of criteria, and a less specific parameter type, such as `object`, means reflection could choose that closer method instead. +* The method is internal to another assembly. + +Extension methods from the [data portal extensions generator](data-portal-extensions-generator.md) and the CSLADP002 and CSLADP009 analyzers cover only the operation methods a class declares. + ## Operation methods that share a name Two operation methods map to the same operation when they have the same attribute and the same criteria parameter types, and differ only in their `[Inject]` parameters. As with reflection-based dispatch, the data portal calls the method with more injected parameters, and analyzer [CSLADP002](analyzers/CSLADP002-DuplicateOperationName.md) reports which method is used. If the methods have the same number of injected parameters, the data portal cannot choose between them, and analyzer [CSLADP009](analyzers/CSLADP009-AmbiguousOperationName.md) reports the ambiguity. diff --git a/releasenotes.md b/releasenotes.md index aa56cff6c1..58f416a428 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -130,6 +130,7 @@ The new `Csla.Mvvm.ViewModel` in the `Csla` package has the view model behavi * [#4996](https://github.com/MarimerLLC/csla/issues/4996) A create or fetch with a single `null` criteria value works with a remote data portal; the `NullCriteria` constructor is now public so the server can deserialize it ([#4997](https://github.com/MarimerLLC/csla/pull/4997)) * [#5024](https://github.com/MarimerLLC/csla/issues/5024) `[CslaImplementPropertiesInterface]` generates properties when the attribute name is namespace-qualified (`Csla.`, `global::Csla.`) or aliased; before, it generated an empty class. The interface can be declared in a different file from the class; before, that made the generator fail. When the attribute isn't on a partial class or struct, or `T` isn't an interface declared in the same project, nothing is generated and the new analyzer CSLA0030 reports it. Attributes on the interface's properties are copied with their type and the names in their arguments fully qualified, so namespace-qualified, aliased, nested and generic attribute types and arguments such as `typeof(Strings)` that rely on the interface file's `using` directives work; before, a namespace-qualified attribute was emitted with its namespace twice ([#5026](https://github.com/MarimerLLC/csla/pull/5026)) * [#4970](https://github.com/MarimerLLC/csla/issues/4970) `Csla.Maui` no longer causes an `IL2112` trim warning in apps that use `csla:PropertyInfo` ([#4973](https://github.com/MarimerLLC/csla/pull/4973)) +* [#5046](https://github.com/MarimerLLC/csla/issues/5046) The generated data portal dispatch of a concrete class also calls the operation methods it inherits from base classes, including `BusinessBase.Child_Create`. Before, calling an inherited operation threw `DataPortalOperationNotSupportedException` from the generated code (caught by the data portal, which then used reflection), so the debugger could break on nearly every data portal call in a project that keeps its operations on a base class **Security** From beba4ca866028d2d44acedfd8503e0070705120c Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Fri, 20 Nov 2026 14:12:17 -0600 Subject: [PATCH 2/4] #5046 Link the pull request in the release notes Co-Authored-By: Claude Opus 5.5 --- releasenotes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes.md b/releasenotes.md index 58f416a428..1df73ba8aa 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -130,7 +130,7 @@ The new `Csla.Mvvm.ViewModel` in the `Csla` package has the view model behavi * [#4996](https://github.com/MarimerLLC/csla/issues/4996) A create or fetch with a single `null` criteria value works with a remote data portal; the `NullCriteria` constructor is now public so the server can deserialize it ([#4997](https://github.com/MarimerLLC/csla/pull/4997)) * [#5024](https://github.com/MarimerLLC/csla/issues/5024) `[CslaImplementPropertiesInterface]` generates properties when the attribute name is namespace-qualified (`Csla.`, `global::Csla.`) or aliased; before, it generated an empty class. The interface can be declared in a different file from the class; before, that made the generator fail. When the attribute isn't on a partial class or struct, or `T` isn't an interface declared in the same project, nothing is generated and the new analyzer CSLA0030 reports it. Attributes on the interface's properties are copied with their type and the names in their arguments fully qualified, so namespace-qualified, aliased, nested and generic attribute types and arguments such as `typeof(Strings)` that rely on the interface file's `using` directives work; before, a namespace-qualified attribute was emitted with its namespace twice ([#5026](https://github.com/MarimerLLC/csla/pull/5026)) * [#4970](https://github.com/MarimerLLC/csla/issues/4970) `Csla.Maui` no longer causes an `IL2112` trim warning in apps that use `csla:PropertyInfo` ([#4973](https://github.com/MarimerLLC/csla/pull/4973)) -* [#5046](https://github.com/MarimerLLC/csla/issues/5046) The generated data portal dispatch of a concrete class also calls the operation methods it inherits from base classes, including `BusinessBase.Child_Create`. Before, calling an inherited operation threw `DataPortalOperationNotSupportedException` from the generated code (caught by the data portal, which then used reflection), so the debugger could break on nearly every data portal call in a project that keeps its operations on a base class +* [#5046](https://github.com/MarimerLLC/csla/issues/5046) The generated data portal dispatch of a concrete class also calls the operation methods it inherits from base classes, including `BusinessBase.Child_Create`. Before, calling an inherited operation threw `DataPortalOperationNotSupportedException` from the generated code (caught by the data portal, which then used reflection), so the debugger could break on nearly every data portal call in a project that keeps its operations on a base class ([#5048](https://github.com/MarimerLLC/csla/pull/5048)) **Security** From 2584d18f5bb5ee99339d77fec82002d393b120ac Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Fri, 20 Nov 2026 15:08:14 -0600 Subject: [PATCH 3/4] #5046 Address review findings in inherited operation dispatch - Track whether a method is inherited separately from its dispatch depth, so overrides without the attribute (such as Child_Create) get no extension methods and no misplaced diagnostics. - Report CSLADP002/CSLADP009 for collisions between a declared and an inherited method, at the declared method, so a cross-level tie that reflection reports as ambiguous is visible at build time. - Leave methods whose signature uses a private or protected nested type out of the generated interface and dispatch; they made the generated code fail to compile (CS0051). Applies to declared methods as well. - Require exact criteria types only between methods at the same level; guard a less specific declared method against criteria that match a method further up the chain instead, so it keeps handling other calls. - Add inherited methods once per type in a separate pipeline step rather than for every operation method. - Dispatch a lone params object[] operation method (the editable lists' Child_UpdateAsync) with the whole criteria array, as reflection does, when no other method of its kind exists. Co-Authored-By: Claude Opus 5.5 --- .../DataPortalOperationsAnalyzer.cs | 14 +- .../DataPortalOperationsBuilder.cs | 125 +++++++++++++---- ...ncrementalDataPortalOperationsGenerator.cs | 7 +- .../Models/OperationMethodModel.cs | 24 +++- .../Models/OperationTypeModel.cs | 20 +-- .../OperationDiscovery.cs | 94 ++++++++++--- .../DataPortalOperations/TrackingNames.cs | 3 + .../DataPortalExtensionsGeneratorTests.cs | 8 ++ .../DataPortalOperationsGeneratorTests.cs | 77 +++++++++++ ...InheritedOperationNameScoring.verified.txt | 45 +++++- ...sonEdit.DataPortalOperations.g.verified.cs | 2 +- ...ineItem.DataPortalOperations.g.verified.cs | 99 +++++++++++++ ...neItems.DataPortalOperations.g.verified.cs | 116 ++++++++++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 130 ++++++++++++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 2 +- ...sonEdit.DataPortalOperations.g.verified.cs | 14 ++ ...sonEdit.DataPortalOperations.g.verified.cs | 68 +++++++++ .../InheritedOperationDispatchTests.cs | 12 +- docs/data-portal-operations-generator.md | 8 +- releasenotes.md | 2 +- 20 files changed, 804 insertions(+), 66 deletions(-) create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedParamsArrayUpdateChild#TestApp.LineItem.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedParamsArrayUpdateChild#TestApp.LineItems.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedProtectedNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PrivateNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsAnalyzer.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsAnalyzer.cs index 20ee8ca9ac..9ecaed60b9 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsAnalyzer.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsAnalyzer.cs @@ -60,13 +60,21 @@ private static void AnalyzeType(SymbolAnalysisContext context, Dictionary !m.IsInherited)); + var (_, collisions) = DataPortalOperationsBuilder.SelectNamedDispatchMethods(model.Methods); foreach (var collision in collisions) { + // A collision between two inherited methods is reported on the type + // declaring them. One that involves a method the type declares is + // reported at that method, even when the other method wins. + var declared = !collision.Loser.IsInherited ? collision.Loser + : !collision.Winner.IsInherited ? collision.Winner + : null; + if (declared is null) + continue; + context.ReportDiagnostic(Diagnostic.Create( collision.IsAmbiguous ? DataPortalOperationsDiagnostics.AmbiguousOperationName : DataPortalOperationsDiagnostics.DuplicateOperationName, - collision.Loser.Location?.ToLocation(context.Compilation), + declared.Location?.ToLocation(context.Compilation), collision.Winner.MethodDisplay, collision.Loser.MethodDisplay, model.Type.TypeName, collision.Winner.OperationName)); } } diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs index 9c42a58e02..287cf2f8a3 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs @@ -31,7 +31,7 @@ internal static class DataPortalOperationsBuilder public static string Build(OperationTypeModel model) { var type = model.Type; - var memberNames = GetInterfaceMemberNames(model.Methods); + var memberNames = GetInterfaceMemberNames(InterfaceMethods(model)); using var stringWriter = new StringWriter(); var writer = new IndentedTextWriter(stringWriter, " "); @@ -145,7 +145,14 @@ public static HashSet GetExcludedFromDispatch(List GetInterfaceMemberNames(EquatableArray methods) + /// + /// The methods named by the IDataPortalOperations interface: all + /// methods except those whose signature the interface cannot name. + /// + private static IEnumerable InterfaceMethods(OperationTypeModel model) + => model.Methods.Where(m => m.CanNameSignature); + + private static Dictionary GetInterfaceMemberNames(IEnumerable methods) { var result = new Dictionary(ReferenceEqualityComparer.Instance); var signatures = new HashSet(); @@ -176,14 +183,14 @@ private static void AppendOperationsInterface(IndentedTextWriter writer, Operati var modifiers = model.Type.HidesInheritedOperationsInterface ? "internal new interface" : "internal interface"; writer.WriteLine($"{modifiers} {OperationDiscovery.OperationsInterfaceName}"); OpenBlock(writer); - foreach (var method in model.Methods) + foreach (var method in InterfaceMethods(model)) writer.WriteLine($"{method.ReturnTypeDisplay} {memberNames[method]}({FormatParameters(method)});"); CloseBlock(writer); } private static void AppendExplicitImplementations(IndentedTextWriter writer, OperationTypeModel model, Dictionary memberNames) { - foreach (var method in model.Methods) + foreach (var method in InterfaceMethods(model)) { var arguments = string.Join(", ", method.Parameters.Select(p => ArgumentPrefix(p) + p.Name)); var target = method.CallThroughBase ? "base." + method.MethodName : method.MethodName; @@ -203,29 +210,51 @@ private static void AppendInvokeOperationAsync(IndentedTextWriter writer, Operat // only the one the runtime would select takes part in dispatch. var (_, collisions) = SelectNamedDispatchMethods(model.Methods); var excluded = GetExcludedFromDispatch(collisions); - var dispatchable = model.Methods.Where(m => m.CanDispatch && !excluded.Contains(m)).ToList(); - - // When several methods of a kind take the same number of criteria, - // require exact runtime types so a less specific overload cannot - // capture the call. Reflection-based dispatch scores a method lower - // for each level of inheritance, so an inherited method is dispatched - // only when every method closer to the type with that criteria count - // takes criteria that match exact types only (value types and sealed - // types); otherwise reflection might prefer the closer method through - // a less specific match, and the call falls back to reflection. - var byKind = new List<(string Kind, List<(OperationMethodModel Method, bool RequireExactTypes)> Methods)>(); + var dispatchable = model.Methods.Where(m => m.CanDispatch && m.CanNameSignature && !excluded.Contains(m)).ToList(); + + var byKind = new List<(string Kind, List Methods)>(); foreach (var kind in OperationDiscovery.OperationKinds) { + // Every method of the kind competes in reflection-based dispatch, + // including those left out of generated dispatch. + var all = model.Methods.Where(m => m.Kind == kind).ToList(); var ofKind = dispatchable.Where(m => m.Kind == kind).ToList(); - var methods = new List<(OperationMethodModel, bool)>(); + var methods = new List(); foreach (var method in ofKind) { - var sameShape = ofKind.Where(m => m.CriteriaCount == method.CriteriaCount).ToList(); - // Methods left out of generated dispatch still compete in reflection-based dispatch. - var closer = model.Methods.Where(m => m.Kind == kind && m.CriteriaCount == method.CriteriaCount && m.InheritanceDepth < method.InheritanceDepth); - if (closer.All(m => m.CriteriaParameters.All(p => p.IsExactTypeMatch))) - methods.Add((method, sameShape.Count > 1)); + var sameShape = all.Where(m => m.CriteriaCount == method.CriteriaCount).ToList(); + + // Reflection-based dispatch scores a method lower for each level of + // inheritance. An inherited method is dispatched only when every + // method closer to the type with that criteria count takes criteria + // that match exact types only (value types and sealed types), which + // a less specific match cannot outscore; otherwise the call is left + // to reflection. + if (!sameShape.Where(m => m.InheritanceDepth < method.InheritanceDepth).All(HasExactCriteriaTypes)) + continue; + + // When several methods at one level take the same number of + // criteria, require exact runtime types so a less specific overload + // cannot capture the call. + var requireExactTypes = ofKind.Count(m => m.CriteriaCount == method.CriteriaCount && m.InheritanceDepth == method.InheritanceDepth) > 1; + + // A method with less specific criteria types leaves the call to + // reflection when the criteria also match a method further up the + // inheritance chain, unless they match its own types exactly. + var guards = requireExactTypes || HasExactCriteriaTypes(method) + ? [] + : sameShape.Where(m => m.InheritanceDepth > method.InheritanceDepth && !HasSameCriteriaTypes(m, method)).ToList(); + + methods.Add(new CriteriaDispatch(method, requireExactTypes, guards)); } + + // A method taking the whole criteria array as params object[] is + // called by reflection-based dispatch when no other method matches; + // it is dispatched only when it is the only method of its kind. + if (all.Count == 1 && all[0].TakesCriteriaArray && all[0].Parameters[0].IsParams + && all[0].CanNameSignature && !model.UnresolvedKinds.Contains(kind)) + methods.Add(new CriteriaDispatch(all[0], RequireExactTypes: false, [])); + if (methods.Count > 0) byKind.Add((kind, methods)); } @@ -240,8 +269,8 @@ private static void AppendInvokeOperationAsync(IndentedTextWriter writer, Operat writer.WriteLine($"{(isFirst ? "if" : "else if")} (operationType == typeof(global::Csla.{kind}Attribute))"); isFirst = false; OpenBlock(writer); - foreach (var (method, requireExactTypes) in methods) - AppendDispatch(writer, method, memberNames[method], candidateIndex++, byName: false, requireExactTypes); + foreach (var dispatch in methods) + AppendDispatch(writer, dispatch.Method, memberNames[dispatch.Method], candidateIndex++, byName: false, dispatch.RequireExactTypes, dispatch.Guards); CloseBlock(writer); } @@ -249,6 +278,22 @@ private static void AppendInvokeOperationAsync(IndentedTextWriter writer, Operat CloseBlock(writer); } + /// + /// A method in criteria-based dispatch. are methods + /// further up the inheritance chain whose criteria types, when matched, + /// leave the call to reflection-based dispatch. + /// + private sealed record CriteriaDispatch(OperationMethodModel Method, bool RequireExactTypes, IReadOnlyList Guards); + + private static bool HasExactCriteriaTypes(OperationMethodModel method) + => method.CriteriaParameters.All(p => p.IsExactTypeMatch); + + private static bool HasSameCriteriaTypes(OperationMethodModel left, OperationMethodModel right) + => left.CriteriaParameters.Select(CriteriaTypeKey).SequenceEqual(right.CriteriaParameters.Select(CriteriaTypeKey)); + + private static string CriteriaTypeKey(OperationParameterModel parameter) + => parameter.PatternTypeDisplay + (parameter.IsNullableValueType ? "?" : string.Empty); + private static void AppendInvokeNamedOperationAsync(IndentedTextWriter writer, OperationTypeModel model, Dictionary memberNames) { writer.WriteLine("async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync("); @@ -257,7 +302,8 @@ private static void AppendInvokeNamedOperationAsync(IndentedTextWriter writer, O writer.Indent--; OpenBlock(writer); - var (selected, _) = SelectNamedDispatchMethods(model.Methods); + // A selected method the interface cannot name is left to reflection. + var selected = SelectNamedDispatchMethods(model.Methods).Selected.Where(m => m.CanNameSignature).ToList(); if (selected.Count > 0) { writer.WriteLine($"var {OperationsLocal} = ({OperationDiscovery.OperationsInterfaceName})this;"); @@ -279,11 +325,16 @@ private static void AppendInvokeNamedOperationAsync(IndentedTextWriter writer, O CloseBlock(writer); } - private static void AppendDispatch(IndentedTextWriter writer, OperationMethodModel method, string memberName, int candidateIndex, bool byName, bool requireExactTypes) + private static void AppendDispatch(IndentedTextWriter writer, OperationMethodModel method, string memberName, int candidateIndex, bool byName, bool requireExactTypes, + IReadOnlyList? guards = null) { var criteria = method.CriteriaParameters.ToList(); var conditions = new List(); - if (criteria.Count == 0) + if (method.TakesCriteriaArray) + { + // The method receives the whole criteria array, whatever it holds. + } + else if (criteria.Count == 0) { conditions.Add("criteria is null or { Length: 0 }"); } @@ -305,9 +356,23 @@ private static void AppendDispatch(IndentedTextWriter writer, OperationMethodMod conditions.Add($"{variable}.GetType() == typeof({parameter.PatternTypeDisplay})"); } } + + if (guards is { Count: > 0 }) + { + var exactMatch = string.Join(" && ", criteria + .Select((p, i) => (Parameter: p, Index: i)) + .Where(c => !c.Parameter.IsExactTypeMatch) + .Select(c => $"{CriteriaVariable(candidateIndex, c.Index)}.GetType() == typeof({c.Parameter.PatternTypeDisplay})")); + foreach (var guard in guards) + { + var guardMatch = string.Join(" && ", guard.CriteriaParameters.Select((p, i) => $"criteria[{i}] is {p.PatternTypeDisplay}")); + conditions.Add($"!({guardMatch} && !({exactMatch}))"); + } + } } - writer.WriteLine($"if ({string.Join(" && ", conditions)})"); + if (conditions.Count > 0) + writer.WriteLine($"if ({string.Join(" && ", conditions)})"); OpenBlock(writer); if (method.IsAsync) @@ -349,6 +414,12 @@ private static void AppendDispatch(IndentedTextWriter writer, OperationMethodMod argument = variable; } } + else if (method.TakesCriteriaArray) + { + // Like reflection-based dispatch, pass the criteria array itself. + // The cast through object avoids a nullability mismatch with object[]. + argument = $"({parameter.TypeDisplay})(object)criteria!"; + } else { argument = CriteriaVariable(candidateIndex, i); diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/IncrementalDataPortalOperationsGenerator.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/IncrementalDataPortalOperationsGenerator.cs index 9a7cf5be9d..efe0cc88b3 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/IncrementalDataPortalOperationsGenerator.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/IncrementalDataPortalOperationsGenerator.cs @@ -57,9 +57,14 @@ internal static IncrementalValueProvider> Get .Select(static (pair, _) => pair.Left.AddRange(pair.Right)); } + // Inherited operation methods are added once per type, rather than + // for each operation method the type declares. return all .Select(static (entries, ct) => OperationDiscovery.GroupByType(entries, ct)) - .WithTrackingName(TrackingNames.GroupOperationTypes); + .WithTrackingName(TrackingNames.GroupOperationTypes) + .Combine(context.CompilationProvider) + .Select(static (pair, ct) => OperationDiscovery.AddInheritedMethods(pair.Left, pair.Right, ct)) + .WithTrackingName(TrackingNames.InheritedOperationMethods); } private static IncrementalValueProvider> GetOperationMethods(IncrementalGeneratorInitializationContext context, string kind) diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs index e387a1d84a..f3bce6de45 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs @@ -62,7 +62,19 @@ internal sealed record OperationMethodModel /// public bool CallThroughBase { get; init; } - public bool IsInherited => InheritanceDepth > 0; + /// + /// The method is declared by a base type, not by the type itself. An + /// inherited method the type overrides without repeating the operation + /// attribute has an of 0 but is still + /// inherited. + /// + public bool IsInherited { get; init; } + + /// + /// The method takes a single object[] parameter, which receives + /// the whole criteria array. + /// + public bool TakesCriteriaArray => Parameters.Count == 1 && Parameters[0].IsObjectArray; public IEnumerable CriteriaParameters => Parameters.Where(p => !p.IsInjected); @@ -77,7 +89,15 @@ internal sealed record OperationMethodModel /// public bool CanDispatch => !Parameters.Any(p => p.RefKindPrefix is "ref " or "out ") - && !(Parameters.Count == 1 && Parameters[0].IsObjectArray); + && !TakesCriteriaArray; + + /// + /// The parameter and return types can be used in the type's internal + /// IDataPortalOperations interface. A method taking a private or + /// protected nested type is left out of the interface and of generated + /// dispatch, and is called through reflection. + /// + public bool CanNameSignature { get; init; } = true; /// /// The method can take part in name-based dispatch. When criteria diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationTypeModel.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationTypeModel.cs index daad3cfb50..1a11282833 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationTypeModel.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationTypeModel.cs @@ -69,12 +69,6 @@ internal sealed record OperationTypeHeader /// The type has the NoDataPortalExtension attribute. public bool NoExtensions { get; init; } - - /// - /// Operation methods inherited from base types that the generated - /// dispatch of a concrete type can call, nearest base type first. - /// - public EquatableArray InheritedMethods { get; init; } } /// @@ -83,7 +77,17 @@ internal sealed record OperationTypeHeader internal sealed record OperationMethodEntry(OperationTypeHeader Type, OperationMethodModel Method); /// - /// A type and all of its data portal operation methods. + /// A type and all of its data portal operation methods: those it + /// declares, followed by those it inherits, nearest base type first. /// - internal sealed record OperationTypeModel(OperationTypeHeader Type, EquatableArray Methods); + internal sealed record OperationTypeModel(OperationTypeHeader Type, EquatableArray Methods) + { + /// + /// Operation kinds for which reflection-based dispatch can see an + /// operation method that is not in , such as an + /// inherited method the generated code cannot call. Generated dispatch + /// must not assume it knows every candidate method of these kinds. + /// + public EquatableArray UnresolvedKinds { get; init; } + } } diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs index 43b167c730..c94e833304 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs @@ -130,7 +130,7 @@ internal static class OperationDiscovery } } - return entries.Count == 0 ? null : GroupByType(entries, ct)[0]; + return entries.Count == 0 ? null : AddInheritedMethods(GroupByType(entries, ct)[0], type, compilation); } /// @@ -148,8 +148,8 @@ internal static class OperationDiscovery /// /// Groups discovered operation methods by type so a partial class - /// spread across several files yields one model. The methods a type - /// declares come first, followed by the operation methods it inherits. + /// spread across several files yields one model. Inherited methods are + /// added afterwards by . /// public static EquatableArray GroupByType(IEnumerable entries, CancellationToken ct) { @@ -162,8 +162,7 @@ public static EquatableArray GroupByType(IEnumerable e.Method) .OrderBy(m => m.Location?.FilePath ?? string.Empty, StringComparer.Ordinal) .ThenBy(m => m.Location?.TextSpan.Start ?? 0) - .ThenBy(m => Array.IndexOf(OperationKinds, m.Kind)) - .Concat(header.InheritedMethods); + .ThenBy(m => Array.IndexOf(OperationKinds, m.Kind)); result.Add(new OperationTypeModel(header, new EquatableArray(methods))); } return new EquatableArray(result); @@ -213,8 +212,48 @@ private static OperationTypeHeader BuildHeader(INamedTypeSymbol type, SyntaxNode Visibility = GetVisibility(type), HasExtensionsAttribute = extensionsAttribute is not null, ExtensionsPrefix = GetPrefix(extensionsAttribute), - NoExtensions = HasAttribute(type, NoDataPortalExtensionAttributeName), - InheritedMethods = GetInheritedMethods(type, compilation) + NoExtensions = HasAttribute(type, NoDataPortalExtensionAttributeName) + }; + } + + /// + /// Adds the inherited operation methods to each type model. Runs once + /// per type, after the methods a type declares are grouped. + /// + public static EquatableArray AddInheritedMethods(EquatableArray models, Compilation compilation, CancellationToken ct) + { + var result = new List(models.Count); + foreach (var model in models) + { + ct.ThrowIfCancellationRequested(); + var type = compilation.Assembly.GetTypeByMetadataName(model.Type.MetadataName); + result.Add(type is null ? model : AddInheritedMethods(model, type, compilation)); + } + return new EquatableArray(result); + } + + /// + /// Adds the inherited operation methods to the model of a type. + /// + public static OperationTypeModel AddInheritedMethods(OperationTypeModel model, INamedTypeSymbol type, Compilation compilation) + { + var unresolved = new List(); + var inherited = GetInheritedMethods(type, compilation, unresolved); + + // Reflection-based dispatch also sees generic operation methods the type declares. + foreach (var method in type.GetMembers().OfType()) + { + if (method.MethodKind == MethodKind.Ordinary && !method.IsStatic && method.IsGenericMethod) + unresolved.AddRange(GetOperationKinds(method)); + } + + if (inherited.Count == 0 && unresolved.Count == 0) + return model; + + return model with + { + Methods = new EquatableArray(model.Methods.Concat(inherited)), + UnresolvedKinds = new EquatableArray(unresolved.Distinct().OrderBy(k => Array.IndexOf(OperationKinds, k))) }; } @@ -226,27 +265,27 @@ private static OperationTypeHeader BuildHeader(INamedTypeSymbol type, SyntaxNode /// declared at the level of its most derived override, because the /// attribute is inherited. A method is left to reflection-based dispatch /// when the generated code could not call it without binding to another - /// method of the same name. + /// method of the same name, or could not name its parameter or return + /// types; the kinds of such methods are added to . /// - private static EquatableArray GetInheritedMethods(INamedTypeSymbol type, Compilation compilation) + private static List GetInheritedMethods(INamedTypeSymbol type, Compilation compilation, List unresolvedKinds) { + var result = new List(); if (type.TypeKind != TypeKind.Class || type.IsAbstract) - return EquatableArray.Empty; + return result; - var result = new List(); // The type and the base types already walked, nearest first; the index is the inheritance depth. var chain = new List { type }; for (var baseType = type.BaseType; baseType is not null && baseType.SpecialType != SpecialType.System_Object; baseType = baseType.BaseType) { foreach (var method in baseType.GetMembers().OfType()) { - if (!IsCandidateMethod(method) - || method.DeclaredAccessibility == Accessibility.Private - || method.Parameters.Any(p => p.RefKind is RefKind.Ref or RefKind.Out)) + // Reflection-based dispatch ignores static and private base methods. + if (method.MethodKind != MethodKind.Ordinary || method.IsStatic || method.DeclaredAccessibility == Accessibility.Private) continue; var kinds = GetOperationKinds(method); - if (kinds.Count == 0 || !compilation.IsSymbolAccessibleWithin(method, type, type)) + if (kinds.Count == 0) continue; // An override declaring the same operation attribute is discovered on its own. @@ -255,20 +294,38 @@ private static EquatableArray GetInheritedMethods(INamedTy if (kinds.Count == 0) continue; - if (!TryGetCallForm(chain, method, out var callThroughBase)) + if (!IsCandidateMethod(method) + || method.Parameters.Any(p => p.RefKind is RefKind.Ref or RefKind.Out) + || !compilation.IsSymbolAccessibleWithin(method, type, type) + || !CanNameSignature(method) + || !TryGetCallForm(chain, method, out var callThroughBase)) + { + unresolvedKinds.AddRange(kinds); continue; + } var depth = overrides.Count > 0 ? overrides.Min(o => o.Depth) : chain.Count; foreach (var kind in kinds) - result.Add(BuildMethod(method, kind) with { InheritanceDepth = depth, CallThroughBase = callThroughBase }); + result.Add(BuildMethod(method, kind) with { InheritanceDepth = depth, CallThroughBase = callThroughBase, IsInherited = true }); } chain.Add(baseType); } // Stable: methods at the same depth keep declaration order. - return new EquatableArray(result.OrderBy(m => m.InheritanceDepth)); + return result.OrderBy(m => m.InheritanceDepth).ToList(); } + /// + /// The parameter and return types of a method can be used in the type's + /// internal IDataPortalOperations interface. A private or protected + /// nested criteria type, for example, cannot: the interface member would + /// fail to compile (CS0051), so the method is left to reflection-based + /// dispatch. + /// + private static bool CanNameSignature(IMethodSymbol method) + => GetVisibility(method.ReturnType) != TypeVisibility.Private + && method.Parameters.All(p => GetVisibility(p.Type) != TypeVisibility.Private); + /// /// The overrides of a base method declared by the types in the chain, /// with the inheritance depth of each. @@ -377,6 +434,7 @@ private static OperationMethodModel BuildMethod(IMethodSymbol method, string kin OperationName = operationName, RunLocal = HasAttribute(method, RunLocalAttributeName), NoExtension = HasAttribute(method, NoDataPortalExtensionAttributeName), + CanNameSignature = CanNameSignature(method), Location = LocationInfo.From(method.Locations.FirstOrDefault()) }; } diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/TrackingNames.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/TrackingNames.cs index 6a959422b1..2b49320e72 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/TrackingNames.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/TrackingNames.cs @@ -19,6 +19,9 @@ public static class TrackingNames /// Grouping of operation methods by containing type. public const string GroupOperationTypes = nameof(GroupOperationTypes); + /// Addition of the operation methods each type inherits. + public const string InheritedOperationMethods = nameof(InheritedOperationMethods); + /// Per-type models for operations generation. public const string OperationTypes = nameof(OperationTypes); diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/DataPortalExtensionsGeneratorTests.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/DataPortalExtensionsGeneratorTests.cs index 84caa445de..004e630881 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/DataPortalExtensionsGeneratorTests.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalExtensions/DataPortalExtensionsGeneratorTests.cs @@ -82,6 +82,9 @@ public abstract class PersonBase : BusinessBase { [Fetch] protected void Load(int id) { } + + [Fetch] + protected virtual void Find(string name) { } } [DataPortalExtensions] @@ -89,6 +92,11 @@ public partial class PersonEdit : PersonBase { [Create] private void New() { } + + // Overrides without the attribute are still inherited operations. + protected override void Find(string name) { } + + protected override void Child_Create() { } } } """; diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs index b1c62b0aaf..2277ecbf41 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs @@ -623,6 +623,83 @@ private void Delete(int id) { } await DataPortalOperationsTestHelper.VerifyWithDiagnostics(source); } + [TestMethod("Inherited method taking a protected nested type is left to reflection")] + public async Task InheritedProtectedNestedCriteria() + { + var source = """ + using Csla; + + namespace TestApp + { + public abstract class PersonBase : Csla.BusinessBase + where T : PersonBase + { + protected class Criteria { } + + [Fetch] + protected void Fetch(Criteria criteria) { } + + [Delete] + protected void Delete(int id) { } + } + + public partial class PersonEdit : PersonBase + { + [Create] + private void Create() { } + } + } + """; + + await TestHelperVerify(source); + } + + [TestMethod("Declared method taking a private nested type is left to reflection")] + public async Task PrivateNestedCriteria() + { + var source = """ + using Csla; + + namespace TestApp + { + public partial class PersonEdit : Csla.BusinessBase + { + private class Criteria { } + + [Fetch] + private void Fetch(Criteria criteria) { } + } + } + """; + + await TestHelperVerify(source); + } + + [TestMethod("Child list dispatches the inherited params object array update")] + public async Task InheritedParamsArrayUpdateChild() + { + var source = """ + using Csla; + + namespace TestApp + { + public partial class LineItem : Csla.BusinessBase + { + [FetchChild] + private void FetchChild(int id) { } + } + + public partial class LineItems : Csla.BusinessListBase + { + [FetchChild] + private void FetchChild(int count) { } + } + } + """; + + await TestHelperVerify(source); + } + [TestMethod("Generic business object excludes type parameter criteria from name dispatch")] public async Task GenericBusinessObject() { diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring.verified.txt b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring.verified.txt index 98c1405475..9b089dfb80 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring.verified.txt +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOperationNameScoring.verified.txt @@ -1,4 +1,47 @@ { target: null, - Diagnostics: [] + Diagnostics: [ + { + Location: /* + [Fetch] + private void Fetch(int id) { } + ^^^^^ + +*/ + Source0.cs: (19,17)-(19,22), + Message: Methods 'Fetch(int)' and 'Load(int, IDal)' on 'PersonEdit' both map to data portal operation 'Fetch__Int32' with the same number of injected parameters; the data portal cannot choose between them and reports an ambiguous match, + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: CSLADP009, + Title: Data portal operation methods are ambiguous, + HelpLink: https://github.com/MarimerLLC/csla/tree/main/docs/analyzers/CSLADP009-AmbiguousOperationName.md, + MessageFormat: Methods '{0}' and '{1}' on '{2}' both map to data portal operation '{3}' with the same number of injected parameters; the data portal cannot choose between them and reports an ambiguous match, + Category: Csla.DataPortal, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Delete] + private void Delete(int id) { } + ^^^^^^ + } +*/ + Source0.cs: (22,17)-(22,23), + Message: Methods 'Delete(int)' and 'Remove(int)' on 'PersonEdit' both map to data portal operation 'Delete__Int32'; name-based dispatch uses 'Delete(int)', + Severity: Info, + WarningLevel: 1, + Descriptor: { + Id: CSLADP002, + Title: Data portal operation methods share an operation name, + HelpLink: https://github.com/MarimerLLC/csla/tree/main/docs/analyzers/CSLADP002-DuplicateOperationName.md, + MessageFormat: Methods '{0}' and '{1}' on '{2}' both map to data portal operation '{3}'; name-based dispatch uses '{0}', + Category: Csla.DataPortal, + DefaultSeverity: Info, + IsEnabledByDefault: true + } + } + ] } \ No newline at end of file diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverriddenWithoutAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverriddenWithoutAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 98c55ac3ec..32b54bd89d 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverriddenWithoutAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverriddenWithoutAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -8,7 +8,7 @@ namespace TestApp partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping { /// - /// Data portal operation methods declared by this type. + /// Data portal operation methods declared or inherited by this type. /// Generated by CSLA .NET so the methods are statically referenced. /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedParamsArrayUpdateChild#TestApp.LineItem.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedParamsArrayUpdateChild#TestApp.LineItem.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..de00e200b2 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedParamsArrayUpdateChild#TestApp.LineItem.DataPortalOperations.g.verified.cs @@ -0,0 +1,99 @@ +//HintName: TestApp.LineItem.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class LineItem : global::TestApp.LineItem.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void FetchChild__Int32(int id); + void CreateChild(); + } + + void IDataPortalOperations.FetchChild__Int32(int id) => FetchChild(id); + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.FetchChildAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.FetchChild__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "FetchChild", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "FetchChild__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c0p0) + { + try + { + __operations.FetchChild__Int32(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "FetchChild", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedParamsArrayUpdateChild#TestApp.LineItems.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedParamsArrayUpdateChild#TestApp.LineItems.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..35127f1cc8 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedParamsArrayUpdateChild#TestApp.LineItems.DataPortalOperations.g.verified.cs @@ -0,0 +1,116 @@ +//HintName: TestApp.LineItems.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class LineItems : global::TestApp.LineItems.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void FetchChild__Int32(int count); + void CreateChild(); + global::System.Threading.Tasks.Task UpdateChild__ObjectArray(object?[] parameters); + } + + void IDataPortalOperations.FetchChild__Int32(int count) => FetchChild(count); + void IDataPortalOperations.CreateChild() => Child_Create(); + global::System.Threading.Tasks.Task IDataPortalOperations.UpdateChild__ObjectArray(object?[] parameters) => Child_UpdateAsync(parameters); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.FetchChildAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.FetchChild__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "FetchChild", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.UpdateChildAttribute)) + { + { + global::Csla.Server.DataPortalOperationHelper.ThrowIfAsyncMethodOnSyncClient(this, isSync, serviceProvider, "Child_UpdateAsync"); + try + { + await __operations.UpdateChild__ObjectArray((object?[])(object)criteria!).ConfigureAwait(false); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_UpdateAsync", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "FetchChild__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c0p0) + { + try + { + __operations.FetchChild__Int32(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "FetchChild", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedProtectedNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedProtectedNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..feb63cc21f --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedProtectedNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -0,0 +1,130 @@ +//HintName: TestApp.PersonEdit.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void Create(); + void Delete__Int32(int id); + void CreateChild(); + } + + void IDataPortalOperations.Create() => Create(); + void IDataPortalOperations.Delete__Int32(int id) => Delete(id); + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.CreateAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.Create(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Create", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.DeleteAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Delete__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Delete", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "Create": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.Create(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Create", __ex); + } + return; + } + break; + case "Delete__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Delete__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Delete", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 107b536890..1f345aa41f 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -29,7 +29,7 @@ internal interface IDataPortalOperations var __operations = (IDataPortalOperations)this; if (operationType == typeof(global::Csla.FetchAttribute)) { - if (criteria is { Length: 1 } && criteria[0] is object __c0p0 && __c0p0.GetType() == typeof(object)) + if (criteria is { Length: 1 } && criteria[0] is object __c0p0 && !(criteria[0] is int && !(__c0p0.GetType() == typeof(object)))) { try { diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ParamsArrayAndKeywordNames#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ParamsArrayAndKeywordNames#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 63dc381c50..63b9f8878f 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ParamsArrayAndKeywordNames#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ParamsArrayAndKeywordNames#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -42,6 +42,20 @@ internal interface IDataPortalOperations return; } } + else if (operationType == typeof(global::Csla.FetchAttribute)) + { + { + try + { + __operations.Fetch__ObjectArray((object[])(object)criteria!); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + } else if (operationType == typeof(global::Csla.CreateChildAttribute)) { if (criteria is null or { Length: 0 }) diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PrivateNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PrivateNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..f5960b54c0 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PrivateNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: TestApp.PersonEdit.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void CreateChild(); + } + + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/csla.netcore.test/DataPortal/InheritedOperationDispatchTests.cs b/Source/tests/csla.netcore.test/DataPortal/InheritedOperationDispatchTests.cs index 8c447b8687..d081f39888 100644 --- a/Source/tests/csla.netcore.test/DataPortal/InheritedOperationDispatchTests.cs +++ b/Source/tests/csla.netcore.test/DataPortal/InheritedOperationDispatchTests.cs @@ -188,5 +188,15 @@ public partial class InheritedOpsChild : InheritedOpsChildBase LoadProperty(NameProperty, name); } - public class InheritedOpsChildList : BusinessListBase; + // Declares an operation of its own, so it has a generated mapping that + // must dispatch the inherited Child_Create and Child_UpdateAsync. + public partial class InheritedOpsChildList : BusinessListBase + { + [FetchChild] + private void FetchChild(string[] names, [Inject] IChildDataPortal childPortal) + { + foreach (var name in names) + Add(childPortal.FetchChild(name)); + } + } } diff --git a/docs/data-portal-operations-generator.md b/docs/data-portal-operations-generator.md index af130be0b7..32f3aa72e4 100644 --- a/docs/data-portal-operations-generator.md +++ b/docs/data-portal-operations-generator.md @@ -69,7 +69,7 @@ public partial class Customer : AppBase } ``` -The generated code for `Customer` calls `Create`, `InsertChild` and `Update` directly, along with operation methods inherited from CSLA's base classes, such as `BusinessBase.Child_Create`. It chooses between methods the same way reflection-based dispatch does: +The generated code for `Customer` calls `Create`, `InsertChild` and `Update` directly, along with operation methods inherited from CSLA's base classes, such as `BusinessBase.Child_Create` and the `Child_UpdateAsync(params object[])` method of the editable list base classes. It chooses between methods the same way reflection-based dispatch does: * Private methods of a base class are not included. * A method declared closer to the class is preferred over one declared further up the inheritance chain. @@ -80,9 +80,13 @@ In a few cases the generated code leaves an inherited method to reflection-based * An intermediate base class declares another member with the same name, which would hide the method from the generated code. * A method closer to the class takes the same number of criteria, and a less specific parameter type, such as `object`, means reflection could choose that closer method instead. +* The criteria also match a method further up the inheritance chain, and do not exactly match the types of a closer method with a less specific parameter type. * The method is internal to another assembly. +* The method takes or returns a protected or private nested type, which the generated internal interface cannot name. The same applies to an operation method the class declares. -Extension methods from the [data portal extensions generator](data-portal-extensions-generator.md) and the CSLADP002 and CSLADP009 analyzers cover only the operation methods a class declares. +When a method the class declares and an inherited method map to the same operation, analyzers CSLADP002 and CSLADP009 report it at the declared method. If they tie, the data portal reports an ambiguous match, as reflection-based dispatch does. + +Extension methods from the [data portal extensions generator](data-portal-extensions-generator.md) cover only the operation methods a class declares. An override of an inherited operation method is not a declared operation method, even though the data portal calls it. ## Operation methods that share a name diff --git a/releasenotes.md b/releasenotes.md index 1df73ba8aa..92d6f2c618 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -130,7 +130,7 @@ The new `Csla.Mvvm.ViewModel` in the `Csla` package has the view model behavi * [#4996](https://github.com/MarimerLLC/csla/issues/4996) A create or fetch with a single `null` criteria value works with a remote data portal; the `NullCriteria` constructor is now public so the server can deserialize it ([#4997](https://github.com/MarimerLLC/csla/pull/4997)) * [#5024](https://github.com/MarimerLLC/csla/issues/5024) `[CslaImplementPropertiesInterface]` generates properties when the attribute name is namespace-qualified (`Csla.`, `global::Csla.`) or aliased; before, it generated an empty class. The interface can be declared in a different file from the class; before, that made the generator fail. When the attribute isn't on a partial class or struct, or `T` isn't an interface declared in the same project, nothing is generated and the new analyzer CSLA0030 reports it. Attributes on the interface's properties are copied with their type and the names in their arguments fully qualified, so namespace-qualified, aliased, nested and generic attribute types and arguments such as `typeof(Strings)` that rely on the interface file's `using` directives work; before, a namespace-qualified attribute was emitted with its namespace twice ([#5026](https://github.com/MarimerLLC/csla/pull/5026)) * [#4970](https://github.com/MarimerLLC/csla/issues/4970) `Csla.Maui` no longer causes an `IL2112` trim warning in apps that use `csla:PropertyInfo` ([#4973](https://github.com/MarimerLLC/csla/pull/4973)) -* [#5046](https://github.com/MarimerLLC/csla/issues/5046) The generated data portal dispatch of a concrete class also calls the operation methods it inherits from base classes, including `BusinessBase.Child_Create`. Before, calling an inherited operation threw `DataPortalOperationNotSupportedException` from the generated code (caught by the data portal, which then used reflection), so the debugger could break on nearly every data portal call in a project that keeps its operations on a base class ([#5048](https://github.com/MarimerLLC/csla/pull/5048)) +* [#5046](https://github.com/MarimerLLC/csla/issues/5046) The generated data portal dispatch of a concrete class also calls the operation methods it inherits from base classes, including `BusinessBase.Child_Create` and the editable lists' `Child_UpdateAsync`. Before, calling an inherited operation threw `DataPortalOperationNotSupportedException` from the generated code (caught by the data portal, which then used reflection), so the debugger could break on nearly every data portal call in a project that keeps its operations on a base class. CSLADP002 and CSLADP009 also report a declared method that shares an operation with an inherited one. An operation method taking a private or protected nested type no longer makes the generated code fail to compile (CS0051); it is called through reflection ([#5048](https://github.com/MarimerLLC/csla/pull/5048)) **Security** From 50aa10657425433ff32243785c08fc5081dcd553 Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Fri, 20 Nov 2026 15:42:23 -0600 Subject: [PATCH 4/4] #5046 Score competing operation methods like reflection Addresses PR review: - Inherited methods the generated code cannot call (hidden by an intermediate member, inaccessible, or with types the interface cannot name) stay in the model, marked CanCall = false, so they compete when generated dispatch picks a method, instead of only marking the kind unresolved. Kinds that remain unresolved (generic methods, and declared methods marked with a subclass of an operation attribute) get no generated dispatch at all. - Criteria dispatch compares, for every other method of the kind with the same criteria count, the lowest score the method can have with the highest score the other can have, using reflection's scoring (exact 3, assignable 2, object 1, minus inheritance depth, plus injected parameters). The method is guarded against criteria that match the other whenever the other could tie or win, or left to reflection when the generated code cannot test the other's types. This replaces the same-level exact-type rule and the closer-method rule, and accounts for injected parameters across levels. - Parameter models record a type category and assignable types, so guards between types that no value can match both (int vs a class, int[] vs List) are omitted. Variant generic types and reference arrays are treated as possibly overlapping. - A subclass of an operation attribute counts as that attribute for inherited methods, as GetCustomAttributes(true) does at runtime. Co-Authored-By: Claude Opus 5.5 --- .../DataPortalOperationsBuilder.cs | 211 ++++++++++++++---- .../Models/OperationMethodModel.cs | 17 +- .../Models/OperationParameterModel.cs | 29 +++ .../OperationDiscovery.cs | 132 ++++++++--- .../DataPortalOperationsGeneratorTests.cs | 100 +++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 4 +- ...sonEdit.DataPortalOperations.g.verified.cs | 6 +- ...sonEdit.DataPortalOperations.g.verified.cs | 70 ++++++ ...ookup_1.DataPortalOperations.g.verified.cs | 4 +- ...sonEdit.DataPortalOperations.g.verified.cs | 101 +++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 154 +++++++++++++ ...sonEdit.DataPortalOperations.g.verified.cs | 2 + ...sonEdit.DataPortalOperations.g.verified.cs | 12 + ...sonEdit.DataPortalOperations.g.verified.cs | 33 ++- docs/data-portal-operations-generator.md | 15 +- 15 files changed, 797 insertions(+), 93 deletions(-) create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DeclaredDerivedOperationAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedDerivedOperationAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs create mode 100644 Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedInjectionScoring#TestApp.PersonEdit.DataPortalOperations.g.verified.cs diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs index 287cf2f8a3..621a1a2469 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/DataPortalOperationsBuilder.cs @@ -150,7 +150,7 @@ public static HashSet GetExcludedFromDispatch(List private static IEnumerable InterfaceMethods(OperationTypeModel model) - => model.Methods.Where(m => m.CanNameSignature); + => model.Methods.Where(m => m.CanCall); private static Dictionary GetInterfaceMemberNames(IEnumerable methods) { @@ -210,50 +210,31 @@ private static void AppendInvokeOperationAsync(IndentedTextWriter writer, Operat // only the one the runtime would select takes part in dispatch. var (_, collisions) = SelectNamedDispatchMethods(model.Methods); var excluded = GetExcludedFromDispatch(collisions); - var dispatchable = model.Methods.Where(m => m.CanDispatch && m.CanNameSignature && !excluded.Contains(m)).ToList(); + var dispatchable = model.Methods.Where(m => m.CanDispatch && m.CanCall && !excluded.Contains(m)).ToList(); var byKind = new List<(string Kind, List Methods)>(); foreach (var kind in OperationDiscovery.OperationKinds) { + // Reflection-based dispatch may see a method of this kind that the + // generator does not model, so the call is left to it. + if (model.UnresolvedKinds.Contains(kind)) + continue; + // Every method of the kind competes in reflection-based dispatch, // including those left out of generated dispatch. var all = model.Methods.Where(m => m.Kind == kind).ToList(); - var ofKind = dispatchable.Where(m => m.Kind == kind).ToList(); var methods = new List(); - foreach (var method in ofKind) + foreach (var method in dispatchable.Where(m => m.Kind == kind)) { - var sameShape = all.Where(m => m.CriteriaCount == method.CriteriaCount).ToList(); - - // Reflection-based dispatch scores a method lower for each level of - // inheritance. An inherited method is dispatched only when every - // method closer to the type with that criteria count takes criteria - // that match exact types only (value types and sealed types), which - // a less specific match cannot outscore; otherwise the call is left - // to reflection. - if (!sameShape.Where(m => m.InheritanceDepth < method.InheritanceDepth).All(HasExactCriteriaTypes)) - continue; - - // When several methods at one level take the same number of - // criteria, require exact runtime types so a less specific overload - // cannot capture the call. - var requireExactTypes = ofKind.Count(m => m.CriteriaCount == method.CriteriaCount && m.InheritanceDepth == method.InheritanceDepth) > 1; - - // A method with less specific criteria types leaves the call to - // reflection when the criteria also match a method further up the - // inheritance chain, unless they match its own types exactly. - var guards = requireExactTypes || HasExactCriteriaTypes(method) - ? [] - : sameShape.Where(m => m.InheritanceDepth > method.InheritanceDepth && !HasSameCriteriaTypes(m, method)).ToList(); - - methods.Add(new CriteriaDispatch(method, requireExactTypes, guards)); + if (PlanCriteriaDispatch(method, all) is { } dispatch) + methods.Add(dispatch); } // A method taking the whole criteria array as params object[] is // called by reflection-based dispatch when no other method matches; // it is dispatched only when it is the only method of its kind. - if (all.Count == 1 && all[0].TakesCriteriaArray && all[0].Parameters[0].IsParams - && all[0].CanNameSignature && !model.UnresolvedKinds.Contains(kind)) - methods.Add(new CriteriaDispatch(all[0], RequireExactTypes: false, [])); + if (all.Count == 1 && all[0].TakesCriteriaArray && all[0].Parameters[0].IsParams && all[0].CanCall) + methods.Add(new CriteriaDispatch(all[0], RequireExactTypes: false, [], [])); if (methods.Count > 0) byKind.Add((kind, methods)); @@ -270,7 +251,7 @@ private static void AppendInvokeOperationAsync(IndentedTextWriter writer, Operat isFirst = false; OpenBlock(writer); foreach (var dispatch in methods) - AppendDispatch(writer, dispatch.Method, memberNames[dispatch.Method], candidateIndex++, byName: false, dispatch.RequireExactTypes, dispatch.Guards); + AppendDispatch(writer, dispatch.Method, memberNames[dispatch.Method], candidateIndex++, byName: false, dispatch.RequireExactTypes, dispatch.Excluding, dispatch.ExcludingUnlessExact); CloseBlock(writer); } @@ -279,14 +260,139 @@ private static void AppendInvokeOperationAsync(IndentedTextWriter writer, Operat } /// - /// A method in criteria-based dispatch. are methods - /// further up the inheritance chain whose criteria types, when matched, - /// leave the call to reflection-based dispatch. + /// A method in criteria-based dispatch. The call is left to + /// reflection-based dispatch when the criteria match a method in + /// , or match a method in + /// without matching this method's + /// criteria types exactly. + /// + private sealed record CriteriaDispatch(OperationMethodModel Method, bool RequireExactTypes, + IReadOnlyList Excluding, IReadOnlyList ExcludingUnlessExact); + + /// + /// Decides when generated dispatch can call a method for the criteria + /// it matches, or returns null to leave every call to reflection. + /// Reflection-based dispatch scores each method that matches the + /// criteria: per criteria value 3 for an exact type, 2 for an assignable + /// type and 1 for object, less one per level of inheritance, plus one + /// per injected parameter when more than one method matches; the highest + /// score wins and a tie is ambiguous. For every other method of the kind + /// with the same criteria count, this compares the lowest score the + /// method can have with the highest the other can have, and keeps the + /// generated code from calling the method whenever the other could tie + /// or win. + /// + private static CriteriaDispatch? PlanCriteriaDispatch(OperationMethodModel method, List all) + { + var methodMin = MinScore(method); + var methodExact = ExactScore(method); + var requireExactTypes = false; + var excluding = new List(); + var excludingUnlessExact = new List(); + + foreach (var other in all) + { + // Methods with the same criteria types share an operation name and + // are chosen by SelectNamedDispatchMethods. Reflection never matches + // criteria to ref, out or in parameters. + if (ReferenceEquals(other, method) || other.CriteriaCount != method.CriteriaCount + || HasSameCriteriaTypes(other, method) || AreDisjoint(other, method) + || other.CriteriaParameters.Any(p => p.RefKindPrefix.Length > 0)) + continue; + + var otherMax = MaxScore(other, method); + if (otherMax < methodMin) + continue; + + if (!other.CanNameCriteriaTypes) + { + // The generated code cannot test for the other method's types. + if (otherMax >= methodExact) + return null; + requireExactTypes = true; + } + else if (otherMax >= methodExact) + { + // When every value this method accepts also matches the other + // method, the call is always left to reflection. + if (Covers(other, method)) + return null; + excluding.Add(other); + } + else + { + excludingUnlessExact.Add(other); + } + } + + return new CriteriaDispatch(method, requireExactTypes, excluding, requireExactTypes ? [] : excludingUnlessExact); + } + + private static int MinScore(OperationMethodModel method) + => method.CriteriaParameters.Sum(p => p.IsNullableValueType ? 2 : p.IsExactTypeMatch ? 3 : IsObject(p) ? 1 : 2) + - method.InheritanceDepth + method.InjectCount; + + private static int ExactScore(OperationMethodModel method) + => method.CriteriaParameters.Sum(p => p.IsNullableValueType ? 2 : 3) + - method.InheritanceDepth + method.InjectCount; + + /// + /// The highest score of another method for criteria that match the method. + /// + private static int MaxScore(OperationMethodModel other, OperationMethodModel method) + => other.CriteriaParameters.Zip(method.CriteriaParameters, (o, m) => + o.IsNullableValueType ? 2 : IsObject(o) && !IsObject(m) ? 1 : 3).Sum() + - other.InheritanceDepth + other.InjectCount; + + /// + /// Every value matching the criteria types of the method also matches + /// those of the other method. /// - private sealed record CriteriaDispatch(OperationMethodModel Method, bool RequireExactTypes, IReadOnlyList Guards); + private static bool Covers(OperationMethodModel other, OperationMethodModel method) + => other.CriteriaParameters.Zip(method.CriteriaParameters, (o, m) => + IsObject(o) || o.PatternTypeDisplay == m.PatternTypeDisplay || m.AssignableTo.Contains(o.PatternTypeDisplay)).All(c => c); - private static bool HasExactCriteriaTypes(OperationMethodModel method) - => method.CriteriaParameters.All(p => p.IsExactTypeMatch); + /// + /// No criteria can match both methods: at some position no value can + /// match both parameter types. + /// + private static bool AreDisjoint(OperationMethodModel other, OperationMethodModel method) + => other.CriteriaParameters.Zip(method.CriteriaParameters, CanOverlap).Any(overlap => !overlap); + + /// + /// Some value can match both parameter types. A boxed int matches both + /// int and int?, so the pattern types are compared, without nullability. + /// + private static bool CanOverlap(OperationParameterModel left, OperationParameterModel right) + { + if (left.PatternTypeDisplay == right.PatternTypeDisplay) + return true; + if (left.Category is CriteriaTypeCategory.Unknown or CriteriaTypeCategory.TypeParameter + || right.Category is CriteriaTypeCategory.Unknown or CriteriaTypeCategory.TypeParameter) + return true; + + // Array covariance lets a string[] match object[], but only arrays of + // reference types are covariant. + if (left.Category == CriteriaTypeCategory.Array && right.Category == CriteriaTypeCategory.Array) + return !left.HasValueTypeElements && !right.HasValueTypeElements; + + if (left.Category == CriteriaTypeCategory.Interface || right.Category == CriteriaTypeCategory.Interface) + { + if (left.Category == right.Category) + return true; + var (type, @interface) = left.Category == CriteriaTypeCategory.Interface ? (right, left) : (left, right); + // A subclass of a class can implement any interface, and array + // covariance makes a string[] an IList. + return type.Category == CriteriaTypeCategory.Class + || (type.Category == CriteriaTypeCategory.Array && !type.HasValueTypeElements) + || type.AssignableTo.Contains(@interface.PatternTypeDisplay); + } + + // Classes, arrays and sealed types overlap only through inheritance. + return left.AssignableTo.Contains(right.PatternTypeDisplay) || right.AssignableTo.Contains(left.PatternTypeDisplay); + } + + private static bool IsObject(OperationParameterModel parameter) => parameter.PatternTypeDisplay == "object"; private static bool HasSameCriteriaTypes(OperationMethodModel left, OperationMethodModel right) => left.CriteriaParameters.Select(CriteriaTypeKey).SequenceEqual(right.CriteriaParameters.Select(CriteriaTypeKey)); @@ -302,8 +408,11 @@ private static void AppendInvokeNamedOperationAsync(IndentedTextWriter writer, O writer.Indent--; OpenBlock(writer); - // A selected method the interface cannot name is left to reflection. - var selected = SelectNamedDispatchMethods(model.Methods).Selected.Where(m => m.CanNameSignature).ToList(); + // A selected method the generated code cannot call, or of a kind with + // methods the generator does not model, is left to reflection. + var selected = SelectNamedDispatchMethods(model.Methods).Selected + .Where(m => m.CanCall && !model.UnresolvedKinds.Contains(m.Kind)) + .ToList(); if (selected.Count > 0) { writer.WriteLine($"var {OperationsLocal} = ({OperationDiscovery.OperationsInterfaceName})this;"); @@ -326,7 +435,7 @@ private static void AppendInvokeNamedOperationAsync(IndentedTextWriter writer, O } private static void AppendDispatch(IndentedTextWriter writer, OperationMethodModel method, string memberName, int candidateIndex, bool byName, bool requireExactTypes, - IReadOnlyList? guards = null) + IReadOnlyList? excluding = null, IReadOnlyList? excludingUnlessExact = null) { var criteria = method.CriteriaParameters.ToList(); var conditions = new List(); @@ -357,17 +466,19 @@ private static void AppendDispatch(IndentedTextWriter writer, OperationMethodMod } } - if (guards is { Count: > 0 }) + // Leave the call to reflection when another method could tie or + // outscore this one for these criteria. + foreach (var other in excluding ?? []) + conditions.Add($"!({MatchCondition(other)})"); + + if (excludingUnlessExact is { Count: > 0 }) { var exactMatch = string.Join(" && ", criteria .Select((p, i) => (Parameter: p, Index: i)) .Where(c => !c.Parameter.IsExactTypeMatch) .Select(c => $"{CriteriaVariable(candidateIndex, c.Index)}.GetType() == typeof({c.Parameter.PatternTypeDisplay})")); - foreach (var guard in guards) - { - var guardMatch = string.Join(" && ", guard.CriteriaParameters.Select((p, i) => $"criteria[{i}] is {p.PatternTypeDisplay}")); - conditions.Add($"!({guardMatch} && !({exactMatch}))"); - } + foreach (var other in excludingUnlessExact) + conditions.Add($"!({MatchCondition(other)} && !({exactMatch}))"); } } @@ -439,6 +550,12 @@ private static void AppendDispatch(IndentedTextWriter writer, OperationMethodMod CloseBlock(writer); } + /// + /// The criteria values match the criteria parameter types of a method. + /// + private static string MatchCondition(OperationMethodModel method) + => string.Join(" && ", method.CriteriaParameters.Select((p, i) => $"criteria[{i}] is {p.PatternTypeDisplay}")); + private static string FormatServiceResolution(OperationParameterModel parameter) { // Nullable services are registered and resolved as Nullable, as in reflection-based dispatch. diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs index f3bce6de45..37af826fa6 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationMethodModel.cs @@ -92,12 +92,21 @@ internal sealed record OperationMethodModel && !TakesCriteriaArray; /// - /// The parameter and return types can be used in the type's internal + /// The generated code can call the method through the type's internal /// IDataPortalOperations interface. A method taking a private or - /// protected nested type is left out of the interface and of generated - /// dispatch, and is called through reflection. + /// protected nested type cannot be named by the interface, and an + /// inherited method may be inaccessible or hidden by another member of + /// the same name. Such a method is left out of the interface and of + /// generated dispatch, and is called through reflection, but it still + /// competes with the other methods when generated dispatch selects one. /// - public bool CanNameSignature { get; init; } = true; + public bool CanCall { get; init; } = true; + + /// + /// The generated code can name the criteria parameter types, for type + /// checks that keep another method from capturing a call. + /// + public bool CanNameCriteriaTypes { get; init; } = true; /// /// The method can take part in name-based dispatch. When criteria diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationParameterModel.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationParameterModel.cs index 5bbc6fef40..444bbe2ccc 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationParameterModel.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/Models/OperationParameterModel.cs @@ -19,6 +19,23 @@ internal enum TypeVisibility Private } + /// + /// The kind of a parameter type, used to decide whether one criteria value + /// can match two parameter types. + /// + internal enum CriteriaTypeCategory + { + /// object, dynamic, or a type the generator cannot reason about. + Unknown, + TypeParameter, + Interface, + Array, + /// A value type or a sealed class. + Sealed, + /// A class that can have subclasses. + Class + } + /// /// A parameter of a data portal operation method. /// @@ -71,5 +88,17 @@ internal sealed record OperationParameterModel public string? DefaultValueExpression { get; init; } public TypeVisibility Visibility { get; init; } + + /// The kind of the pattern type. + public CriteriaTypeCategory Category { get; init; } + + /// + /// The pattern types of the base classes and interfaces of the pattern + /// type, which a value of this type also matches. + /// + public EquatableArray AssignableTo { get; init; } + + /// For an array, its element type is a value type. + public bool HasValueTypeElements { get; init; } } } diff --git a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs index c94e833304..f6dd3ada86 100644 --- a/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs +++ b/Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/DataPortalOperations/OperationDiscovery.cs @@ -240,11 +240,17 @@ public static OperationTypeModel AddInheritedMethods(OperationTypeModel model, I var unresolved = new List(); var inherited = GetInheritedMethods(type, compilation, unresolved); - // Reflection-based dispatch also sees generic operation methods the type declares. + // Reflection-based dispatch also sees operation methods the type + // declares that the generator does not model: generic methods, and + // methods marked with a subclass of an operation attribute. foreach (var method in type.GetMembers().OfType()) { - if (method.MethodKind == MethodKind.Ordinary && !method.IsStatic && method.IsGenericMethod) + if (method.MethodKind != MethodKind.Ordinary || method.IsStatic) + continue; + if (method.IsGenericMethod) unresolved.AddRange(GetOperationKinds(method)); + else + unresolved.AddRange(GetDerivedOperationAttributeKinds(method)); } if (inherited.Count == 0 && unresolved.Count == 0) @@ -258,15 +264,17 @@ public static OperationTypeModel AddInheritedMethods(OperationTypeModel model, I } /// - /// The operation methods a concrete type inherits that its generated - /// dispatch can call, nearest base type first. Like reflection-based - /// dispatch, private base methods are not included, and a virtual - /// method overridden without an operation attribute is treated as - /// declared at the level of its most derived override, because the - /// attribute is inherited. A method is left to reflection-based dispatch - /// when the generated code could not call it without binding to another - /// method of the same name, or could not name its parameter or return - /// types; the kinds of such methods are added to . + /// The operation methods a concrete type inherits, nearest base type + /// first. Like reflection-based dispatch, private base methods are not + /// included, and a virtual method overridden without an operation + /// attribute is treated as declared at the level of its most derived + /// override, because the attribute is inherited. A method the generated + /// code cannot call (it would bind to another method of the same name, + /// it is not accessible, or the interface cannot name its types) is + /// still included with false, + /// because it competes in reflection-based dispatch. The kinds of + /// generic methods, which cannot be modeled, are added to + /// . /// private static List GetInheritedMethods(INamedTypeSymbol type, Compilation compilation, List unresolvedKinds) { @@ -294,19 +302,31 @@ private static List GetInheritedMethods(INamedTypeSymbol t if (kinds.Count == 0) continue; - if (!IsCandidateMethod(method) - || method.Parameters.Any(p => p.RefKind is RefKind.Ref or RefKind.Out) - || !compilation.IsSymbolAccessibleWithin(method, type, type) - || !CanNameSignature(method) - || !TryGetCallForm(chain, method, out var callThroughBase)) + if (!IsCandidateMethod(method)) { unresolvedKinds.AddRange(kinds); continue; } + var canCall = compilation.IsSymbolAccessibleWithin(method, type, type) + & CanNameSignature(method) + & TryGetCallForm(chain, method, out var callThroughBase); + var canNameCriteriaTypes = method.Parameters + .Where(p => !IsInjected(p)) + .All(p => compilation.IsSymbolAccessibleWithin(p.Type, type)); + var depth = overrides.Count > 0 ? overrides.Min(o => o.Depth) : chain.Count; foreach (var kind in kinds) - result.Add(BuildMethod(method, kind) with { InheritanceDepth = depth, CallThroughBase = callThroughBase, IsInherited = true }); + { + result.Add(BuildMethod(method, kind) with + { + InheritanceDepth = depth, + CallThroughBase = callThroughBase, + IsInherited = true, + CanCall = canCall, + CanNameCriteriaTypes = canNameCriteriaTypes + }); + } } chain.Add(baseType); } @@ -384,24 +404,53 @@ private static bool TryGetCallForm(List chain, IMethodSymbol m } /// - /// The operation kinds of the operation attributes on a method, in attribute order. + /// The operation kinds of the operation attributes on a method, in + /// attribute order. Like reflection-based dispatch, a subclass of an + /// operation attribute counts as that attribute. /// private static List GetOperationKinds(IMethodSymbol method) { var result = new List(); foreach (var attribute in method.GetAttributes()) { - if (IsOperationAttribute(attribute.AttributeClass)) - { - var name = attribute.AttributeClass!.Name; - var kind = name.Substring(0, name.Length - "Attribute".Length); - if (!result.Contains(kind)) - result.Add(kind); - } + if (GetOperationKind(attribute.AttributeClass) is { } kind && !result.Contains(kind)) + result.Add(kind); + } + return result; + } + + /// + /// The operation kinds a method has only through subclasses of operation + /// attributes. The generator discovers the methods a type declares by the + /// exact attribute, so it does not model these methods. + /// + private static List GetDerivedOperationAttributeKinds(IMethodSymbol method) + { + var result = new List(); + foreach (var attribute in method.GetAttributes()) + { + if (!IsOperationAttribute(attribute.AttributeClass) && GetOperationKind(attribute.AttributeClass) is { } kind && !result.Contains(kind)) + result.Add(kind); } return result; } + /// + /// The operation kind of an operation attribute or of a subclass of one, or null. + /// + private static string? GetOperationKind(INamedTypeSymbol? attributeClass) + { + for (var current = attributeClass; current is not null; current = current.BaseType) + { + if (IsOperationAttribute(current)) + return current.Name.Substring(0, current.Name.Length - "Attribute".Length); + } + return null; + } + + private static bool IsInjected(IParameterSymbol parameter) + => parameter.GetAttributes().Any(a => IsOrDerivesFrom(a.AttributeClass, InjectAttributeName)); + /// /// The Prefix set by a DataPortalExtensions attribute, or null when it is not set. /// @@ -434,7 +483,7 @@ private static OperationMethodModel BuildMethod(IMethodSymbol method, string kin OperationName = operationName, RunLocal = HasAttribute(method, RunLocalAttributeName), NoExtension = HasAttribute(method, NoDataPortalExtensionAttributeName), - CanNameSignature = CanNameSignature(method), + CanCall = CanNameSignature(method), Location = LocationInfo.From(method.Locations.FirstOrDefault()) }; } @@ -489,10 +538,39 @@ private static OperationParameterModel BuildParameter(IParameterSymbol parameter AllowNull = allowNull, ServiceKeyExpression = serviceKey, DefaultValueExpression = parameter.HasExplicitDefaultValue ? FormatDefaultValue(type, parameter.ExplicitDefaultValue) : null, - Visibility = GetVisibility(type) + Visibility = GetVisibility(type), + Category = GetCriteriaTypeCategory(patternType), + AssignableTo = new EquatableArray(GetAssignableTypes(patternType)), + HasValueTypeElements = patternType is IArrayTypeSymbol { ElementType.IsValueType: true } }; } + private static CriteriaTypeCategory GetCriteriaTypeCategory(ITypeSymbol type) => type switch + { + { SpecialType: SpecialType.System_Object } => CriteriaTypeCategory.Unknown, + { TypeKind: TypeKind.Dynamic } => CriteriaTypeCategory.Unknown, + // Variance (IEnumerable, Func) lets a value match + // types that are not among its declared base types and interfaces. + INamedTypeSymbol { IsGenericType: true } named when named.OriginalDefinition.TypeParameters.Any(t => t.Variance != VarianceKind.None) + => CriteriaTypeCategory.Unknown, + ITypeParameterSymbol => CriteriaTypeCategory.TypeParameter, + IArrayTypeSymbol => CriteriaTypeCategory.Array, + { TypeKind: TypeKind.Interface } => CriteriaTypeCategory.Interface, + { IsValueType: true } => CriteriaTypeCategory.Sealed, + { TypeKind: TypeKind.Class, IsSealed: true } => CriteriaTypeCategory.Sealed, + { TypeKind: TypeKind.Class } => CriteriaTypeCategory.Class, + _ => CriteriaTypeCategory.Unknown + }; + + private static IEnumerable GetAssignableTypes(ITypeSymbol type) + { + var result = new List(); + for (var baseType = type.BaseType; baseType is not null; baseType = baseType.BaseType) + result.Add(baseType.ToDisplayString(PatternFormat)); + result.AddRange(type.AllInterfaces.Select(i => i.ToDisplayString(PatternFormat))); + return result.Distinct().OrderBy(n => n, StringComparer.Ordinal); + } + /// /// Computes a deterministic type key for use in operation names. /// Must produce the same result as DataPortalOperationNameHelper.GetTypeKey(Type) at runtime. diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs index 2277ecbf41..0d52919171 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/DataPortalOperationsGeneratorTests.cs @@ -512,6 +512,10 @@ public abstract class PersonBase : Csla.BusinessBase [Fetch] protected void Fetch(int id) { } + // Ties with the hidden Fetch(int), so reflection reports an ambiguous match. + [Fetch] + protected void Load(int id) { } + [Delete] protected void Delete(int id) { } } @@ -668,6 +672,102 @@ private class Criteria { } [Fetch] private void Fetch(Criteria criteria) { } + + // Must not capture a Criteria value, which reflection gives to Fetch(Criteria). + [Fetch] + private void Fetch(object value) { } + } + } + """; + + await TestHelperVerify(source); + } + + [TestMethod("Injected parameters of a method further up the chain can outscore a closer method")] + public async Task InheritedInjectionScoring() + { + var source = """ + using Csla; + + namespace TestApp + { + public interface IA { } + public interface IB { } + public interface IC { } + public interface ID { } + + public abstract class PersonBase : Csla.BusinessBase + where T : PersonBase + { + [Fetch] + protected void Load(object value, [Inject] IA a, [Inject] IB b, [Inject] IC c, [Inject] ID d) { } + } + + public abstract class PersonMiddle : PersonBase + where T : PersonMiddle + { + // For an int, reflection scores this 3 - 1 = 2 and Load 1 - 2 + 4 = 3. + [Fetch] + protected void Fetch(int id) { } + } + + public partial class PersonEdit : PersonMiddle + { + [Create] + private void Create() { } + } + } + """; + + await TestHelperVerify(source); + } + + [TestMethod("Inherited method marked with a subclass of an operation attribute is dispatched")] + public async Task InheritedDerivedOperationAttribute() + { + var source = """ + using Csla; + + namespace TestApp + { + public class InitializeChildAttribute : CreateChildAttribute { } + + public abstract class PersonBase : Csla.BusinessBase + where T : PersonBase + { + // Closer than BusinessBase.Child_Create, so reflection calls this. + [InitializeChild] + protected void Initialize() { } + } + + public partial class PersonEdit : PersonBase + { + [Fetch] + private void Fetch(int id) { } + } + } + """; + + await TestHelperVerify(source); + } + + [TestMethod("Declared method marked with a subclass of an operation attribute leaves its kind to reflection")] + public async Task DeclaredDerivedOperationAttribute() + { + var source = """ + using Csla; + + namespace TestApp + { + public class InitializeChildAttribute : CreateChildAttribute { } + + public partial class PersonEdit : Csla.BusinessBase + { + [InitializeChild] + private void Initialize() { } + + [Fetch] + private void Fetch(int id) { } } } """; diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 8a6aba0985..a9e74a15db 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.AmbiguousOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -31,7 +31,7 @@ internal interface IDataPortalOperations var __operations = (IDataPortalOperations)this; if (operationType == typeof(global::Csla.FetchAttribute)) { - if (criteria is { Length: 1 } && criteria[0] is object __c0p0 && __c0p0.GetType() == typeof(object)) + if (criteria is { Length: 1 } && criteria[0] is object __c0p0 && !(criteria[0] is global::TestApp.Criteria) && !(criteria[0] is int)) { try { @@ -43,7 +43,7 @@ internal interface IDataPortalOperations } return; } - if (criteria is { Length: 1 } && criteria[0] is global::TestApp.Criteria __c1p0 && __c1p0.GetType() == typeof(global::TestApp.Criteria)) + if (criteria is { Length: 1 } && criteria[0] is global::TestApp.Criteria __c1p0) { try { diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ArrayNullableGenericCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ArrayNullableGenericCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 9b924a9e2d..cf69a34657 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ArrayNullableGenericCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.ArrayNullableGenericCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -35,7 +35,7 @@ internal interface IDataPortalOperations var __operations = (IDataPortalOperations)this; if (operationType == typeof(global::Csla.FetchAttribute)) { - if (criteria is { Length: 1 } && criteria[0] is int[] __c0p0 && __c0p0.GetType() == typeof(int[])) + if (criteria is { Length: 1 } && criteria[0] is int[] __c0p0) { try { @@ -59,7 +59,7 @@ internal interface IDataPortalOperations } return; } - if (criteria is { Length: 1 } && criteria[0] is global::System.Collections.Generic.List __c2p0 && __c2p0.GetType() == typeof(global::System.Collections.Generic.List)) + if (criteria is { Length: 1 } && criteria[0] is global::System.Collections.Generic.List __c2p0) { try { @@ -83,7 +83,7 @@ internal interface IDataPortalOperations } return; } - if (criteria is { Length: 1 } && criteria[0] is global::System.Collections.Generic.Dictionary>[] __c4p0 && __c4p0.GetType() == typeof(global::System.Collections.Generic.Dictionary>[])) + if (criteria is { Length: 1 } && criteria[0] is global::System.Collections.Generic.Dictionary>[] __c4p0) { try { diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DeclaredDerivedOperationAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DeclaredDerivedOperationAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..b4290a0535 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.DeclaredDerivedOperationAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -0,0 +1,70 @@ +//HintName: TestApp.PersonEdit.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void Fetch__Int32(int id); + void CreateChild(); + } + + void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.FetchAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is int __c0p0) + { + try + { + __operations.Fetch__Int32(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "Fetch__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c0p0) + { + try + { + __operations.Fetch__Int32(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.GenericBusinessObject#TestApp.Lookup_1.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.GenericBusinessObject#TestApp.Lookup_1.DataPortalOperations.g.verified.cs index 19ebfa717c..609bf5e154 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.GenericBusinessObject#TestApp.Lookup_1.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.GenericBusinessObject#TestApp.Lookup_1.DataPortalOperations.g.verified.cs @@ -27,7 +27,7 @@ internal interface IDataPortalOperations var __operations = (IDataPortalOperations)this; if (operationType == typeof(global::Csla.FetchAttribute)) { - if (criteria is { Length: 1 } && criteria[0] is TKey __c0p0 && __c0p0.GetType() == typeof(TKey)) + if (criteria is { Length: 1 } && criteria[0] is TKey __c0p0 && !(criteria[0] is int)) { try { @@ -39,7 +39,7 @@ internal interface IDataPortalOperations } return; } - if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + if (criteria is { Length: 1 } && criteria[0] is int __c1p0 && !(criteria[0] is TKey)) { try { diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedDerivedOperationAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedDerivedOperationAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..33d58e4ce3 --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedDerivedOperationAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -0,0 +1,101 @@ +//HintName: TestApp.PersonEdit.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void Fetch__Int32(int id); + void CreateChild(); + void CreateChild_2(); + } + + void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.CreateChild() => Initialize(); + void IDataPortalOperations.CreateChild_2() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.FetchAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is int __c0p0) + { + try + { + __operations.Fetch__Int32(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Initialize", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "Fetch__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c0p0) + { + try + { + __operations.Fetch__Int32(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Initialize", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedInjectionScoring#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedInjectionScoring#TestApp.PersonEdit.DataPortalOperations.g.verified.cs new file mode 100644 index 0000000000..f37e2af9ce --- /dev/null +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedInjectionScoring#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -0,0 +1,154 @@ +//HintName: TestApp.PersonEdit.DataPortalOperations.g.cs +// +#nullable enable +#pragma warning disable CS1998 // Async method lacks 'await' operators + +namespace TestApp +{ + partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, global::Csla.Server.IDataPortalOperationMapping, global::Csla.Server.IDataPortalOperationNamedMapping + { + /// + /// Data portal operation methods declared or inherited by this type. + /// Generated by CSLA .NET so the methods are statically referenced. + /// + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal interface IDataPortalOperations + { + void Create(); + void Fetch__Int32(int id); + void Fetch__Object(object value, global::TestApp.IA a, global::TestApp.IB b, global::TestApp.IC c, global::TestApp.ID d); + void CreateChild(); + } + + void IDataPortalOperations.Create() => Create(); + void IDataPortalOperations.Fetch__Int32(int id) => Fetch(id); + void IDataPortalOperations.Fetch__Object(object value, global::TestApp.IA a, global::TestApp.IB b, global::TestApp.IC c, global::TestApp.ID d) => Load(value, a, b, c, d); + void IDataPortalOperations.CreateChild() => Child_Create(); + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( + global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + if (operationType == typeof(global::Csla.CreateAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.Create(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Create", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.FetchAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is object __c1p0) + { + try + { + var __c1i0 = (global::TestApp.IA)(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(serviceProvider, typeof(global::TestApp.IA)))!; + var __c1i1 = (global::TestApp.IB)(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(serviceProvider, typeof(global::TestApp.IB)))!; + var __c1i2 = (global::TestApp.IC)(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(serviceProvider, typeof(global::TestApp.IC)))!; + var __c1i3 = (global::TestApp.ID)(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(serviceProvider, typeof(global::TestApp.ID)))!; + __operations.Fetch__Object(__c1p0, __c1i0, __c1i1, __c1i2, __c1i3); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Load", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) + { + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationType, criteria); + } + + async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationNamedMapping.InvokeNamedOperationAsync( + string operationName, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) + { + var __operations = (IDataPortalOperations)this; + switch (operationName) + { + case "Create": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.Create(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Create", __ex); + } + return; + } + break; + case "Fetch__Int32": + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Fetch__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + break; + case "Fetch__Object": + if (criteria is { Length: 1 } && (criteria[0] is null || criteria[0] is object)) + { + try + { + var __c2i0 = (global::TestApp.IA)(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(serviceProvider, typeof(global::TestApp.IA)))!; + var __c2i1 = (global::TestApp.IB)(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(serviceProvider, typeof(global::TestApp.IB)))!; + var __c2i2 = (global::TestApp.IC)(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(serviceProvider, typeof(global::TestApp.IC)))!; + var __c2i3 = (global::TestApp.ID)(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(serviceProvider, typeof(global::TestApp.ID)))!; + __operations.Fetch__Object((object)criteria[0]!, __c2i0, __c2i1, __c2i2, __c2i3); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Load", __ex); + } + return; + } + break; + case "CreateChild": + if (criteria is null or { Length: 0 }) + { + try + { + __operations.CreateChild(); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Child_Create", __ex); + } + return; + } + break; + } + throw new global::Csla.Server.DataPortalOperationNotSupportedException(operationName, criteria); + } + } +} diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByIntermediate#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByIntermediate#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index feb63cc21f..7d5dbf5aea 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByIntermediate#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByIntermediate#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -15,11 +15,13 @@ partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, glo internal interface IDataPortalOperations { void Create(); + void Fetch__Int32(int id); void Delete__Int32(int id); void CreateChild(); } void IDataPortalOperations.Create() => Create(); + void IDataPortalOperations.Fetch__Int32(int id) => Load(id); void IDataPortalOperations.Delete__Int32(int id) => Delete(id); void IDataPortalOperations.CreateChild() => Child_Create(); diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index 1f345aa41f..85c0054aa0 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -41,6 +41,18 @@ internal interface IDataPortalOperations } return; } + if (criteria is { Length: 1 } && criteria[0] is int __c1p0) + { + try + { + __operations.Fetch__Int32(__c1p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Load", __ex); + } + return; + } } else if (operationType == typeof(global::Csla.CreateChildAttribute)) { diff --git a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PrivateNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PrivateNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs index f5960b54c0..55bc82f67a 100644 --- a/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PrivateNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs +++ b/Source/tests/Csla.Generator.AutoImplementProperties.CSharp.Tests/DataPortalOperations/Snapshots/DataPortalOperationsGeneratorTests.PrivateNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs @@ -14,16 +14,33 @@ partial class PersonEdit : global::TestApp.PersonEdit.IDataPortalOperations, glo [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] internal interface IDataPortalOperations { + void Fetch__Object(object value); void CreateChild(); } + void IDataPortalOperations.Fetch__Object(object value) => Fetch(value); void IDataPortalOperations.CreateChild() => Child_Create(); async global::System.Threading.Tasks.Task global::Csla.Server.IDataPortalOperationMapping.InvokeOperationAsync( global::System.Type operationType, bool isSync, object?[]? criteria, global::System.IServiceProvider serviceProvider) { var __operations = (IDataPortalOperations)this; - if (operationType == typeof(global::Csla.CreateChildAttribute)) + if (operationType == typeof(global::Csla.FetchAttribute)) + { + if (criteria is { Length: 1 } && criteria[0] is object __c0p0 && !(criteria[0] is global::TestApp.PersonEdit.Criteria)) + { + try + { + __operations.Fetch__Object(__c0p0); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + } + else if (operationType == typeof(global::Csla.CreateChildAttribute)) { if (criteria is null or { Length: 0 }) { @@ -47,6 +64,20 @@ internal interface IDataPortalOperations var __operations = (IDataPortalOperations)this; switch (operationName) { + case "Fetch__Object": + if (criteria is { Length: 1 } && (criteria[0] is null || criteria[0] is object)) + { + try + { + __operations.Fetch__Object((object)criteria[0]!); + } + catch (global::System.Exception __ex) + { + throw global::Csla.Server.DataPortalOperationHelper.CreateCallMethodException(this, "Fetch", __ex); + } + return; + } + break; case "CreateChild": if (criteria is null or { Length: 0 }) { diff --git a/docs/data-portal-operations-generator.md b/docs/data-portal-operations-generator.md index 32f3aa72e4..a28bea52ae 100644 --- a/docs/data-portal-operations-generator.md +++ b/docs/data-portal-operations-generator.md @@ -72,17 +72,18 @@ public partial class Customer : AppBase The generated code for `Customer` calls `Create`, `InsertChild` and `Update` directly, along with operation methods inherited from CSLA's base classes, such as `BusinessBase.Child_Create` and the `Child_UpdateAsync(params object[])` method of the editable list base classes. It chooses between methods the same way reflection-based dispatch does: * Private methods of a base class are not included. -* A method declared closer to the class is preferred over one declared further up the inheritance chain. +* A subclass of an operation attribute counts as that attribute. * An override is called virtually, even when it does not repeat the operation attribute. * If the class declares a member with the same name as an inherited operation method, the generated code calls the inherited method through `base`. +* When several methods could take the criteria, the generated code uses the scores of reflection-based dispatch: 3 per criteria value of the exact parameter type, 2 for an assignable type and 1 for `object`, less one per level of inheritance, plus one per injected parameter. It calls a method only when no other method could tie or outscore it for those criteria, and otherwise leaves the call to reflection. -In a few cases the generated code leaves an inherited method to reflection-based dispatch, which still calls it as before: +The generated code cannot call some methods, but still takes them into account when it chooses between methods, and reflection-based dispatch calls them as before: -* An intermediate base class declares another member with the same name, which would hide the method from the generated code. -* A method closer to the class takes the same number of criteria, and a less specific parameter type, such as `object`, means reflection could choose that closer method instead. -* The criteria also match a method further up the inheritance chain, and do not exactly match the types of a closer method with a less specific parameter type. -* The method is internal to another assembly. -* The method takes or returns a protected or private nested type, which the generated internal interface cannot name. The same applies to an operation method the class declares. +* An inherited method hidden by another member with the same name in an intermediate base class. +* An inherited method that is internal to another assembly. +* A method, declared or inherited, that takes or returns a protected or private nested type, which the generated internal interface cannot name. + +When the class declares a generic operation method, or marks a method with a subclass of an operation attribute, the generator leaves every call of that kind of operation (for example all `[CreateChild]` calls) to reflection-based dispatch. When a method the class declares and an inherited method map to the same operation, analyzers CSLADP002 and CSLADP009 report it at the declared method. If they tie, the data portal reports an ambiguous match, as reflection-based dispatch does.