Skip to content

Commit

Permalink
Adjust DTO accessors to make them public (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
torbacz authored Nov 14, 2022
1 parent 60be3f4 commit eba39fd
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 56 deletions.
21 changes: 15 additions & 6 deletions nanoFramework.Json/JsonArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@

namespace nanoFramework.Json
{
internal class JsonArray : JsonToken
/// <summary>
/// Represents array of objects from JSON string.
/// </summary>
public sealed class JsonArray : JsonToken
{
public JsonArray()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="JsonArray" /> class.
/// </summary>
/// <param name="values">Initial <see cref="JsonToken"/> array.</param>
public JsonArray(JsonToken[] values)
{
Items = values;
}


/// <summary>
/// Gets the lenght of <see cref="Items"/> array.
/// </summary>
public int Length => Items.Length;

/// <summary>
/// Gets collection of <see cref="JsonToken"/>.
/// </summary>
public JsonToken[] Items { get; }
}
}
25 changes: 23 additions & 2 deletions nanoFramework.Json/JsonObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,36 @@

namespace nanoFramework.Json
{
internal class JsonObject : JsonToken
/// <summary>
/// Represents single JSON object that contains multiple JSON properties.
/// </summary>
public sealed class JsonObject : JsonToken
{
private readonly Hashtable _members = new();

/// <summary>
/// Gets the collection of values from <see cref="_members"/>.
/// </summary>
public ICollection Members => _members.Values;

/// <summary>
/// Adds new key value pair to collection.
/// </summary>
/// <param name="name">JSON property key.</param>
/// <param name="value">JSON property value.</param>
public void Add(string name, JsonToken value)
{
_members.Add(name.ToLower(), new JsonProperty(name, value));
_members.Add(name, new JsonProperty(name, value));
}

/// <summary>
/// Gets the value of property for given key.
/// </summary>
/// <param name="name">JSON property key.</param>
/// <returns>JsonProperty object which contains key and value of object.</returns>
public JsonProperty Get(string name)
{
return (JsonProperty)_members[name];
}
}
}
25 changes: 18 additions & 7 deletions nanoFramework.Json/JsonProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@

namespace nanoFramework.Json
{
internal class JsonProperty : JsonToken
/// <summary>
/// Represents single JSON key value pair.
/// </summary>
public sealed class JsonProperty : JsonToken
{
public JsonProperty()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="JsonProperty" /> class.
/// </summary>
/// <param name="name">JSON property key.</param>
/// <param name="value">JSON property value.</param>
public JsonProperty(string name, JsonToken value)
{
Name = name;
Value = value;
}

public string Name { get; set; }
public JsonToken Value { get; set; }
/// <summary>
/// Gets key of JSON property.
/// </summary>
public string Name { get; }

/// <summary>
/// Gets value of Json property.
/// </summary>
public JsonToken Value { get; }
}
}
41 changes: 5 additions & 36 deletions nanoFramework.Json/JsonToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,11 @@

namespace nanoFramework.Json
{
internal abstract class JsonToken
/// <summary>
/// Base class for all Json structures.
/// </summary>
public abstract class JsonToken
{
public static string ConvertToString(byte[] byteArray, int start, int count)
{
var _chars = new char[byteArray.Length];

Encoding.UTF8.GetDecoder().Convert(
byteArray,
start,
count,
_chars,
0,
byteArray.Length,
false,
out _,
out int _charsUsed,
out _);

return new string(_chars, 0, _charsUsed);
}

public static int FindNul(byte[] buffer, int start)
{
int current = start;

while (current < buffer.Length)
{
if (buffer[current++] != 0)
{
continue;
}

return current - 1;
}

return -1;
}

}
}
18 changes: 13 additions & 5 deletions nanoFramework.Json/JsonValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

namespace nanoFramework.Json
{
internal class JsonValue : JsonToken
/// <summary>
/// Represents single object from JSON string.
/// </summary>
public sealed class JsonValue : JsonToken
{
public JsonValue()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="JsonValue" /> class.
/// </summary>
/// <param name="value">Value of current JSON object.</param>
/// <param name="isDateTime">Is the type of value DateTime.</param>
public JsonValue(object value, bool isDateTime = false)
{
if (isDateTime)
Expand All @@ -29,6 +34,9 @@ public JsonValue(object value, bool isDateTime = false)
}
}

public object Value { get; set; }
/// <summary>
/// Gets or sets object value.
/// </summary>
public object Value { get; }
}
}

0 comments on commit eba39fd

Please sign in to comment.