-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename generic type binding configurator
- Loading branch information
1 parent
fff66ed
commit 608cfb4
Showing
4 changed files
with
97 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/JsBind.Net/Configurations/ITypedBindingConfigurator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace JsBind.Net.Configurations | ||
{ | ||
/// <summary> | ||
/// The configurator for binding of a defined type. | ||
/// </summary> | ||
public interface ITypedBindingConfigurator | ||
{ | ||
/// <summary> | ||
/// Configure the type to include declared properties. | ||
/// </summary> | ||
void IncludeDeclaredProperties(); | ||
|
||
/// <summary> | ||
/// Configure the type to include specified properties. | ||
/// </summary> | ||
/// <param name="properties">The properties to include.</param> | ||
void IncludeProperties(params string[] properties); | ||
|
||
/// <summary> | ||
/// Configure the type to exclude specified properties. | ||
/// </summary> | ||
/// <param name="properties">The properties to exclude.</param> | ||
void ExcludeProperties(params string[] properties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using JsBind.Net.BindingConfigurations; | ||
|
||
namespace JsBind.Net.Configurations | ||
{ | ||
/// <summary> | ||
/// The configurator for binding of type <typeparamref name="T" />. | ||
/// </summary> | ||
/// <typeparam name="T">The type configured.</typeparam> | ||
public class TypedBindingConfigurator<T> : ITypedBindingConfigurator | ||
{ | ||
private readonly IBindingConfigurationProvider bindingConfigurationProvider; | ||
private BindingConfiguration? bindingConfiguration; | ||
private BindingConfiguration BindingConfiguration | ||
{ | ||
get | ||
{ | ||
if (bindingConfiguration is null) | ||
{ | ||
bindingConfiguration = new BindingConfiguration(); | ||
bindingConfigurationProvider.Add(typeof(T), bindingConfiguration); | ||
} | ||
|
||
return bindingConfiguration; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="BindingConfigurator" />. | ||
/// </summary> | ||
/// <param name="bindingConfigurationProvider">The binding configuration provider.</param> | ||
public TypedBindingConfigurator(IBindingConfigurationProvider bindingConfigurationProvider) | ||
{ | ||
this.bindingConfigurationProvider = bindingConfigurationProvider; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void IncludeDeclaredProperties() | ||
{ | ||
AddIncludeProperties(bindingConfigurationProvider.GetDeclaredProperties(typeof(T))); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void IncludeProperties(params string[] properties) | ||
{ | ||
AddIncludeProperties(properties); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void ExcludeProperties(params string[] properties) | ||
{ | ||
BindingConfiguration.ExcludeProperties = properties; | ||
} | ||
|
||
private void AddIncludeProperties(IEnumerable<string> includeProperties) | ||
{ | ||
if (BindingConfiguration.IncludeProperties is null) | ||
{ | ||
BindingConfiguration.IncludeProperties = includeProperties; | ||
} | ||
else | ||
{ | ||
BindingConfiguration.IncludeProperties = BindingConfiguration.IncludeProperties.Concat(includeProperties).ToList(); | ||
} | ||
} | ||
} | ||
} |