From 5f4a91d0e144c1f37dc4ada6657a25a78bb7cb4e Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Tue, 31 Jul 2018 21:27:13 -0700 Subject: [PATCH] doc(Identifiable): add xml docs --- src/JsonApiDotNetCore/Models/Identifiable.cs | 30 ++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/JsonApiDotNetCore/Models/Identifiable.cs b/src/JsonApiDotNetCore/Models/Identifiable.cs index 703cc2f051..08dd43bf22 100644 --- a/src/JsonApiDotNetCore/Models/Identifiable.cs +++ b/src/JsonApiDotNetCore/Models/Identifiable.cs @@ -5,12 +5,26 @@ namespace JsonApiDotNetCore.Models { public class Identifiable : Identifiable - {} - + { } + public class Identifiable : IIdentifiable { + /// + /// The resource identifier + /// public virtual T Id { get; set; } + /// + /// The string representation of the `Id`. + /// + /// This is used in serialization and deserialization. + /// The getters should handle the conversion + /// from `typeof(T)` to a string and the setter vice versa. + /// + /// To override this behavior, you can either implement the + /// interface directly or override + /// `GetStringId` and `GetTypedId` methods. + /// [NotMapped] public string StringId { @@ -18,22 +32,28 @@ public string StringId set => Id = GetTypedId(value); } + /// + /// Convert the provided resource identifier to a string. + /// protected virtual string GetStringId(object value) { var type = typeof(T); var stringValue = value.ToString(); - if(type == typeof(Guid)) + if (type == typeof(Guid)) { var guid = Guid.Parse(stringValue); return guid == Guid.Empty ? string.Empty : stringValue; } - return stringValue == "0" - ? string.Empty + return stringValue == "0" + ? string.Empty : stringValue; } + /// + /// Convert a string to a typed resource identifier. + /// protected virtual T GetTypedId(string value) { var convertedValue = TypeHelper.ConvertType(value, typeof(T));