Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #364 #367

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/redmine-net-api/RedmineKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static class RedmineKeys
/// <summary>
///
/// </summary>
public const string ASSIGNABLE = "Assignable";
public const string ASSIGNABLE = "assignable";
/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ public static bool ReadAttributeAsBoolean(this XmlReader reader, string attribut
return result;
}

/// <summary>
/// Reads the element content as nullable boolean.
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns></returns>
public static bool? ReadElementContentAsNullableBoolean(this XmlReader reader)
{
var content = reader.ReadElementContentAsString();

if (content.IsNullOrWhiteSpace() || !bool.TryParse(content, out var result))
{
return null;
}

return result;
}

/// <summary>
/// Reads the element content as nullable date time.
/// </summary>
Expand Down
18 changes: 2 additions & 16 deletions src/redmine-net-api/Types/Permission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,9 @@ public void WriteXml(XmlWriter writer) { }
/// <param name="reader"></param>
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;
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/redmine-net-api/Types/Role.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
Copyright 2011 - 2023 Adrian Popescu

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -59,7 +59,7 @@ public sealed class Role : IdentifiableName, IEquatable<Role>
/// <summary>
///
/// </summary>
public bool IsAssignable { get; set; }
public bool? IsAssignable { get; set; }
#endregion

#region Implementation of IXmlSerialization
Expand All @@ -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<Permission>(); break;
default: reader.Read(); break;
}
Expand Down Expand Up @@ -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<Permission>(); break;
default: reader.Read(); break;
}
Expand All @@ -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<int>.Default.Equals(Id, other.Id) &&
EqualityComparer<string>.Default.Equals(Name, other.Name) &&
IsAssignable == other.IsAssignable &&
EqualityComparer<IList<Permission>>.Default.Equals(Permissions, other.Permissions);

}

/// <summary>
Expand All @@ -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;
}
Expand Down
Loading