Skip to content

Commit

Permalink
Fix issue #93. (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun authored Dec 10, 2020
1 parent 0c3a1d5 commit 54ea010
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/Beef.Core/InvokerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class InvokerBase<TParam> : Invoker
/// <param name="memberName">The method or property name of the caller to the method.</param>
/// <param name="filePath">The full path of the source file that contains the caller.</param>
/// <param name="lineNumber">The line number in the source file at which the method is called.</param>
public void Invoke(object caller, Action action, TParam param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
public void Invoke(object caller, Action action, TParam? param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
=> WrapInvoke(caller, action, param, memberName, filePath, lineNumber);

/// <summary>
Expand All @@ -37,7 +37,7 @@ public void Invoke(object caller, Action action, TParam param = default, [Caller
/// <param name="memberName">The method or property name of the caller to the method.</param>
/// <param name="filePath">The full path of the source file that contains the caller.</param>
/// <param name="lineNumber">The line number in the source file at which the method is called.</param>
protected virtual void WrapInvoke(object caller, Action action, TParam param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
protected virtual void WrapInvoke(object caller, Action action, TParam? param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
=> Check.NotNull(action, nameof(action)).Invoke();

/// <summary>
Expand All @@ -49,7 +49,7 @@ protected virtual void WrapInvoke(object caller, Action action, TParam param = d
/// <param name="memberName">The method or property name of the caller to the method.</param>
/// <param name="filePath">The full path of the source file that contains the caller.</param>
/// <param name="lineNumber">The line number in the source file at which the method is called.</param>
public async Task InvokeAsync(object caller, Func<Task> func, TParam param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
public async Task InvokeAsync(object caller, Func<Task> func, TParam? param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
=> await WrapInvokeAsync(caller, func, param, memberName, filePath, lineNumber).ConfigureAwait(false);

/// <summary>
Expand All @@ -61,7 +61,7 @@ public async Task InvokeAsync(object caller, Func<Task> func, TParam param = def
/// <param name="memberName">The method or property name of the caller to the method.</param>
/// <param name="filePath">The full path of the source file that contains the caller.</param>
/// <param name="lineNumber">The line number in the source file at which the method is called.</param>
protected virtual async Task WrapInvokeAsync(object caller, Func<Task> func, TParam param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
protected virtual async Task WrapInvokeAsync(object caller, Func<Task> func, TParam? param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
{
Check.NotNull(func, nameof(func));
await func.Invoke().ConfigureAwait(false);
Expand All @@ -82,7 +82,7 @@ protected virtual async Task WrapInvokeAsync(object caller, Func<Task> func, TPa
/// <param name="filePath">The full path of the source file that contains the caller.</param>
/// <param name="lineNumber">The line number in the source file at which the method is called.</param>
/// <returns>The result.</returns>
public TResult Invoke<TResult>(object caller, Func<TResult> func, TParam param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
public TResult Invoke<TResult>(object caller, Func<TResult> func, TParam? param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
=> WrapInvoke(caller, func, param, memberName, filePath, lineNumber);

/// <summary>
Expand All @@ -96,7 +96,7 @@ public TResult Invoke<TResult>(object caller, Func<TResult> func, TParam param =
/// <param name="filePath">The full path of the source file that contains the caller.</param>
/// <param name="lineNumber">The line number in the source file at which the method is called.</param>
/// <returns>The result.</returns>
protected virtual TResult WrapInvoke<TResult>(object caller, Func<TResult> func, TParam param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
protected virtual TResult WrapInvoke<TResult>(object caller, Func<TResult> func, TParam? param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
=> Check.NotNull(func, nameof(func)).Invoke();

/// <summary>
Expand All @@ -110,7 +110,7 @@ protected virtual TResult WrapInvoke<TResult>(object caller, Func<TResult> func,
/// <param name="filePath">The full path of the source file that contains the caller.</param>
/// <param name="lineNumber">The line number in the source file at which the method is called.</param>
/// <returns>The result.</returns>
public Task<TResult> InvokeAsync<TResult>(object caller, Func<Task<TResult>> func, TParam param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
public Task<TResult> InvokeAsync<TResult>(object caller, Func<Task<TResult>> func, TParam? param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
=> WrapInvokeAsync(caller, func, param, memberName, filePath, lineNumber);

/// <summary>
Expand All @@ -124,7 +124,7 @@ public Task<TResult> InvokeAsync<TResult>(object caller, Func<Task<TResult>> fun
/// <param name="filePath">The full path of the source file that contains the caller.</param>
/// <param name="lineNumber">The line number in the source file at which the method is called.</param>
/// <returns>The result.</returns>
protected virtual Task<TResult> WrapInvokeAsync<TResult>(object caller, Func<Task<TResult>> func, TParam param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
protected virtual Task<TResult> WrapInvokeAsync<TResult>(object caller, Func<Task<TResult>> func, TParam? param = default, [CallerMemberName] string? memberName = null, [CallerFilePath] string? filePath = null, [CallerLineNumber] int lineNumber = 0)
=> Check.NotNull(func, nameof(func)).Invoke();

#endregion
Expand Down
2 changes: 2 additions & 0 deletions src/Beef.Data.Database/DatabaseWildcard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public class DatabaseWildcard
/// <param name="singleWildcard">The database single wildcard character.</param>
/// <param name="charactersToEscape">The list of characters that are to be escaped (defaults to <see cref="DefaultCharactersToEscape"/>).</param>
/// <param name="escapeFormat">The escaping format string when one of the <see cref="CharactersToEscape"/> is found (defaults to <see cref="DefaultEscapeFormat"/>).</param>
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Somehow the compiler thinks CharactersToEscape can be null; so not true.
public DatabaseWildcard(Wildcard? wildcard = null, char multiWildcard = MultiWildcardCharacter, char singleWildcard = SingleWildcardCharacter,
#pragma warning restore CS8618
char[]? charactersToEscape = null, string? escapeFormat = null)
{
Wildcard = wildcard ?? Wildcard.Default ?? Wildcard.MultiAll;
Expand Down
2 changes: 1 addition & 1 deletion tools/Beef.CodeGen.Core/Beef.CodeGen.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Beef.CodeGen</RootNamespace>
<Version>4.1.11</Version>
<Version>4.1.12</Version>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<ApplicationIcon />
<StartupObject />
Expand Down
3 changes: 3 additions & 0 deletions tools/Beef.CodeGen.Core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v4.1.12
- *Fixed:* Issue [93](https://github.com/Avanade/Beef/issues/93) fixed. The `XxxServiceCollectionExtensions.cs` classes were errantly being generated where there are no corresponding operations that would require.

## v4.1.11
- *Fixed:* Issue [91](https://github.com/Avanade/Beef/issues/91) fixed. `WebApiAuthorize` attribute code-gen output reverted back to pre-_Handlebars_ behaviour. Controller-level will only output where specified; will no longer default to `AllowAnonymous`. Method-level will only output where specified; will no longer default to parent (entity) value.

Expand Down
21 changes: 21 additions & 0 deletions tools/Beef.CodeGen.Core/Generators/EntitySceDataCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef

using System.Collections.Generic;
using System.Linq;

namespace Beef.CodeGen.Generators
{
/// <summary>
/// Represents the <b>Data</b> Service Collection Extensions code generator; where not excluded and at least one operation exists.
/// </summary>
public class EntitySceDataCodeGenerator : CodeGeneratorBase<Config.Entity.CodeGenConfig, Config.Entity.CodeGenConfig>
{
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="config"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
protected override IEnumerable<Config.Entity.CodeGenConfig> SelectGenConfig(Config.Entity.CodeGenConfig config)
=> Check.NotNull(config, nameof(config)).Entities.Any(x => x.ExcludeData != "Yes" && x.Operations!.Count > 0) ? new Config.Entity.CodeGenConfig[] { config } : System.Array.Empty<Config.Entity.CodeGenConfig>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef

using System.Collections.Generic;
using System.Linq;

namespace Beef.CodeGen.Generators
{
/// <summary>
/// Represents the <b>DataSvc</b> Service Collection Extensions code generator; where not excluded and at least one operation exists.
/// </summary>
public class EntitySceDataSvcCodeGenerator : CodeGeneratorBase<Config.Entity.CodeGenConfig, Config.Entity.CodeGenConfig>
{
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="config"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
protected override IEnumerable<Config.Entity.CodeGenConfig> SelectGenConfig(Config.Entity.CodeGenConfig config)
=> Check.NotNull(config, nameof(config)).Entities.Any(x => IsFalse(x.ExcludeDataSvc) && x.Operations!.Count > 0) ? new Config.Entity.CodeGenConfig[] { config } : System.Array.Empty<Config.Entity.CodeGenConfig>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef

using System.Collections.Generic;
using System.Linq;

namespace Beef.CodeGen.Generators
{
/// <summary>
/// Represents the <b>Manager</b> Service Collection Extensions code generator; where not excluded and at least one operation exists.
/// </summary>
public class EntitySceManagerCodeGenerator : CodeGeneratorBase<Config.Entity.CodeGenConfig, Config.Entity.CodeGenConfig>
{
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="config"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
protected override IEnumerable<Config.Entity.CodeGenConfig> SelectGenConfig(Config.Entity.CodeGenConfig config)
=> Check.NotNull(config, nameof(config)).Entities.Any(x => IsFalse(x.ExcludeManager) && x.Operations!.Count > 0) ? new Config.Entity.CodeGenConfig[] { config } : System.Array.Empty<Config.Entity.CodeGenConfig>();
}
}
8 changes: 4 additions & 4 deletions tools/Beef.CodeGen.Core/Scripts/EntityBusiness.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Generate GenType="Beef.CodeGen.Generators.IEntityManagerCodeGenerator" Template="IEntityManager_cs.hbs" FileName="I{{Name}}Manager.cs" OutDir="{{Root.Company}}.{{Root.AppName}}.Business" HelpText="IEntityManagerCodeGenerator: Business" />
<Generate GenType="Beef.CodeGen.Generators.EntityManagerCodeGenerator" Template="EntityManager_cs.hbs" FileName="{{Name}}Manager.cs" OutDir="{{Root.Company}}.{{Root.AppName}}.Business" HelpText="EntityManagerCodeGenerator: Business" />

<Generate GenType="Beef.CodeGen.Generators.RootEntityCodeGenerator" Template="ServiceCollectionExtensionsManager_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business" HelpText="RootEntityCodeGenerator: Business" />
<Generate GenType="Beef.CodeGen.Generators.RootEntityCodeGenerator" Template="ServiceCollectionExtensionsDataSvc_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business/DataSvc" HelpText="RootEntityCodeGenerator: Business|DataSvc" />
<Generate GenType="Beef.CodeGen.Generators.RootEntityCodeGenerator" Template="ServiceCollectionExtensionsData_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business/Data" HelpText="RootEntityCodeGenerator: Business|Data" />
</Script>
<Generate GenType="Beef.CodeGen.Generators.EntitySceManagerCodeGenerator" Template="ServiceCollectionExtensionsManager_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business" HelpText="EntitySceManagerCodeGenerator: Business" />
<Generate GenType="Beef.CodeGen.Generators.EntitySceDataSvcCodeGenerator" Template="ServiceCollectionExtensionsDataSvc_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business/DataSvc" HelpText="EntitySceDataSvcCodeGenerator: Business|DataSvc" />
<Generate GenType="Beef.CodeGen.Generators.EntitySceDataCodeGenerator" Template="ServiceCollectionExtensionsData_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business/Data" HelpText="EntitySceDataCodeGenerator: Business|Data" />
</Script>
6 changes: 3 additions & 3 deletions tools/Beef.CodeGen.Core/Scripts/EntityWebApiCoreAgent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<Generate GenType="Beef.CodeGen.Generators.IEntityManagerCodeGenerator" Template="IEntityManager_cs.hbs" FileName="I{{Name}}Manager.cs" OutDir="{{Root.Company}}.{{Root.AppName}}.Business" HelpText="IEntityManagerCodeGenerator: Business" />
<Generate GenType="Beef.CodeGen.Generators.EntityManagerCodeGenerator" Template="EntityManager_cs.hbs" FileName="{{Name}}Manager.cs" OutDir="{{Root.Company}}.{{Root.AppName}}.Business" HelpText="EntityManagerCodeGenerator: Business" />

<Generate GenType="Beef.CodeGen.Generators.RootEntityCodeGenerator" Template="ServiceCollectionExtensionsManager_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business" HelpText="RootEntityCodeGenerator: Business" />
<Generate GenType="Beef.CodeGen.Generators.RootEntityCodeGenerator" Template="ServiceCollectionExtensionsDataSvc_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business/DataSvc" HelpText="RootEntityCodeGenerator: Business|DataSvc" />
<Generate GenType="Beef.CodeGen.Generators.RootEntityCodeGenerator" Template="ServiceCollectionExtensionsData_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business/Data" HelpText="RootEntityCodeGenerator: Business|Data" />
<Generate GenType="Beef.CodeGen.Generators.EntitySceManagerCodeGenerator" Template="ServiceCollectionExtensionsManager_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business" HelpText="EntitySceManagerCodeGenerator: Business" />
<Generate GenType="Beef.CodeGen.Generators.EntitySceDataSvcCodeGenerator" Template="ServiceCollectionExtensionsDataSvc_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business/DataSvc" HelpText="EntitySceDataSvcCodeGenerator: Business|DataSvc" />
<Generate GenType="Beef.CodeGen.Generators.EntitySceDataCodeGenerator" Template="ServiceCollectionExtensionsData_cs.hbs" FileName="ServiceCollectionExtensions.cs" OutDir="{{Company}}.{{AppName}}.Business/Data" HelpText="EntitySceDataCodeGenerator: Business|Data" />

<Generate GenType="Beef.CodeGen.Generators.EntityWebApiControllerCodeGenerator" Template="EntityWebApiController_cs.hbs" FileName="{{Name}}Controller.cs" OutDir="{{Root.Company}}.{{Root.AppName}}.{{Root.ApiName}}/Controllers" EntityScope="Common" HelpText="EntityWebApiControllerCodeGenerator: Api|Controllers" />
<Generate GenType="Beef.CodeGen.Generators.EntityWebApiAgentCodeGenerator" Template="EntityWebApiAgent_cs.hbs" FileName="{{Name}}Agent.cs" OutDir="{{Root.Company}}.{{Root.AppName}}.Common/Agents" EntityScope="Common" HelpText="EntityWebApiAgentCodeGenerator: Common|Agents" />
Expand Down

0 comments on commit 54ea010

Please sign in to comment.