diff --git a/sdks/thunderpay-sdk-cs/Resource.cs b/sdks/thunderpay-sdk-cs/Resource.cs index 77f6b8e..c73a6ba 100644 --- a/sdks/thunderpay-sdk-cs/Resource.cs +++ b/sdks/thunderpay-sdk-cs/Resource.cs @@ -12,35 +12,52 @@ using System; using System.Linq; using System.Text; -using System.Threading.Tasks; -using System.Collections; -using Newtonsoft.Json; using System.Dynamic; using System.Reflection; using System.Collections.Generic; -using System.Runtime.Serialization; +using System.Threading.Tasks; +using System.Collections; +using Newtonsoft.Json; namespace ThunderPay { public abstract class Resource { - [ResourceField(seialize = false)] + [ResourceField(serialize = false)] public string href { get; set; - } + } // public string href [ResourceField(serialize = false)] public string id { get; set; - } + } // public string id [ResourceField] public Dictionary links { get; set; - } + } // public Dictionary links + + [ResourceField] + public Dictionary meta + { + get; set; + } // public Dictionary meta + + [ResourceField(serialize = false)] + public DateTime created_at + { + get; set; + } // public DateTime created_at + + [ResourceField(serialize = false)] + public DateTime updated_at + { + get; set; + } // public DateTime updaetd_at public Resource() { } @@ -54,12 +71,54 @@ public void Save() } else { - string href = this.GetType().GetProperties("resource_href").GetValue(this).ToString(); + string href = this.GetType().GetProperty("resource_href").GetValue(this).ToString(); res = Client.Post(href, Serialize(this)); } UpdateResource(res); - } - } + } // public void Save() + + public void Unstore() + { + Client.Delete(this.href); + } // publid void Unstore() + + public static T Fetch(string href) + { + return Client.Get(href); + } // public static T Fetch(string href) + + public void Reload() + { + dynamic res = Client.Get(href); + UpdateResource(res); + } // publid void Reload() + + public void UpdateResource(dynamic res) + { + Type resType = this.GetType(); + List fields = resType.GetProperties().ToList(); + + foreach (PropertyInfo f in fields) + { + string propName = f.Name; + if (f.Name.Equals("resource_href")) + continue; + PropertyInfo propToCopy = res.GetType().GetProperty(propName); + object propValue = propToCopy.GetValue(res); + + f.SetValue(this, propValue); + } + } // public void UpdateResource(dynamic res) -} \ No newline at end of file + public static string Serialize(object resource) + { + return JsonConvert.SerializeObject(resource, + new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore, + ContractResolver = new AllPropertiesResolver() + }); + } // public static string Serialize(object resource) + } // public abstract class Resource +} // namespace ThunderPay \ No newline at end of file diff --git a/sdks/thunderpay-sdk-cs/obj/Debug/net9.0/thunderpay-sdk-cs.AssemblyInfo.cs b/sdks/thunderpay-sdk-cs/obj/Debug/net9.0/thunderpay-sdk-cs.AssemblyInfo.cs index eabc1db..07c6fde 100644 --- a/sdks/thunderpay-sdk-cs/obj/Debug/net9.0/thunderpay-sdk-cs.AssemblyInfo.cs +++ b/sdks/thunderpay-sdk-cs/obj/Debug/net9.0/thunderpay-sdk-cs.AssemblyInfo.cs @@ -13,7 +13,7 @@ [assembly: System.Reflection.AssemblyCompanyAttribute("thunderpay-sdk-cs")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a2b25f7099d797eb3b6a14b72c669ddbd23f893d")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+98e7c57081cbc5ad8474a27db23593819e6cb71b")] [assembly: System.Reflection.AssemblyProductAttribute("thunderpay-sdk-cs")] [assembly: System.Reflection.AssemblyTitleAttribute("thunderpay-sdk-cs")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/sdks/thunderpay-sdk-cs/obj/Debug/net9.0/thunderpay-sdk-cs.AssemblyInfoInputs.cache b/sdks/thunderpay-sdk-cs/obj/Debug/net9.0/thunderpay-sdk-cs.AssemblyInfoInputs.cache index 45391dd..03cdb68 100644 --- a/sdks/thunderpay-sdk-cs/obj/Debug/net9.0/thunderpay-sdk-cs.AssemblyInfoInputs.cache +++ b/sdks/thunderpay-sdk-cs/obj/Debug/net9.0/thunderpay-sdk-cs.AssemblyInfoInputs.cache @@ -1 +1 @@ -5035e2da64ffff0315c4e7709b49c057df41c37c0d95b348a217b69475677c26 +4c8d7999ad4188bb686fd945a555d56f2637fc3d90af4c7f0e82d1b4d0e9da55