diff --git a/src/OrangeJetpack.Localization/LocalizedContent.cs b/src/OrangeJetpack.Localization/LocalizedContent.cs index 8f286c2..bbdb72c 100644 --- a/src/OrangeJetpack.Localization/LocalizedContent.cs +++ b/src/OrangeJetpack.Localization/LocalizedContent.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; + +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; diff --git a/src/OrangeJetpack.Localization/LocalizedContentExtensions.cs b/src/OrangeJetpack.Localization/LocalizedContentExtensions.cs index 7cb0367..13b4116 100644 --- a/src/OrangeJetpack.Localization/LocalizedContentExtensions.cs +++ b/src/OrangeJetpack.Localization/LocalizedContentExtensions.cs @@ -253,5 +253,41 @@ public static T Set(this T item, Expression> property, IDicti return Set(item, property, localizedContents); } + + /// + /// Sets an item's localized content property for a specific language, + /// Usefull to do updates on objects. + /// + /// + /// An ILocalizable item. + /// The property to set. + /// The language to set the content. + /// The value to set the content to. + /// + public static T Set(this T item, Expression> property, string lang, string value) where T : class, ILocalizable + { + var memberExpression = (MemberExpression)property.Body; + var propertyInfo = (PropertyInfo)memberExpression.Member; + + var itemValue = propertyInfo.GetValue(item); + var content = + new List( + LocalizedContent.Deserialize(itemValue != null ? itemValue as string : LocalizedContent.Init())); + + LocalizedContent update = content.FirstOrDefault(p => p.Key.Equals(lang)); + + if (update != null) + { + update.Value = value; + } + else + { + content.Add(new LocalizedContent(lang, value)); + } + + propertyInfo.SetValue(item, content.Serialize(), null); + + return item; + } } } \ No newline at end of file diff --git a/src/OrangeJetpack.Localization/OrangeJetpack.Localization.csproj b/src/OrangeJetpack.Localization/OrangeJetpack.Localization.csproj index cdfab45..206c3fb 100644 --- a/src/OrangeJetpack.Localization/OrangeJetpack.Localization.csproj +++ b/src/OrangeJetpack.Localization/OrangeJetpack.Localization.csproj @@ -32,9 +32,9 @@ 4 - - ..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll - True + + False + ..\..\..\..\ECSaudeWindowsApplication\External Libs\Newtonsoft.Json.dll