Skip to content

Commit 2541a8e

Browse files
committed
Merge pull request #405 from sharwell/ExtensibleJsonObject
ExtensibleJsonObject
2 parents 0a3bafc + 50a9271 commit 2541a8e

165 files changed

Lines changed: 409 additions & 189 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/console/console.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
</PropertyGroup>
3939
<ItemGroup>
4040
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
41-
<SpecificVersion>False</SpecificVersion>
42-
<HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net40\Newtonsoft.Json.dll</HintPath>
41+
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
4342
</Reference>
4443
<Reference Include="SimpleRESTServices, Version=1.3.0.0, Culture=neutral, PublicKeyToken=8965cea5c205d3a3, processorArchitecture=MSIL">
4544
<SpecificVersion>False</SpecificVersion>

src/console/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Newtonsoft.Json" version="5.0.6" targetFramework="net40" />
3+
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net40" />
44
<package id="SimpleRESTServices" version="1.3.0.1" targetFramework="net40" />
55
</packages>

src/corelib/Core/Domain/AuthenticationRequirement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// <threadsafety static="true" instance="false"/>
1313
/// <preliminary/>
1414
[JsonObject(MemberSerialization.OptIn)]
15-
public class AuthenticationRequirement
15+
public class AuthenticationRequirement : ExtensibleJsonObject
1616
{
1717
#pragma warning disable 649 // Field 'fieldName' is never assigned to, and will always have its default value {value}
1818
/// <summary>

src/corelib/Core/Domain/CloudNetwork.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// <seealso href="http://docs.rackspace.com/networks/api/v2/cn-devguide/content/ch_overview.html">Overview (Rackspace Cloud Networks Developer Guide - OpenStack Networking API v2)</seealso>
99
/// <threadsafety static="true" instance="false"/>
1010
[JsonObject(MemberSerialization.OptIn)]
11-
public class CloudNetwork
11+
public class CloudNetwork : ExtensibleJsonObject
1212
{
1313
/// <summary>
1414
/// Gets the network ID.

src/corelib/Core/Domain/Container.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/// <seealso href="http://docs.rackspace.com/files/api/v1/cf-devguide/content/GET_listcontainers_v1__account__accountServicesOperations_d1e000.html">Show Account Details and List Containers (Rackspace Cloud Files Developer Guide - API v1)</seealso>
1212
/// <threadsafety static="true" instance="false"/>
1313
[JsonObject(MemberSerialization.OptIn)]
14-
public class Container
14+
public class Container : ExtensibleJsonObject
1515
{
1616
/// <summary>
1717
/// Gets the name of the container.

src/corelib/Core/Domain/ContainerCDN.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// <seealso href="http://docs.rackspace.com/files/api/v1/cf-devguide/content/CDN_Container_Services-d1e2632.html">CDN Container Services (Rackspace Cloud Files Developer Guide - API v1)</seealso>
1515
/// <threadsafety static="true" instance="false"/>
1616
[JsonObject(MemberSerialization.OptIn)]
17-
public class ContainerCDN
17+
public class ContainerCDN : ExtensibleJsonObject
1818
{
1919
/// <summary>
2020
/// Gets the name of the container.

src/corelib/Core/Domain/ContainerObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// <seealso href="http://docs.openstack.org/api/openstack-object-storage/1.0/content/GET_showContainerDetails_v1__account___container__storage_container_services.html">Show container details and list objects (OpenStack Object Storage API v1 Reference)</seealso>
1010
/// <threadsafety static="true" instance="false"/>
1111
[JsonObject(MemberSerialization.OptIn)]
12-
public class ContainerObject
12+
public class ContainerObject : ExtensibleJsonObject
1313
{
1414
/// <summary>
1515
/// Gets a "name" associated with the object.

src/corelib/Core/Domain/Converters/IPAddressDetailsConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public override bool CanConvert(Type objectType)
7272
/// <seealso cref="IComputeProvider.ListAddressesByNetwork"/>
7373
/// <threadsafety static="true" instance="false"/>
7474
[JsonObject(MemberSerialization.OptIn)]
75-
protected class AddressDetails
75+
protected class AddressDetails : ExtensibleJsonObject
7676
{
7777
/// <summary>
7878
/// Gets the network address. This is an IPv4 address if <see cref="Version"/> is <c>"4"</c>,

src/corelib/Core/Domain/Endpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace net.openstack.Core.Domain
77
/// </summary>
88
/// <threadsafety static="true" instance="false"/>
99
[JsonObject(MemberSerialization.OptIn)]
10-
public class Endpoint
10+
public class Endpoint : ExtensibleJsonObject
1111
{
1212
/// <summary>
1313
/// Gets the public URL of the service.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
namespace net.openstack.Core.Domain
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using net.openstack.Core.Collections;
7+
using Newtonsoft.Json;
8+
using Newtonsoft.Json.Linq;
9+
10+
/// <summary>
11+
/// This is the abstract base class for types modeling the JSON representation of a resource
12+
/// which may be extended by specific providers or updated in future releases of a core
13+
/// service.
14+
/// </summary>
15+
/// <threadsafety static="true" instance="false"/>
16+
/// <preliminary/>
17+
[JsonObject(MemberSerialization.OptIn)]
18+
public abstract class ExtensibleJsonObject
19+
{
20+
/// <summary>
21+
/// An empty, and thus immutable, value which is the default return value
22+
/// for <see cref="ExtensionData"/> when the backing field is <see langword="null"/>.
23+
/// </summary>
24+
protected static readonly ReadOnlyDictionary<string, JToken> EmptyExtensionData =
25+
new ReadOnlyDictionary<string, JToken>(new Dictionary<string, JToken>());
26+
27+
/// <summary>
28+
/// This is the backing field for the <see cref="ExtensionData"/> property.
29+
/// </summary>
30+
[JsonExtensionData]
31+
private Dictionary<string, JToken> _extensionData;
32+
33+
/// <summary>
34+
/// Initializes a new instance of the <see cref="ExtensibleJsonObject"/> class
35+
/// during JSON deserialization.
36+
/// </summary>
37+
[JsonConstructor]
38+
protected ExtensibleJsonObject()
39+
{
40+
}
41+
42+
/// <summary>
43+
/// Initializes a new instance of the <see cref="ExtensibleJsonObject"/> class
44+
/// with the specified extension data.
45+
/// </summary>
46+
/// <param name="extensionData">The extension data.</param>
47+
/// <exception cref="ArgumentNullException">If <paramref name="extensionData"/> is <see langword="null"/>.</exception>
48+
protected ExtensibleJsonObject(IDictionary<string, JToken> extensionData)
49+
{
50+
if (extensionData == null)
51+
throw new ArgumentNullException("extensionData");
52+
53+
if (extensionData.Count > 0)
54+
_extensionData = new Dictionary<string, JToken>(extensionData);
55+
}
56+
57+
/// <summary>
58+
/// Initializes a new instance of the <see cref="ExtensibleJsonObject"/> class
59+
/// with the specified extension data.
60+
/// </summary>
61+
/// <param name="extensionData">The extension data.</param>
62+
/// <exception cref="ArgumentNullException">If <paramref name="extensionData"/> is <see langword="null"/>.</exception>
63+
/// <exception cref="ArgumentException">If <paramref name="extensionData"/> contains any <see langword="null"/> values.</exception>
64+
protected ExtensibleJsonObject(IEnumerable<JProperty> extensionData)
65+
: this(extensionData.ToArray())
66+
{
67+
}
68+
69+
/// <summary>
70+
/// Initializes a new instance of the <see cref="ExtensibleJsonObject"/> class
71+
/// with the specified extension data.
72+
/// </summary>
73+
/// <param name="extensionData">The extension data.</param>
74+
/// <exception cref="ArgumentNullException">If <paramref name="extensionData"/> is <see langword="null"/>.</exception>
75+
/// <exception cref="ArgumentException">If <paramref name="extensionData"/> contains any <see langword="null"/> values.</exception>
76+
protected ExtensibleJsonObject(params JProperty[] extensionData)
77+
{
78+
if (extensionData == null)
79+
throw new ArgumentNullException("extensionData");
80+
81+
if (extensionData.Length > 0)
82+
{
83+
_extensionData = new Dictionary<string, JToken>();
84+
foreach (JProperty property in extensionData)
85+
{
86+
if (property == null)
87+
throw new ArgumentException("extensionData cannot contain any null values");
88+
89+
_extensionData[property.Name] = property.Value;
90+
}
91+
}
92+
}
93+
94+
/// <summary>
95+
/// Gets a map of object properties which did not map to another field or property
96+
/// during JSON deserialization. The keys of the map represent the property names,
97+
/// and the values are <see cref="JToken"/> instances containing the parsed JSON
98+
/// values.
99+
/// </summary>
100+
/// <value>
101+
/// A collection of object properties which did not map to another field or property
102+
/// during JSON deserialization.
103+
/// <para>-or-</para>
104+
/// <para>An empty dictionary if the object did not contain any unmapped properties.</para>
105+
/// </value>
106+
public ReadOnlyDictionary<string, JToken> ExtensionData
107+
{
108+
get
109+
{
110+
if (_extensionData == null)
111+
return EmptyExtensionData;
112+
113+
return new ReadOnlyDictionary<string, JToken>(_extensionData);
114+
}
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)