diff --git a/src/redmine-net-api/RedmineKeys.cs b/src/redmine-net-api/RedmineKeys.cs index 5bd7661e..8cc70a16 100644 --- a/src/redmine-net-api/RedmineKeys.cs +++ b/src/redmine-net-api/RedmineKeys.cs @@ -67,7 +67,7 @@ public static class RedmineKeys /// /// /// - public const string ASSIGNABLE = "Assignable"; + public const string ASSIGNABLE = "assignable"; /// /// /// diff --git a/src/redmine-net-api/Serialization/Xml/Extensions/XmlReaderExtensions.cs b/src/redmine-net-api/Serialization/Xml/Extensions/XmlReaderExtensions.cs index f0312351..1c762b1a 100644 --- a/src/redmine-net-api/Serialization/Xml/Extensions/XmlReaderExtensions.cs +++ b/src/redmine-net-api/Serialization/Xml/Extensions/XmlReaderExtensions.cs @@ -87,6 +87,23 @@ public static bool ReadAttributeAsBoolean(this XmlReader reader, string attribut return result; } + /// + /// Reads the element content as nullable boolean. + /// + /// The reader. + /// + public static bool? ReadElementContentAsNullableBoolean(this XmlReader reader) + { + var content = reader.ReadElementContentAsString(); + + if (content.IsNullOrWhiteSpace() || !bool.TryParse(content, out var result)) + { + return null; + } + + return result; + } + /// /// Reads the element content as nullable date time. /// diff --git a/src/redmine-net-api/Types/Permission.cs b/src/redmine-net-api/Types/Permission.cs index 3a658453..fcfcbbf1 100644 --- a/src/redmine-net-api/Types/Permission.cs +++ b/src/redmine-net-api/Types/Permission.cs @@ -77,23 +77,9 @@ public void WriteXml(XmlWriter writer) { } /// public void ReadJson(JsonReader reader) { - while (reader.Read()) + if (reader.TokenType == JsonToken.String) { - if (reader.TokenType == JsonToken.EndObject) - { - return; - } - - if (reader.TokenType != JsonToken.PropertyName) - { - continue; - } - - switch (reader.Value) - { - case RedmineKeys.PERMISSION: Info = reader.ReadAsString(); break; - default: reader.Read(); break; - } + Info = reader.Value as string; } } diff --git a/src/redmine-net-api/Types/Role.cs b/src/redmine-net-api/Types/Role.cs index 366ce69e..40ac4122 100644 --- a/src/redmine-net-api/Types/Role.cs +++ b/src/redmine-net-api/Types/Role.cs @@ -1,4 +1,4 @@ -/* +/* Copyright 2011 - 2023 Adrian Popescu Licensed under the Apache License, Version 2.0 (the "License"); @@ -59,7 +59,7 @@ public sealed class Role : IdentifiableName, IEquatable /// /// /// - public bool IsAssignable { get; set; } + public bool? IsAssignable { get; set; } #endregion #region Implementation of IXmlSerialization @@ -82,6 +82,7 @@ public override void ReadXml(XmlReader reader) { case RedmineKeys.ID: Id = reader.ReadElementContentAsInt(); break; case RedmineKeys.NAME: Name = reader.ReadElementContentAsString(); break; + case RedmineKeys.ASSIGNABLE: IsAssignable = reader.ReadElementContentAsNullableBoolean(); break; case RedmineKeys.PERMISSIONS: Permissions = reader.ReadElementContentAsCollection(); break; default: reader.Read(); break; } @@ -113,6 +114,7 @@ public override void ReadJson(JsonReader reader) { case RedmineKeys.ID: Id = reader.ReadAsInt(); break; case RedmineKeys.NAME: Name = reader.ReadAsString(); break; + case RedmineKeys.ASSIGNABLE: IsAssignable = reader.ReadAsBoolean(); break; case RedmineKeys.PERMISSIONS: Permissions = reader.ReadAsCollection(); break; default: reader.Read(); break; } @@ -129,7 +131,11 @@ public override void ReadJson(JsonReader reader) public bool Equals(Role other) { if (other == null) return false; - return Id == other.Id && Name == other.Name; + return EqualityComparer.Default.Equals(Id, other.Id) && + EqualityComparer.Default.Equals(Name, other.Name) && + IsAssignable == other.IsAssignable && + EqualityComparer>.Default.Equals(Permissions, other.Permissions); + } /// @@ -156,6 +162,7 @@ public override int GetHashCode() var hashCode = 13; hashCode = HashCodeHelper.GetHashCode(Id, hashCode); hashCode = HashCodeHelper.GetHashCode(Name, hashCode); + hashCode = HashCodeHelper.GetHashCode(IsAssignable, hashCode); hashCode = HashCodeHelper.GetHashCode(Permissions, hashCode); return hashCode; }