Skip to content

Commit 9c54535

Browse files
authored
Merge pull request #364 from json-api-dotnet/chore/docs
doc(Identifiable): add xml docs
2 parents 74667eb + 5f4a91d commit 9c54535

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/JsonApiDotNetCore/Models/Identifiable.cs

+25-5
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,55 @@
55
namespace JsonApiDotNetCore.Models
66
{
77
public class Identifiable : Identifiable<int>
8-
{}
9-
8+
{ }
9+
1010
public class Identifiable<T> : IIdentifiable<T>
1111
{
12+
/// <summary>
13+
/// The resource identifier
14+
/// </summary>
1215
public virtual T Id { get; set; }
1316

17+
/// <summary>
18+
/// The string representation of the `Id`.
19+
///
20+
/// This is used in serialization and deserialization.
21+
/// The getters should handle the conversion
22+
/// from `typeof(T)` to a string and the setter vice versa.
23+
///
24+
/// To override this behavior, you can either implement the
25+
/// <see cref="IIdentifiable{T}"> interface directly or override
26+
/// `GetStringId` and `GetTypedId` methods.
27+
/// </summary>
1428
[NotMapped]
1529
public string StringId
1630
{
1731
get => GetStringId(Id);
1832
set => Id = GetTypedId(value);
1933
}
2034

35+
/// <summary>
36+
/// Convert the provided resource identifier to a string.
37+
/// </summary>
2138
protected virtual string GetStringId(object value)
2239
{
2340
var type = typeof(T);
2441
var stringValue = value.ToString();
2542

26-
if(type == typeof(Guid))
43+
if (type == typeof(Guid))
2744
{
2845
var guid = Guid.Parse(stringValue);
2946
return guid == Guid.Empty ? string.Empty : stringValue;
3047
}
3148

32-
return stringValue == "0"
33-
? string.Empty
49+
return stringValue == "0"
50+
? string.Empty
3451
: stringValue;
3552
}
3653

54+
/// <summary>
55+
/// Convert a string to a typed resource identifier.
56+
/// </summary>
3757
protected virtual T GetTypedId(string value)
3858
{
3959
var convertedValue = TypeHelper.ConvertType(value, typeof(T));

0 commit comments

Comments
 (0)