Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexinea committed Jan 10, 2020
1 parent ee7db2c commit 3ead88d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static ContainerBuilder RegisterCosmosLocalization(this ContainerBuilder
optionAct?.Invoke(options);

var translationManager = new TranslationManager();
var translationSetter = translationManager as ITranslationManSetter;
var translationSetter = (ITranslationManSetter) translationManager;

foreach (var package in options.TranslationPackages) {
var translationPackage = package.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
<PackageReference Include="AspectCore.Core" Version="2.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netcoreapp3.1' OR
'$(TargetFramework)'=='netstandard2.1' OR
'$(TargetFramework)'=='netstandard2.0' OR
'$(TargetFramework)'=='net461'">
<ItemGroup Condition="'$(TargetFramework)'=='netcoreapp3.1' OR &#xD;&#xA; '$(TargetFramework)'=='netstandard2.1' OR &#xD;&#xA; '$(TargetFramework)'=='netstandard2.0' OR &#xD;&#xA; '$(TargetFramework)'=='net461'">
<PackageReference Include="AspectCore.Extensions.DependencyInjection" Version="2.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ public class ConsoleLanguageServiceProvider : ILanguageServiceProvider {

private readonly TranslationProcessor _translationProcessor;

/// <inheritdoc />
/// <summary>
/// Create a new instance of <see cref="ConsoleLanguageServiceProvider"/>.
/// </summary>
/// <param name="manager"></param>
/// <param name="processor"></param>
public ConsoleLanguageServiceProvider(ITranslationManager manager, TranslationProcessor processor) {
_translationManager = manager ?? throw new ArgumentNullException(nameof(manager));
_translationProcessor = processor ?? throw new ArgumentNullException(nameof(processor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class I18NServiceCollection : II18NServiceCollection {
/// <param name="options"></param>
public I18NServiceCollection(IServiceCollection services = null, I18NOptions options = null) {
_services = services ?? new ServiceCollection();
_options = options ?? new I18NOptions();
_options = I18NOptions.Create(options);
_translationManager = new TranslationManager();

AfterBuild(UpdateStaticResolver);
Expand All @@ -50,7 +50,11 @@ public II18NServiceCollection AddDependency(Action<IServiceCollection> servicesA
return this;
}

/// <inheritdoc />
/// <summary>
/// Build
/// </summary>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public IServiceProvider Build() {
if (_hasBuild) {
throw new InvalidOperationException("Only can be built once.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ public static class GlobalConfigurationExtensions {
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static II18NServiceCollection ToGlobal(this II18NServiceCollection services, Action<I18NOptions> optionsAct) {
if (services == null) throw new ArgumentNullException(nameof(services));
if (optionsAct == null) throw new ArgumentNullException(nameof(optionsAct));
if (services is null)
throw new ArgumentNullException(nameof(services));
if (optionsAct is null)
throw new ArgumentNullException(nameof(optionsAct));

services.AppendOptionsAction(optionsAct);

Expand Down
28 changes: 22 additions & 6 deletions src/Cosmos.I18N/Cosmos/I18N/Configurations/I18NOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public I18NOptions AddPackage(ITranslatePackage package, MergeLevel level = Merg
if (__translationPackages.TryGetValue(hashOfPackageKey, out var packageInstance)) {
var template = TranslatePackageMerger.Merge(packageInstance, package, level, customMergeProvider);
__translationPackages[hashOfPackageKey] = template;
}
else {
} else {
AddPackageInternal(package);
}
}
Expand Down Expand Up @@ -108,14 +107,12 @@ public I18NOptions AddResource(string packageKey, ITranslateResource resource) {
if (TryRegisterLanguageTagOnce(resource.Binding)) {
if (__translationPackages.TryGetValue(hashOfPackageKey, out var package)) {
package.AddResource(resource);
}
else {
} else {
var future = new TranslatePackage(packageKey, _fallbackExperimenter);
future.AddResource(resource);
AddPackageInternal(future);
}
}
else {
} else {
throw new InvalidOperationException($"Something broken when add new resource '{resource.Name}'.");
}
}
Expand Down Expand Up @@ -271,5 +268,24 @@ public I18NOptions RemoveLanguageTagChangedHandler() {

#endregion

/// <summary>
/// Create
/// </summary>
/// <param name="optionAct"></param>
/// <returns></returns>
public static I18NOptions Create(Action<I18NOptions> optionAct = null) {
var options = new I18NOptions();
optionAct?.Invoke(options);
return options;
}

/// <summary>
/// Create
/// </summary>
/// <param name="options"></param>
/// <returns></returns>
public static I18NOptions Create(I18NOptions options) {
return options ?? new I18NOptions();
}
}
}

0 comments on commit 3ead88d

Please sign in to comment.