This repository has been archived by the owner on Nov 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
OperationBase.cs
76 lines (64 loc) · 1.76 KB
/
OperationBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// 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 System;
using Newtonsoft.Json;
namespace Microsoft.AspNetCore.JsonPatch.Operations
{
public class OperationBase
{
private string _op;
private OperationType _operationType;
[JsonIgnore]
public OperationType OperationType
{
get
{
return _operationType;
}
}
[JsonProperty("path")]
public string path { get; set; }
[JsonProperty("op")]
public string op
{
get
{
return _op;
}
set
{
OperationType result;
if (!Enum.TryParse(value, ignoreCase: true, result: out result))
{
result = OperationType.Invalid;
}
_operationType = result;
_op = value;
}
}
[JsonProperty("from")]
public string from { get; set; }
public OperationBase()
{
}
public OperationBase(string op, string path, string from)
{
if (op == null)
{
throw new ArgumentNullException(nameof(op));
}
if (path == null)
{
throw new ArgumentNullException(nameof(path));
}
this.op = op;
this.path = path;
this.from = from;
}
public bool ShouldSerializefrom()
{
return (OperationType == OperationType.Move
|| OperationType == OperationType.Copy);
}
}
}