Skip to content

Commit

Permalink
Merge pull request #3 from RocketSurgeonsGuild/more/binder
Browse files Browse the repository at this point in the history
More/binder
  • Loading branch information
david-driscoll authored Dec 16, 2017
2 parents 9636ea4 + 97299a2 commit b3e16b1
Show file tree
Hide file tree
Showing 13 changed files with 752 additions and 187 deletions.
4 changes: 3 additions & 1 deletion Common.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<RSG_Build_Version>1.2.1</RSG_Build_Version>
<RSG_Build_Version>1.2.2</RSG_Build_Version>
<System_Interactive_Version>3.1.1</System_Interactive_Version>
<System_Reactive_Version>3.1.1</System_Reactive_Version>
<SourceLink_Version>2.6.0</SourceLink_Version>
<Microsoft_Extensions_Configuration_Version>2.0.0</Microsoft_Extensions_Configuration_Version>
<Microsoft_NET_Test_Sdk_Version>15.5.0</Microsoft_NET_Test_Sdk_Version>
<xunit_Version>2.3.1</xunit_Version>
<FluentAssertions_Version>5.0.0-beta0004</FluentAssertions_Version>
Expand All @@ -19,5 +20,6 @@
</PropertyGroup>
<!-- Overrides -->
<PropertyGroup Condition="'$(TargetFramework)'=='netstandard1.3' or '$(TargetFramework)'=='net451'">
<Microsoft_Extensions_Configuration_Version>1.1.2</Microsoft_Extensions_Configuration_Version>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion cakefile.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#load "nuget:?package=Rocket.Surgery.Cake.Library&version=0.1.8";
#load "nuget:?package=Rocket.Surgery.Cake.Library&version=0.1.10";

Task("Default")
.IsDependentOn("dotnet");
Expand Down
5 changes: 0 additions & 5 deletions global.json

This file was deleted.

1 change: 0 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>true</IsPackable>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<RootNamespace>$(MSBuildProjectName.Replace('.Extensions', ''))</RootNamespace>
</PropertyGroup>
<ItemGroup>
Expand Down
21 changes: 3 additions & 18 deletions src/Extensions/Binding/BackingFieldValueProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
namespace Rocket.Surgery.Binding
{
/// <summary>
/// Class BackingFieldValueProvider.
/// Allows Newtonsoft.Json to set the underlying backing field for a given readonly autoprop
/// </summary>
/// <seealso cref="Newtonsoft.Json.Serialization.IValueProvider" />
/// TODO Edit XML Comment Template for BackingFieldValueProvider
public class BackingFieldValueProvider : IValueProvider
{
private readonly FieldInfo _backingField;
Expand All @@ -20,20 +18,13 @@ public class BackingFieldValueProvider : IValueProvider
/// </summary>
/// <param name="memberInfo">The member information.</param>
/// <param name="backingField">The backing field.</param>
/// TODO Edit XML Comment Template for #ctor
public BackingFieldValueProvider(MemberInfo memberInfo, FieldInfo backingField)
{
_backingField = backingField;
_memberInfo = memberInfo;
}

/// <summary>
/// Sets the value.
/// </summary>
/// <param name="target">The target to set the value on.</param>
/// <param name="value">The value to set on the target.</param>
/// <exception cref="Newtonsoft.Json.JsonSerializationException"></exception>
/// TODO Edit XML Comment Template for SetValue
/// <inheritdoc />
public void SetValue(object target, object value)
{
try
Expand All @@ -46,13 +37,7 @@ public void SetValue(object target, object value)
}
}

/// <summary>
/// Gets the value.
/// </summary>
/// <param name="target">The target to get the value from.</param>
/// <returns>The value.</returns>
/// <exception cref="Newtonsoft.Json.JsonSerializationException"></exception>
/// TODO Edit XML Comment Template for GetValue
/// <inheritdoc />
public object GetValue(object target)
{
try
Expand Down
101 changes: 80 additions & 21 deletions src/Extensions/Binding/IJsonBinder.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Rocket.Surgery.Binding
{
/// <summary>
/// Interface IJsonBinder
/// <see cref="IJsonBinder"/> is a way to bind complex objects, with nested keys.
/// </summary>
/// TODO Edit XML Comment Template for IJsonBinder
public interface IJsonBinder
{
/// <summary>
/// Gets the key.
/// Bind the values to the source type
/// </summary>
/// <param name="token">The token.</param>
/// <returns>System.String.</returns>
/// TODO Edit XML Comment Template for GetKey
string GetKey(JToken token);
/// <typeparam name="T"></typeparam>
/// <param name="values">The values.</param>
T Bind<T>(IEnumerable<KeyValuePair<string, string>> values)
where T : class, new();

/// <summary>
/// Parses the specified values.
/// Bind the values to the source type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="values">The values.</param>
/// <returns>JObject.</returns>
/// TODO Edit XML Comment Template for Parse
JObject Parse(IEnumerable<KeyValuePair<string, string>> values);
/// <param name="serializer">The serializer.</param>
T Bind<T>(IEnumerable<KeyValuePair<string, string>> values, JsonSerializer serializer)
where T : class, new();

/// <summary>
/// Bind the values to the source type
/// </summary>
/// <param name="objectType"></param>
/// <param name="values">The values.</param>
object Bind(Type objectType, IEnumerable<KeyValuePair<string, string>> values);

/// <summary>
/// Gets the specified values.
/// Bind the values to the source type
/// </summary>
/// <param name="objectType"></param>
/// <param name="values">The values.</param>
/// <param name="serializer">The serializer.</param>
object Bind(Type objectType, IEnumerable<KeyValuePair<string, string>> values, JsonSerializer serializer);

/// <summary>
/// Populate the values to the source type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">The value.</param>
/// <param name="values">The values.</param>
/// <returns>T.</returns>
/// TODO Edit XML Comment Template for Get`1
T Get<T>(IEnumerable<KeyValuePair<string, string>> values) where T : class, new();

T Populate<T>(T value, IEnumerable<KeyValuePair<string, string>> values)
where T : class;

/// <summary>
/// Gets the specified values.
/// Populate the values to the source type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">The value.</param>
/// <param name="values">The values.</param>
/// <param name="serializer">The serializer.</param>
T Populate<T>(T value, IEnumerable<KeyValuePair<string, string>> values, JsonSerializer serializer)
where T : class;

/// <summary>
/// Parses the given key value pairs into a <see cref="JObject"/>.
/// </summary>
/// <param name="values">The values.</param>
/// <param name="settings">The settings.</param>
/// <returns>T.</returns>
/// TODO Edit XML Comment Template for Get`1
T Get<T>(IEnumerable<KeyValuePair<string, string>> values, JsonSerializer settings) where T : class, new();
/// <returns>Newtonsoft.Json.Linq.JObject.</returns>
JObject Parse(IEnumerable<KeyValuePair<string, string>> values);

/// <summary>
/// Get a list of <see cref="JValue"/>'s for a given object
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">The value.</param>
IEnumerable<KeyValuePair<string, JValue>> GetValues<T>(T value)
where T : class;

/// <summary>
/// Get a list of <see cref="JValue"/>'s for a given object
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">The value.</param>
/// <param name="serializer">The serializer.</param>
IEnumerable<KeyValuePair<string, JValue>> GetValues<T>(T value, JsonSerializer serializer)
where T : class;

/// <summary>
/// Get a list of key value pairs for the given source object
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">The value.</param>
IEnumerable<KeyValuePair<string, string>> From<T>(T value)
where T : class;

/// <summary>
/// Get a list of key value pairs for the given source object
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">The value.</param>
/// <param name="serializer">The serializer.</param>
IEnumerable<KeyValuePair<string, string>> From<T>(T value, JsonSerializer serializer)
where T : class;
}
}
Loading

0 comments on commit b3e16b1

Please sign in to comment.