Skip to content

Commit

Permalink
Minor edits; adjust Numbers dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Dec 7, 2021
1 parent 833ae34 commit a2c6f3f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 87 deletions.
4 changes: 2 additions & 2 deletions CBOR.nuspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<package
><metadata><version>4.4.2</version><id>PeterO.Cbor</id><requireLicenseAcceptance>false</requireLicenseAcceptance><releaseNotes>Version 4.4.2:
><metadata><version>4.5</version><id>PeterO.Cbor</id><requireLicenseAcceptance>false</requireLicenseAcceptance><releaseNotes>Version 4.4.2:

- Performance improvements in some cases, especially involving date/time conversions
- Error checks in DateTimeFieldsToCBORObject method in CBORDateConverter
Expand All @@ -16,5 +16,5 @@ Version 4.4:
- CBORDateConverter made public and expanded to enable conversion between various
date/time formats and CBOR objects
- Added CanFitInUInt64 and CanTruncatedIntFitInUInt64 methods
- Bug fixes</releaseNotes><summary></summary><license type='expression'>CC0-1.0</license><projectUrl>https://github.com/peteroupc/CBOR</projectUrl><authors>Peter Occil</authors><description>A C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949.</description><owners>Peter Occil</owners><title>CBOR (Concise Binary Object Representation)</title><tags>cbor data serialization binary json</tags><dependencies><group targetFramework='.NETStandard1.0'><dependency id='PeterO.URIUtility' version='1.0.0' /><dependency id='PeterO.Numbers' version='1.8.0' /></group><group targetFramework='.NETFramework2.0'><dependency id='PeterO.URIUtility' version='1.0.0' /><dependency id='PeterO.Numbers' version='1.8.0' /></group><group targetFramework='.NETFramework4.0'><dependency id='PeterO.URIUtility' version='1.0.0' /><dependency id='PeterO.Numbers' version='1.8.0' /></group></dependencies></metadata><files><file src='CBOR/bin/Release/netstandard1.0/CBOR.dll' target='/lib/netstandard1.0' /><file src='CBOR/bin/Release/netstandard1.0/CBOR.xml' target='/lib/netstandard1.0' /><file src='CBOR20/bin/Release/CBOR.dll' target='/lib/net20' /><file src='CBOR20/bin/Release/CBOR.xml' target='/lib/net20' /><file src='CBOR40/bin/Release/CBOR.dll' target='/lib/net40' /><file src='CBOR40/bin/Release/CBOR.xml' target='/lib/net40' /></files></package
- Bug fixes</releaseNotes><summary></summary><license type='expression'>CC0-1.0</license><projectUrl>https://github.com/peteroupc/CBOR</projectUrl><authors>Peter Occil</authors><description>A C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949.</description><owners>Peter Occil</owners><title>CBOR (Concise Binary Object Representation)</title><tags>cbor data serialization binary json</tags><dependencies><group targetFramework='.NETStandard1.0'><dependency id='PeterO.URIUtility' version='1.0.0' /><dependency id='PeterO.Numbers' version='1.8.1' /></group><group targetFramework='.NETFramework2.0'><dependency id='PeterO.URIUtility' version='1.0.0' /><dependency id='PeterO.Numbers' version='1.8.1' /></group><group targetFramework='.NETFramework4.0'><dependency id='PeterO.URIUtility' version='1.0.0' /><dependency id='PeterO.Numbers' version='1.8.1' /></group></dependencies></metadata><files><file src='CBOR/bin/Release/netstandard1.0/CBOR.dll' target='/lib/netstandard1.0' /><file src='CBOR/bin/Release/netstandard1.0/CBOR.xml' target='/lib/netstandard1.0' /><file src='CBOR20/bin/Release/CBOR.dll' target='/lib/net20' /><file src='CBOR20/bin/Release/CBOR.xml' target='/lib/net20' /><file src='CBOR40/bin/Release/CBOR.dll' target='/lib/net40' /><file src='CBOR40/bin/Release/CBOR.xml' target='/lib/net40' /></files></package
>
2 changes: 1 addition & 1 deletion CBOR/CBOR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ Version 4.4:
<AdditionalFiles Include='stylecop.json'/>
<AdditionalFiles Include='rules.ruleset'/><PackageReference Include='PeterO.URIUtility' Version='1.0.0'/>

<PackageReference Include='PeterO.Numbers' Version='1.8.1'/>
<PackageReference Include='PeterO.Numbers' Version='1.8.2'/>
<PackageReference Include='Microsoft.CodeAnalysis.NetAnalyzers' PrivateAssets='All' Version='5.0.3'/></ItemGroup>
</Project>
160 changes: 82 additions & 78 deletions CBOR/PeterO/Cbor/CBORObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,93 +1646,97 @@ public object ToObject(Type t, PODOptions options) {
/// <item>If the type is a one-dimensional or multidimensional array
/// type and this CBOR object is an array, returns an array containing
/// the items in this CBOR object.</item>
/// <item>If the type is List or
/// the generic or non-generic IList, ICollection, or IEnumerable, (or
/// <item>If the type is List,
/// ReadOnlyCollection or the generic or non-generic IList,
/// ICollection, IEnumerable, IReadOnlyCollection, or IReadOnlyList (or
/// ArrayList, List, Collection, or Iterable in Java), and if this CBOR
/// object is an array, returns an object conforming to the type,
/// class, or interface passed to this method, where the object will
/// contain all items in this CBOR array.</item>
/// <item>If the type is
/// Dictionary or the generic or non-generic IDictionary (or HashMap or
/// Map in Java), and if this CBOR object is a map, returns an object
/// conforming to the type, class, or interface passed to this method,
/// where the object will contain all keys and values in this CBOR
/// map.</item>
/// <item>If the type is an enumeration constant ("enum"),
/// and this CBOR object is an integer or text string, returns the
/// enumeration constant with the given number or name, respectively.
/// (Enumeration constants made up of multiple enumeration constants,
/// as allowed by .NET, can only be matched by number this way.)</item>
/// <item>If the type is <c>DateTime</c>
/// Dictionary, ReadOnlyDictionary or the generic or non-generic
/// IDictionary or IReadOnlyDictionary (or HashMap or Map in Java), and
/// if this CBOR object is a map, returns an object conforming to the
/// type, class, or interface passed to this method, where the object
/// will contain all keys and values in this CBOR map.</item>
/// <item>If
/// the type is an enumeration constant ("enum"), and this CBOR object
/// is an integer or text string, returns the enumeration constant with
/// the given number or name, respectively. (Enumeration constants made
/// up of multiple enumeration constants, as allowed by .NET, can only
/// be matched by number this way.)</item>
/// <item>If the type is
/// <c>DateTime</c>
/// (or <c>Date</c>
/// in Java) ,
/// returns a date/time object if the CBOR object's outermost tag is 0
/// or 1. For tag 1, this method treats the CBOR object as a number of
/// seconds since the start of 1970, which is based on the POSIX
/// definition of "seconds since the Epoch", a definition that does not
/// count leap seconds. In this method, this number of seconds assumes
/// the use of a proleptic Gregorian calendar, in which the rules
/// regarding the number of days in each month and which years are leap
/// years are the same for all years as they were in 1970 (including
/// without regard to time zone differences or transitions from other
/// calendars to the Gregorian). The string format used in tag 0
/// supports only years up to 4 decimal digits long. For tag 1, CBOR
/// objects that express infinity or not-a-number (NaN) are treated as
/// invalid by this method. This default behavior for <c>DateTime</c>
/// and <c>Date</c>
/// can be changed by passing a suitable CBORTypeMapper
/// to this method, such as a CBORTypeMapper that registers a
/// CBORDateConverter for <c>DateTime</c>
/// in Java) , returns a date/time
/// object if the CBOR object's outermost tag is 0 or 1. For tag 1,
/// this method treats the CBOR object as a number of seconds since the
/// start of 1970, which is based on the POSIX definition of "seconds
/// since the Epoch", a definition that does not count leap seconds. In
/// this method, this number of seconds assumes the use of a proleptic
/// Gregorian calendar, in which the rules regarding the number of days
/// in each month and which years are leap years are the same for all
/// years as they were in 1970 (including without regard to time zone
/// differences or transitions from other calendars to the Gregorian).
/// The string format used in tag 0 supports only years up to 4 decimal
/// digits long. For tag 1, CBOR objects that express infinity or
/// not-a-number (NaN) are treated as invalid by this method. This
/// default behavior for <c>DateTime</c>
/// and <c>Date</c>
/// can be changed
/// by passing a suitable CBORTypeMapper to this method, such as a
/// CBORTypeMapper that registers a CBORDateConverter for
/// <c>DateTime</c>
/// or <c>Date</c>
/// objects. See
/// the examples.</item>
/// <item>If the type is <c>Uri</c>
/// objects. See the examples.</item>
/// <item>If the type is <c>Uri</c>
/// (or <c>URI</c>
/// in Java), returns a URI object if possible.</item>
/// <item>If the
/// type is <c>Guid</c>
/// (or <c>UUID</c>
/// in Java), returns a UUID object
/// if possible.</item>
/// <item>Plain-Old-Data deserialization: If the
/// object is a type not specially handled above, the type includes a
/// zero-parameter constructor (default or not), this CBOR object is a
/// CBOR map, and the "mapper" parameter (if any) allows this type to
/// be eligible for Plain-Old-Data deserialization, then this method
/// checks the given type for eligible setters as follows:</item>
/// <item>(*) In the .NET version, eligible setters are the public,
/// nonstatic setters of properties with a public, nonstatic getter.
/// Eligible setters also include public, nonstatic, non- <c>const</c>
/// , non- <c>readonly</c>
/// fields. If a class has two properties and/or
/// fields of the form "X" and "IsX", where "X" is any name, or has
/// multiple properties and/or fields with the same name, those
/// properties and fields are ignored.</item>
/// <item>(*) In the Java
/// version, eligible setters are public, nonstatic methods starting
/// with "set" followed by a character other than a basic digit or
/// lower-case letter, that is, other than "a" to "z" or "0" to "9",
/// that take one parameter. The class containing an eligible setter
/// must have a public, nonstatic method with the same name, but
/// starting with "get" or "is" rather than "set", that takes no
/// parameters and does not return void. (For example, if a class has
/// "public setValue(String)" and "public getValue()", "setValue" is an
/// eligible setter. However, "setValue()" and "setValue(String, int)"
/// are not eligible setters.) In addition, public, nonstatic, nonfinal
/// fields are also eligible setters. If a class has two or more
/// otherwise eligible setters (methods and/or fields) with the same
/// name, but different parameter type, they are not eligible
/// setters.</item>
/// <item>Then, the method creates an object of the
/// given type and invokes each eligible setter with the corresponding
/// value in the CBOR map, if any. Key names in the map are matched to
/// eligible setters according to the rules described in the <see
/// cref='PeterO.Cbor.PODOptions'/> documentation. Note that for
/// security reasons, certain types are not supported even if they
/// contain eligible setters. For the Java version, the object creation
/// may fail in the case of a nested nonstatic class.</item>
/// in Java), returns a
/// URI object if possible.</item>
/// <item>If the type is <c>Guid</c>
/// (or
/// <c>UUID</c>
/// in Java), returns a UUID object if possible.</item>
/// <item>Plain-Old-Data deserialization: If the object is a type not
/// specially handled above, the type includes a zero-parameter
/// constructor (default or not), this CBOR object is a CBOR map, and
/// the "mapper" parameter (if any) allows this type to be eligible for
/// Plain-Old-Data deserialization, then this method checks the given
/// type for eligible setters as follows:</item>
/// <item>(*) In the .NET
/// version, eligible setters are the public, nonstatic setters of
/// properties with a public, nonstatic getter. Eligible setters also
/// include public, nonstatic, non- <c>const</c>
/// , non- <c>readonly</c>
/// fields. If a class has two properties and/or fields of the form "X"
/// and "IsX", where "X" is any name, or has multiple properties and/or
/// fields with the same name, those properties and fields are
/// ignored.</item>
/// <item>(*) In the Java version, eligible setters are
/// public, nonstatic methods starting with "set" followed by a
/// character other than a basic digit or lower-case letter, that is,
/// other than "a" to "z" or "0" to "9", that take one parameter. The
/// class containing an eligible setter must have a public, nonstatic
/// method with the same name, but starting with "get" or "is" rather
/// than "set", that takes no parameters and does not return void. (For
/// example, if a class has "public setValue(String)" and "public
/// getValue()", "setValue" is an eligible setter. However,
/// "setValue()" and "setValue(String, int)" are not eligible setters.)
/// In addition, public, nonstatic, nonfinal fields are also eligible
/// setters. If a class has two or more otherwise eligible setters
/// (methods and/or fields) with the same name, but different parameter
/// type, they are not eligible setters.</item>
/// <item>Then, the method
/// creates an object of the given type and invokes each eligible
/// setter with the corresponding value in the CBOR map, if any. Key
/// names in the map are matched to eligible setters according to the
/// rules described in the <see cref='PeterO.Cbor.PODOptions'/>
/// documentation. Note that for security reasons, certain types are
/// not supported even if they contain eligible setters. For the Java
/// version, the object creation may fail in the case of a nested
/// nonstatic class.</item>
/// </list>
/// </summary>
/// </summary>
/// <param name='t'>The type, class, or interface that this method's
/// return value will belong to. To express a generic type in Java, see
/// the example. <b>Note:</b>
Expand Down
8 changes: 3 additions & 5 deletions CBOR/PeterO/Cbor/PropertyMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ public static object TypeToObject(
isList = td.Equals(typeof(List<>)) || td.Equals(typeof(IList<>)) ||
td.Equals(typeof(ICollection<>)) ||
td.Equals(typeof(IEnumerable<>));
#if NET20
#if NET20 || NET40
isReadOnlyCollection = false;
#else
isReadOnlyCollection = (td.Equals(typeof(IReadOnlyCollection<>)) ||
Expand All @@ -1119,8 +1119,6 @@ public static object TypeToObject(
listObject = Activator.CreateInstance(listType);
}
#else
// TODO: Document new support of IReadOnlyCollection/IReadOnlyList
// and add tests
// TODO: Support IReadOnlyDictionary
if (t.GetTypeInfo().IsGenericType) {
Type td = t.GetGenericTypeDefinition();
Expand Down Expand Up @@ -1216,7 +1214,7 @@ public static object TypeToObject(
Type td = t.GetGenericTypeDefinition();
isDict = td.Equals(typeof(Dictionary<,>)) ||
td.Equals(typeof(IDictionary<,>));
#if NET20
#if NET20 || NET40
isReadOnlyDict = false;
#else
isReadOnlyDict =
Expand Down Expand Up @@ -1275,7 +1273,7 @@ public static object TypeToObject(
key.ToObject(keyType, mapper, options, depth + 1),
value.ToObject(valueType, mapper, options, depth + 1));
}
#if !NET20
#if !NET20 && !NET40
if (isReadOnlyDict) {
Type listType =
typeof(
Expand Down
2 changes: 1 addition & 1 deletion CBORTest/CBORTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include='StyleCop.Analyzers' PrivateAssets='All' Version='1.2.0-beta.354'/>
<PackageReference Include='PeterO.Numbers' Version='1.8.1'/>
<PackageReference Include='PeterO.Numbers' Version='1.8.2'/>
</ItemGroup>
</Project>

0 comments on commit a2c6f3f

Please sign in to comment.