[JsonPatch]: Added NotNull attribute to parameters and updated comments

This commit is contained in:
Kirthi Krishnamraju 2015-07-01 16:12:40 -07:00
parent c2952f26fa
commit 38748b54eb
7 changed files with 194 additions and 176 deletions

View File

@ -22,7 +22,9 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
/// </summary>
/// <param name="contractResolver">The <see cref="IContractResolver"/>.</param>
/// <param name="logErrorAction">The <see cref="Action"/> for logging <see cref="JsonPatchError{TModel}"/>.</param>
public ObjectAdapter(IContractResolver contractResolver, Action<JsonPatchError<TModel>> logErrorAction)
public ObjectAdapter(
[NotNull] IContractResolver contractResolver,
Action<JsonPatchError<TModel>> logErrorAction)
{
ContractResolver = contractResolver;
LogErrorAction = logErrorAction;
@ -97,8 +99,8 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
/// because "a" does not exist.
/// </summary>
/// <param name="operation">The add operation.</param>
/// <param name="objectApplyTo">Object to apply the operation to.</param>
public void Add(Operation<TModel> operation, TModel objectToApplyTo)
/// <param name="objectToApplyTo">Object to apply the operation to.</param>
public void Add([NotNull] Operation<TModel> operation, [NotNull] TModel objectToApplyTo)
{
Add(operation.path, operation.value, objectToApplyTo, operation);
}
@ -107,7 +109,11 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
/// Add is used by various operations (eg: add, copy, ...), yet through different operations;
/// This method allows code reuse yet reporting the correct operation on error
/// </summary>
private void Add(string path, object value, TModel objectToApplyTo, Operation<TModel> operationToReport)
private void Add(
[NotNull] string path,
object value,
[NotNull] TModel objectToApplyTo,
[NotNull] Operation<TModel> operationToReport)
{
// add, in this implementation, does not just "add" properties - that's
// technically impossible; It can however be used to add items to arrays,
@ -237,8 +243,8 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
/// location; i.e., a location cannot be moved into one of its children.
/// </summary>
/// <param name="operation">The move operation.</param>
/// <param name="objectApplyTo">Object to apply the operation to.</param>
public void Move(Operation<TModel> operation, TModel objectToApplyTo)
/// <param name="objectToApplyTo">Object to apply the operation to.</param>
public void Move([NotNull] Operation<TModel> operation, [NotNull] TModel objectToApplyTo)
{
// get value at from location
object valueAtFromLocation = null;
@ -322,8 +328,8 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
/// specified index are shifted one position to the left.
/// </summary>
/// <param name="operation">The remove operation.</param>
/// <param name="objectApplyTo">Object to apply the operation to.</param>
public void Remove(Operation<TModel> operation, TModel objectToApplyTo)
/// <param name="objectToApplyTo">Object to apply the operation to.</param>
public void Remove([NotNull] Operation<TModel> operation, [NotNull] TModel objectToApplyTo)
{
Remove(operation.path, objectToApplyTo, operation);
}
@ -332,7 +338,10 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
/// Remove is used by various operations (eg: remove, move, ...), yet through different operations;
/// This method allows code reuse yet reporting the correct operation on error
/// </summary>
private void Remove(string path, TModel objectToApplyTo, Operation<TModel> operationToReport)
private void Remove(
[NotNull] string path,
[NotNull] TModel objectToApplyTo,
[NotNull] Operation<TModel> operationToReport)
{
var removeFromList = false;
var positionAsInteger = -1;
@ -442,8 +451,8 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
/// for performance reasons (multiple checks of same requirements).
/// </summary>
/// <param name="operation">The replace operation.</param>
/// <param name="objectApplyTo">Object to apply the operation to.</param>
public void Replace(Operation<TModel> operation, TModel objectToApplyTo)
/// <param name="objectToApplyTo">Object to apply the operation to.</param>
public void Replace([NotNull] Operation<TModel> operation, [NotNull] TModel objectToApplyTo)
{
Remove(operation.path, objectToApplyTo, operation);
Add(operation.path, operation.value, objectToApplyTo, operation);
@ -470,8 +479,8 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
/// the value specified in from for performance reasons (multiple checks of same requirements).
/// </summary>
/// <param name="operation">The copy operation.</param>
/// <param name="objectApplyTo">Object to apply the operation to.</param>
public void Copy(Operation<TModel> operation, TModel objectToApplyTo)
/// <param name="objectToApplyTo">Object to apply the operation to.</param>
public void Copy([NotNull] Operation<TModel> operation, [NotNull] TModel objectToApplyTo)
{
// get value at from location
object valueAtFromLocation = null;
@ -610,9 +619,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
}
}
private JsonPatchProperty FindPropertyAndParent(
object targetObject,
string propertyPath)
private JsonPatchProperty FindPropertyAndParent(object targetObject, string propertyPath)
{
try
{
@ -674,7 +681,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
}
}
private Type GetIListType([NotNull] Type type)
private Type GetIListType(Type type)
{
if (IsGenericListType(type))
{
@ -692,7 +699,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
return null;
}
private bool IsGenericListType([NotNull] Type type)
private bool IsGenericListType(Type type)
{
if (type.GetTypeInfo().IsGenericType &&
type.GetGenericTypeDefinition() == typeof(IList<>))

View File

@ -3,6 +3,7 @@
using System;
using Microsoft.AspNet.JsonPatch.Operations;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.JsonPatch.Exceptions
{
@ -27,14 +28,14 @@ namespace Microsoft.AspNet.JsonPatch.Exceptions
}
public JsonPatchException(JsonPatchError<TModel> jsonPatchError)
public JsonPatchException([NotNull] JsonPatchError<TModel> jsonPatchError)
{
FailedOperation = jsonPatchError.Operation;
_message = jsonPatchError.ErrorMessage;
AffectedObject = jsonPatchError.AffectedObject;
}
public JsonPatchException(JsonPatchError<TModel> jsonPatchError, Exception innerException)
public JsonPatchException([NotNull] JsonPatchError<TModel> jsonPatchError, Exception innerException)
: this(jsonPatchError)
{
InnerException = innerException;

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
using Newtonsoft.Json.Serialization;
namespace Microsoft.AspNet.JsonPatch
@ -13,7 +14,7 @@ namespace Microsoft.AspNet.JsonPatch
/// <summary>
/// Initializes a new instance.
/// </summary>
public JsonPatchProperty(JsonProperty property, object parent)
public JsonPatchProperty([NotNull] JsonProperty property, [NotNull] object parent)
{
Property = property;
Parent = parent;

View File

@ -8,6 +8,7 @@ using Microsoft.AspNet.JsonPatch.Adapters;
using Microsoft.AspNet.JsonPatch.Converters;
using Microsoft.AspNet.JsonPatch.Helpers;
using Microsoft.AspNet.JsonPatch.Operations;
using Microsoft.Framework.Internal;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
@ -31,8 +32,10 @@ namespace Microsoft.AspNet.JsonPatch
ContractResolver = new DefaultContractResolver();
}
// Create from list of operations
public JsonPatchDocument(List<Operation<TModel>> operations, IContractResolver contractResolver)
// Create from list of operations.
public JsonPatchDocument(
[NotNull] List<Operation<TModel>> operations,
[NotNull] IContractResolver contractResolver)
{
Operations = operations;
ContractResolver = contractResolver;
@ -42,11 +45,11 @@ namespace Microsoft.AspNet.JsonPatch
/// Add operation. Will result in, for example,
/// { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }
/// </summary>
/// <typeparam name="TProp">value type</typeparam>
/// <param name="path">path</param>
/// <param name="value">value</param>
/// <returns></returns>
public JsonPatchDocument<TModel> Add<TProp>(Expression<Func<TModel, TProp>> path, TProp value)
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="path">The path of the property to add.</param>
/// <param name="value">The value to add.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Add<TProp>([NotNull] Expression<Func<TModel, TProp>> path, TProp value)
{
Operations.Add(new Operation<TModel>(
"add",
@ -58,16 +61,15 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Add value to list at given position
/// Add value to list at given position.
/// </summary>
/// <typeparam name="TProp">value type</typeparam>
/// <param name="path">path</param>
/// <param name="value">value</param>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="path">The path of the property to add.</param>
/// <param name="value">The value to add.</param>
/// <param name="position">position</param>
/// <returns></returns>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Add<TProp>(
Expression<Func<TModel,
IList<TProp>>> path,
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
TProp value,
int position)
{
@ -81,13 +83,13 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// At value at end of list
/// At value at end of list.
/// </summary>
/// <typeparam name="TProp">value type</typeparam>
/// <param name="path">path</param>
/// <param name="value">value</param>
/// <returns></returns>
public JsonPatchDocument<TModel> Add<TProp>(Expression<Func<TModel, IList<TProp>>> path, TProp value)
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="path">The path of the property to add.</param>
/// <param name="value">The value to add.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Add<TProp>([NotNull] Expression<Func<TModel, IList<TProp>>> path, TProp value)
{
Operations.Add(new Operation<TModel>(
"add",
@ -102,24 +104,26 @@ namespace Microsoft.AspNet.JsonPatch
/// Remove value at target location. Will result in, for example,
/// { "op": "remove", "path": "/a/b/c" }
/// </summary>
/// <param name="remove"></param>
/// <param name="path"></param>
/// <returns></returns>
public JsonPatchDocument<TModel> Remove<TProp>(Expression<Func<TModel, TProp>> path)
/// <param name="path">The path of the property to remove.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Remove<TProp>([NotNull] Expression<Func<TModel, TProp>> path)
{
Operations.Add(new Operation<TModel>("remove", ExpressionHelpers.GetPath(path).ToLowerInvariant(), from: null));
Operations.Add(
new Operation<TModel>("remove", ExpressionHelpers.GetPath(path).ToLowerInvariant(), from: null));
return this;
}
/// <summary>
/// Remove value from list at given position
/// Remove value from list at given position.
/// </summary>
/// <typeparam name="TProp">value type</typeparam>
/// <param name="path">target location</param>
/// <param name="position">position</param>
/// <returns></returns>
public JsonPatchDocument<TModel> Remove<TProp>(Expression<Func<TModel, IList<TProp>>> path, int position)
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="path">The path of the property to remove.</param>
/// <param name="position">The position in the list.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Remove<TProp>(
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
int position)
{
Operations.Add(new Operation<TModel>(
"remove",
@ -130,12 +134,12 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Remove value from end of list
/// Remove value from end of list.
/// </summary>
/// <typeparam name="TProp">value type</typeparam>
/// <param name="path">target location</param>
/// <returns></returns>
public JsonPatchDocument<TModel> Remove<TProp>(Expression<Func<TModel, IList<TProp>>> path)
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="path">The path of the property to remove.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Remove<TProp>([NotNull] Expression<Func<TModel, IList<TProp>>> path)
{
Operations.Add(new Operation<TModel>(
"remove",
@ -149,10 +153,10 @@ namespace Microsoft.AspNet.JsonPatch
/// Replace value. Will result in, for example,
/// { "op": "replace", "path": "/a/b/c", "value": 42 }
/// </summary>
/// <param name="path"></param>
/// <param name="value"></param>
/// <returns></returns>
public JsonPatchDocument<TModel> Replace<TProp>(Expression<Func<TModel, TProp>> path, TProp value)
/// <param name="path">The path of the property to replace.</param>
/// <param name="value">The value to replace.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Replace<TProp>([NotNull] Expression<Func<TModel, TProp>> path, TProp value)
{
Operations.Add(new Operation<TModel>(
"replace",
@ -164,15 +168,16 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Replace value in a list at given position
/// Replace value in a list at given position.
/// </summary>
/// <typeparam name="TProp">value type</typeparam>
/// <param name="path">target location</param>
/// <param name="position">position</param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="path">The path of the property to replace.</param>
/// <param name="position">The position in the list.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Replace<TProp>(
Expression<Func<TModel, IList<TProp>>> path,
TProp value, int position)
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
TProp value,
int position)
{
Operations.Add(new Operation<TModel>(
"replace",
@ -184,12 +189,14 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Replace value at end of a list
/// Replace value at end of a list.
/// </summary>
/// <typeparam name="TProp">value type</typeparam>
/// <param name="path">target location</param>
/// <returns></returns>
public JsonPatchDocument<TModel> Replace<TProp>(Expression<Func<TModel, IList<TProp>>> path, TProp value)
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="path">The path of the property to replace.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Replace<TProp>(
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
TProp value)
{
Operations.Add(new Operation<TModel>(
"replace",
@ -204,12 +211,12 @@ namespace Microsoft.AspNet.JsonPatch
/// Removes value at specified location and add it to the target location. Will result in, for example:
/// { "op": "move", "from": "/a/b/c", "path": "/a/b/d" }
/// </summary>
/// <param name="from"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <param name="from">The path of the property to remove.</param>
/// <param name="path">The path of the property to add.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Move<TProp>(
Expression<Func<TModel, TProp>> from,
Expression<Func<TModel, TProp>> path)
[NotNull] Expression<Func<TModel, TProp>> from,
[NotNull] Expression<Func<TModel, TProp>> path)
{
Operations.Add(new Operation<TModel>(
"move",
@ -220,17 +227,17 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Move from a position in a list to a new location
/// Move from a position in a list to a new location.
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <param name="from"></param>
/// <param name="positionFrom"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="from">The path of the property to remove.</param>
/// <param name="positionFrom">The position in the list to remove.</param>
/// <param name="path">The path of the property to add.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Move<TProp>(
Expression<Func<TModel, IList<TProp>>> from,
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
int positionFrom,
Expression<Func<TModel, TProp>> path)
[NotNull] Expression<Func<TModel, TProp>> path)
{
Operations.Add(new Operation<TModel>(
"move",
@ -241,16 +248,16 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Move from a property to a location in a list
/// Move from a property to a location in a list.
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <param name="from"></param>
/// <param name="positionFrom"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="from">The path of the property to remove.</param>
/// <param name="path">The path of the property to add.</param>
/// <param name="positionTo">The position in the list to add.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Move<TProp>(
Expression<Func<TModel, TProp>> from,
Expression<Func<TModel, IList<TProp>>> path,
[NotNull] Expression<Func<TModel, TProp>> from,
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
int positionTo)
{
Operations.Add(new Operation<TModel>(
@ -262,17 +269,18 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Move from a position in a list to another location in a list
/// Move from a position in a list to another location in a list.
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <param name="from"></param>
/// <param name="positionFrom"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="from">The path of the property to remove.</param>
/// <param name="positionFrom">The position in the list to remove.</param>
/// <param name="path">The path of the property to add.</param>
/// <param name="positionTo">The position in the list to add.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Move<TProp>(
Expression<Func<TModel, IList<TProp>>> from,
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
int positionFrom,
Expression<Func<TModel, IList<TProp>>> path,
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
int positionTo)
{
Operations.Add(new Operation<TModel>(
@ -284,17 +292,17 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Move from a position in a list to the end of another list
/// Move from a position in a list to the end of another list.
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <param name="from"></param>
/// <param name="positionFrom"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="from">The path of the property to remove.</param>
/// <param name="positionFrom">The position in the list to remove.</param>
/// <param name="path">The path of the property to add.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Move<TProp>(
Expression<Func<TModel, IList<TProp>>> from,
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
int positionFrom,
Expression<Func<TModel, IList<TProp>>> path)
[NotNull] Expression<Func<TModel, IList<TProp>>> path)
{
Operations.Add(new Operation<TModel>(
"move",
@ -305,16 +313,15 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Move to the end of a list
/// Move to the end of a list.
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <param name="from"></param>
/// <param name="positionFrom"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="from">The path of the property to remove.</param>
/// <param name="path">The path of the property to add.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Move<TProp>(
Expression<Func<TModel, TProp>> from,
Expression<Func<TModel, IList<TProp>>> path)
[NotNull] Expression<Func<TModel, TProp>> from,
[NotNull] Expression<Func<TModel, IList<TProp>>> path)
{
Operations.Add(new Operation<TModel>(
"move",
@ -325,15 +332,15 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Copy the value at specified location to the target location. Willr esult in, for example:
/// Copy the value at specified location to the target location. Will result in, for example:
/// { "op": "copy", "from": "/a/b/c", "path": "/a/b/e" }
/// </summary>
/// <param name="from"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <param name="from">The path of the property to copy from.</param>
/// <param name="path">The path of the property to copy to.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Copy<TProp>(
Expression<Func<TModel, TProp>> from,
Expression<Func<TModel, TProp>> path)
[NotNull] Expression<Func<TModel, TProp>> from,
[NotNull] Expression<Func<TModel, TProp>> path)
{
Operations.Add(new Operation<TModel>(
"copy",
@ -344,17 +351,17 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Copy from a position in a list to a new location
/// Copy from a position in a list to a new location.
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <param name="from"></param>
/// <param name="positionFrom"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="from">The path of the property to copy from.</param>
/// <param name="positionFrom">The position in the list to copy from.</param>
/// <param name="path">The path of the property to copy to.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Copy<TProp>(
Expression<Func<TModel, IList<TProp>>> from,
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
int positionFrom,
Expression<Func<TModel, TProp>> path)
[NotNull] Expression<Func<TModel, TProp>> path)
{
Operations.Add(new Operation<TModel>(
"copy",
@ -365,16 +372,16 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Copy from a property to a location in a list
/// Copy from a property to a location in a list.
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <param name="from"></param>
/// <param name="positionFrom"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="from">The path of the property to copy from.</param>
/// <param name="path">The path of the property to copy to.</param>
/// <param name="positionTo">The position in the list to copy to.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Copy<TProp>(
Expression<Func<TModel, TProp>> from,
Expression<Func<TModel, IList<TProp>>> path,
[NotNull] Expression<Func<TModel, TProp>> from,
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
int positionTo)
{
Operations.Add(new Operation<TModel>(
@ -386,17 +393,18 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Copy from a position in a list to a new location in a list
/// Copy from a position in a list to a new location in a list.
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <param name="from"></param>
/// <param name="positionFrom"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="from">The path of the property to copy from.</param>
/// <param name="positionFrom">The position in the list to copy from.</param>
/// <param name="path">The path of the property to copy to.</param>
/// <param name="positionTo">The position in the list to copy to.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Copy<TProp>(
Expression<Func<TModel, IList<TProp>>> from,
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
int positionFrom,
Expression<Func<TModel, IList<TProp>>> path,
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
int positionTo)
{
Operations.Add(new Operation<TModel>(
@ -408,18 +416,17 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Copy from a position in a list to the end of another list
/// Copy from a position in a list to the end of another list.
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <param name="from"></param>
/// <param name="positionFrom"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="from">The path of the property to copy from.</param>
/// <param name="positionFrom">The position in the list to copy from.</param>
/// <param name="path">The path of the property to copy to.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Copy<TProp>(
Expression<Func<TModel,
IList<TProp>>> from,
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
int positionFrom,
Expression<Func<TModel, IList<TProp>>> path)
[NotNull] Expression<Func<TModel, IList<TProp>>> path)
{
Operations.Add(new Operation<TModel>(
"copy",
@ -430,16 +437,15 @@ namespace Microsoft.AspNet.JsonPatch
}
/// <summary>
/// Copy to the end of a list
/// Copy to the end of a list.
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <param name="from"></param>
/// <param name="positionFrom"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <typeparam name="TProp">The value type.</typeparam>
/// <param name="from">The path of the property to copy from.</param>
/// <param name="path">The path of the property to copy to.</param>
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
public JsonPatchDocument<TModel> Copy<TProp>(
Expression<Func<TModel, TProp>> from,
Expression<Func<TModel, IList<TProp>>> path)
[NotNull] Expression<Func<TModel, TProp>> from,
[NotNull] Expression<Func<TModel, IList<TProp>>> path)
{
Operations.Add(new Operation<TModel>(
"copy",
@ -449,17 +455,17 @@ namespace Microsoft.AspNet.JsonPatch
return this;
}
public void ApplyTo(TModel objectToApplyTo)
public void ApplyTo([NotNull] TModel objectToApplyTo)
{
ApplyTo(objectToApplyTo, new ObjectAdapter<TModel>(ContractResolver, logErrorAction: null));
}
public void ApplyTo(TModel objectToApplyTo, Action<JsonPatchError<TModel>> logErrorAction)
public void ApplyTo([NotNull] TModel objectToApplyTo, Action<JsonPatchError<TModel>> logErrorAction)
{
ApplyTo(objectToApplyTo, new ObjectAdapter<TModel>(ContractResolver, logErrorAction));
}
public void ApplyTo(TModel objectToApplyTo, IObjectAdapter<TModel> adapter)
public void ApplyTo([NotNull] TModel objectToApplyTo, [NotNull] IObjectAdapter<TModel> adapter)
{
// apply each operation in order
foreach (var op in Operations)

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
using Newtonsoft.Json;
namespace Microsoft.AspNet.JsonPatch.Operations
@ -15,13 +16,13 @@ namespace Microsoft.AspNet.JsonPatch.Operations
}
public Operation(string op, string path, string from, object value)
public Operation([NotNull] string op, [NotNull] string path, string from, object value)
: base(op, path, from)
{
this.value = value;
}
public Operation(string op, string path, string from)
public Operation([NotNull] string op, [NotNull] string path, string from)
: base(op, path, from)
{

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.Internal;
using Newtonsoft.Json;
namespace Microsoft.AspNet.JsonPatch.Operations
@ -31,7 +32,7 @@ namespace Microsoft.AspNet.JsonPatch.Operations
}
public OperationBase(string op, string path, string from)
public OperationBase([NotNull] string op, [NotNull] string path, string from)
{
this.op = op;
this.path = path;
@ -40,7 +41,7 @@ namespace Microsoft.AspNet.JsonPatch.Operations
public bool ShouldSerializefrom()
{
return (OperationType == Operations.OperationType.Move
return (OperationType == OperationType.Move
|| OperationType == OperationType.Copy);
}
}

View File

@ -3,6 +3,7 @@
using System;
using Microsoft.AspNet.JsonPatch.Adapters;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.JsonPatch.Operations
{
@ -13,19 +14,19 @@ namespace Microsoft.AspNet.JsonPatch.Operations
}
public Operation(string op, string path, string from, object value)
public Operation([NotNull] string op, [NotNull] string path, string from, object value)
: base(op, path, from)
{
this.value = value;
}
public Operation(string op, string path, string from)
public Operation([NotNull] string op, [NotNull] string path, string from)
: base(op, path, from)
{
}
public void Apply(TModel objectToApplyTo, IObjectAdapter<TModel> adapter)
public void Apply([NotNull] TModel objectToApplyTo, [NotNull] IObjectAdapter<TModel> adapter)
{
switch (OperationType)
{
@ -53,7 +54,7 @@ namespace Microsoft.AspNet.JsonPatch.Operations
public bool ShouldSerializevalue()
{
return (OperationType == Operations.OperationType.Add
return (OperationType == OperationType.Add
|| OperationType == OperationType.Replace
|| OperationType == OperationType.Test);
}