Closed LightCZ closed 3 years ago
@LightCZ do you have an example of the exception + stack trace?
Code right now should return "null" if description is not there.
/// <summary>
/// Gets a specific <see cref="Field"/> from the <see cref="Fields"/> collection.
/// </summary>
/// <param name="fieldName">The name of the <see cref="Field"/> to get.</param>
/// <returns><see cref="Field"/> matching the <paramref name="fieldName"/>; null when not found.</returns>
public Field GetField(string fieldName)
{
return _fields.TryGetValue(fieldName, out var field) ? field : null;
}
/// <summary>
/// Summary of the issue.
/// </summary>
public string Summary {
get
{
var field = GetField("Summary");
return field?.Value?.ToString();
}
set => SetField("Summary", value);
}
/// <summary>
/// Description of the issue.
/// </summary>
public string Description {
get
{
var field = GetField("Description");
return field?.Value?.ToString();
}
set => SetField("Description", value);
}
fixed in my fork if required SteveHaine/YouTrackSharp
@SteveHaine thanks a lot! I took a liberty to copy your change wrt Issue.GetField, Issue.Summary and Issue.Description to 2021.3.1 (mind that it requires migration described in 2021.3.0)
I don't think cherry-picking this to 2020.* is needed at this time, but we could consider releasing a bugfix for previous versions if someone requests it.
When you load Issues and you receive an issue without description (and yes that could happen) This method will fail when Description is not existent (the same will be for all properties)
public string Description { get { var field = GetField("Description"); return field?.Value.ToString(); } set => SetField("Description", value); }
public Field GetField(string fieldName) { _fields.TryGetValue(fieldName, out var field); //when this returns false it should not be ignored!!!! return field; }