diff --git a/CBOR.nuspec b/CBOR.nuspec index 9fc8f991..2ef4e366 100644 --- a/CBOR.nuspec +++ b/CBOR.nuspec @@ -1,5 +1,5 @@ 4.4.2PeterO.CborfalseVersion 4.4.2: +>4.5PeterO.CborfalseVersion 4.4.2: - Performance improvements in some cases, especially involving date/time conversions - Error checks in DateTimeFieldsToCBORObject method in CBORDateConverter @@ -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 fixesCC0-1.0https://github.com/peteroupc/CBORPeter OccilA C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949.Peter OccilCBOR (Concise Binary Object Representation)cbor data serialization binary jsonCC0-1.0https://github.com/peteroupc/CBORPeter OccilA C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949.Peter OccilCBOR (Concise Binary Object Representation)cbor data serialization binary json diff --git a/CBOR/CBOR.csproj b/CBOR/CBOR.csproj index 6e7536c5..3bf0954d 100644 --- a/CBOR/CBOR.csproj +++ b/CBOR/CBOR.csproj @@ -56,6 +56,6 @@ Version 4.4: - + diff --git a/CBOR/PeterO/Cbor/CBORObject.cs b/CBOR/PeterO/Cbor/CBORObject.cs index 310482e1..2f6b4fa2 100644 --- a/CBOR/PeterO/Cbor/CBORObject.cs +++ b/CBOR/PeterO/Cbor/CBORObject.cs @@ -1646,93 +1646,97 @@ public object ToObject(Type t, PODOptions options) { /// 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. - /// If the type is List or - /// the generic or non-generic IList, ICollection, or IEnumerable, (or + /// 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. /// 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. - /// 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.) - /// If the type is DateTime + /// 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. + /// 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.) + /// If the type is + /// DateTime /// (or Date - /// 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 DateTime - /// and Date - /// can be changed by passing a suitable CBORTypeMapper - /// to this method, such as a CBORTypeMapper that registers a - /// CBORDateConverter for DateTime + /// 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 DateTime + /// and Date + /// can be changed + /// by passing a suitable CBORTypeMapper to this method, such as a + /// CBORTypeMapper that registers a CBORDateConverter for + /// DateTime /// or Date - /// objects. See - /// the examples. - /// If the type is Uri + /// objects. See the examples. + /// If the type is Uri /// (or URI - /// in Java), returns a URI object if possible. - /// If the - /// type is Guid - /// (or UUID - /// in Java), returns a UUID object - /// if possible. - /// 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: - /// (*) 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- const - /// , non- readonly - /// 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. - /// (*) 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. - /// 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 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. + /// in Java), returns a + /// URI object if possible. + /// If the type is Guid + /// (or + /// UUID + /// in Java), returns a UUID object if possible. + /// 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: + /// (*) 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- const + /// , non- readonly + /// 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. + /// (*) 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. + /// 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 + /// 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. /// - /// + /// /// The type, class, or interface that this method's /// return value will belong to. To express a generic type in Java, see /// the example. Note: diff --git a/CBOR/PeterO/Cbor/PropertyMap.cs b/CBOR/PeterO/Cbor/PropertyMap.cs index 8c93bd8a..ce82517f 100644 --- a/CBOR/PeterO/Cbor/PropertyMap.cs +++ b/CBOR/PeterO/Cbor/PropertyMap.cs @@ -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<>)) || @@ -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(); @@ -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 = @@ -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( diff --git a/CBORTest/CBORTest.csproj b/CBORTest/CBORTest.csproj index 0e7fa0a2..f9cb08d7 100644 --- a/CBORTest/CBORTest.csproj +++ b/CBORTest/CBORTest.csproj @@ -25,6 +25,6 @@ all - +