From 6a18b913f8820143f95b0bc587d4335722354250 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Thu, 17 Oct 2024 20:30:31 -0300 Subject: [PATCH] Fields not assigned in FromXmlFile should retain the _N flag as true --- .../GxClasses/Domain/GxCollections.cs | 10 +- .../Domain/SdtXmlSerializationTest.cs | 29 ++ .../Domain/type_SdtEmisor.cs | 272 ++++++++++++++++++ .../DotNetCoreUnitTest.csproj | 1 - 4 files changed, 307 insertions(+), 5 deletions(-) create mode 100644 dotnet/test/DotNetCoreUnitTest/Domain/SdtXmlSerializationTest.cs create mode 100644 dotnet/test/DotNetCoreUnitTest/Domain/type_SdtEmisor.cs diff --git a/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs b/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs index d27abc904..05d7e88f8 100644 --- a/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs +++ b/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs @@ -1048,6 +1048,7 @@ public class GxUserType : IGxXMLSerializable, ICloneable, IGxJSONAble, IGxJSONSe static readonly IGXLogger log = GXLoggerFactory.GetLogger(); protected ConcurrentDictionary dirties = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); private const string PROPERTY_PREFIX = "gxtpr_"; + private const string FIELD_PREFIX = "gxTv_"; static object setupChannelObject = null; static bool setupChannelInitialized; [XmlIgnore] @@ -1115,9 +1116,10 @@ public virtual bool IsDirty(string fieldName) } public virtual void Copy(GxUserType source) { - foreach (PropertyDescriptor item in TypeDescriptor.GetProperties(source)) + foreach (FieldInfo item in GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic)) { - item.SetValue(this, item.GetValue(source)); + if (item.Name.StartsWith(FIELD_PREFIX)) + item.SetValue(this, item.GetValue(source)); } } @@ -1176,7 +1178,7 @@ public bool IsEqual(GxUserType source) return false; foreach (FieldInfo item in GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic)) { - if (item.Name.StartsWith("gxTv_")) + if (item.Name.StartsWith(FIELD_PREFIX)) { GxUserType thisGxUserType = item.GetValue(this) as GxUserType; GxUserType sourceGxUserType = item.GetValue(source) as GxUserType; @@ -1667,7 +1669,7 @@ public void FromJSONObject(dynamic obj) { string sVar = uploadPath.Replace(GXFormData.FORMDATA_REFERENCE, string.Empty); - MethodInfo setBlob = GetMethodInfo("gxtv_" + GetType().Name + "_" + name + "_setblob"); + MethodInfo setBlob = GetMethodInfo(FIELD_PREFIX + GetType().Name + "_" + name + "_setblob"); if (setBlob != null) { if (HttpHelper.GetHttpRequestPostedFile(context, sVar, out uploadPath)) diff --git a/dotnet/test/DotNetCoreUnitTest/Domain/SdtXmlSerializationTest.cs b/dotnet/test/DotNetCoreUnitTest/Domain/SdtXmlSerializationTest.cs new file mode 100644 index 000000000..c3dd69419 --- /dev/null +++ b/dotnet/test/DotNetCoreUnitTest/Domain/SdtXmlSerializationTest.cs @@ -0,0 +1,29 @@ +using GeneXus.Application; +using GeneXus.Programs; +using Xunit; + +namespace DotNetCoreUnitTest.Domain +{ + public class SdtXmlSerializationTest + { + [Fact] + public void EmptyValuesDeserializationTest() + { + GxContext context = new GxContext(); + SdtEmisor emisor = new SdtEmisor(context); + string xml = ""; + xml += " 212934610017"; + xml += " ISL"; + xml += " MKT"; + xml += ""; + + emisor.FromXml(xml, null, "", ""); + bool shouldSerializeField = emisor.ShouldSerializegxTpr_Giroemis(); + Assert.False(shouldSerializeField, "GiroEmis should not be serialized since it was not assigned during XML deserialization"); + + shouldSerializeField = emisor.ShouldSerializegxTpr_Departamento(); + Assert.True(shouldSerializeField, "Departamento should be serialized since it was assigned during XML deserialization"); + + } + } +} diff --git a/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtEmisor.cs b/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtEmisor.cs new file mode 100644 index 000000000..0a24d5b69 --- /dev/null +++ b/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtEmisor.cs @@ -0,0 +1,272 @@ +/* + File: type_SdtEmisor + Description: Emisor + Author: Nemo 🐠 for C# version 18.0.11.184517 + Program type: Callable routine + Main DBMS: +*/ +using System; +using System.Collections; +using System.ServiceModel; +using System.Xml.Serialization; +using GeneXus.Application; +using GeneXus.Utils; + + +namespace GeneXus.Programs +{ + [XmlSerializerFormat] + [XmlRoot(ElementName="Emisor")] + [XmlType(TypeName="Emisor")] + [Serializable] + public class SdtEmisor : GxUserType + { + public SdtEmisor( ) + { + /* Constructor for serialization */ + gxTv_SdtEmisor_Rucemisor = ""; + gxTv_SdtEmisor_Rucemisor_N = true; + + gxTv_SdtEmisor_Rznsoc = ""; + gxTv_SdtEmisor_Rznsoc_N = true; + + gxTv_SdtEmisor_Nomcomercial = ""; + gxTv_SdtEmisor_Nomcomercial_N = true; + + gxTv_SdtEmisor_Giroemis = ""; + gxTv_SdtEmisor_Giroemis_N = true; + + gxTv_SdtEmisor_Departamento = ""; + gxTv_SdtEmisor_Departamento_N = true; + + } + + public SdtEmisor(IGxContext context) + { + this.context = context; + initialize(); + } + + #region Json + private static Hashtable mapper; + public override string JsonMap(string value) + { + if (mapper == null) + { + mapper = new Hashtable(); + } + return (string)mapper[value]; ; + } + + public override void ToJSON() + { + ToJSON(true) ; + return; + } + + public override void ToJSON(bool includeState) + { + AddObjectProperty("RUCEmisor", gxTpr_Rucemisor, false); + + + AddObjectProperty("RznSoc", gxTpr_Rznsoc, false); + + + AddObjectProperty("NomComercial", gxTpr_Nomcomercial, false); + + + AddObjectProperty("GiroEmis", gxTpr_Giroemis, false); + + + AddObjectProperty("Departamento", gxTpr_Departamento, false); + + return; + } + #endregion + + #region Properties + [SoapElement(ElementName="RUCEmisor")] + [XmlElement(ElementName="RUCEmisor")] + public string gxTpr_Rucemisor + { + get { + return gxTv_SdtEmisor_Rucemisor; + } + set { + gxTv_SdtEmisor_Rucemisor_N = false; + gxTv_SdtEmisor_Rucemisor = value; + SetDirty("Rucemisor"); + } + } + + public bool ShouldSerializegxTpr_Rucemisor() + + { + return !gxTv_SdtEmisor_Rucemisor_N; + + } + + + + [SoapElement(ElementName="RznSoc")] + [XmlElement(ElementName="RznSoc")] + public string gxTpr_Rznsoc + { + get { + return gxTv_SdtEmisor_Rznsoc; + } + set { + gxTv_SdtEmisor_Rznsoc_N = false; + gxTv_SdtEmisor_Rznsoc = value; + SetDirty("Rznsoc"); + } + } + + public bool ShouldSerializegxTpr_Rznsoc() + + { + return !gxTv_SdtEmisor_Rznsoc_N; + + } + + + + [SoapElement(ElementName="NomComercial")] + [XmlElement(ElementName="NomComercial")] + public string gxTpr_Nomcomercial + { + get { + return gxTv_SdtEmisor_Nomcomercial; + } + set { + gxTv_SdtEmisor_Nomcomercial_N = false; + gxTv_SdtEmisor_Nomcomercial = value; + SetDirty("Nomcomercial"); + } + } + + public bool ShouldSerializegxTpr_Nomcomercial() + + { + return !gxTv_SdtEmisor_Nomcomercial_N; + + } + + + + [SoapElement(ElementName="GiroEmis")] + [XmlElement(ElementName="GiroEmis")] + public string gxTpr_Giroemis + { + get { + return gxTv_SdtEmisor_Giroemis; + } + set { + gxTv_SdtEmisor_Giroemis_N = false; + gxTv_SdtEmisor_Giroemis = value; + SetDirty("Giroemis"); + } + } + + public bool ShouldSerializegxTpr_Giroemis() + + { + return !gxTv_SdtEmisor_Giroemis_N; + + } + + + + [SoapElement(ElementName="Departamento")] + [XmlElement(ElementName="Departamento")] + public string gxTpr_Departamento + { + get { + return gxTv_SdtEmisor_Departamento; + } + set { + gxTv_SdtEmisor_Departamento_N = false; + gxTv_SdtEmisor_Departamento = value; + SetDirty("Departamento"); + } + } + + public bool ShouldSerializegxTpr_Departamento() + + { + return !gxTv_SdtEmisor_Departamento_N; + + } + + + public override bool ShouldSerializeSdtJson() + { + return true; + } + + + + #endregion + + #region Static Type Properties + + [SoapIgnore] + [XmlIgnore] + private static GXTypeInfo _typeProps; + protected override GXTypeInfo TypeInfo { get { return _typeProps; } set { _typeProps = value; } } + + #endregion + + #region Initialization + + public void initialize( ) + { + gxTv_SdtEmisor_Rucemisor = ""; + gxTv_SdtEmisor_Rucemisor_N = true; + + gxTv_SdtEmisor_Rznsoc = ""; + gxTv_SdtEmisor_Rznsoc_N = true; + + gxTv_SdtEmisor_Nomcomercial = ""; + gxTv_SdtEmisor_Nomcomercial_N = true; + + gxTv_SdtEmisor_Giroemis = ""; + gxTv_SdtEmisor_Giroemis_N = true; + + gxTv_SdtEmisor_Departamento = ""; + gxTv_SdtEmisor_Departamento_N = true; + + return ; + } + + + + #endregion + + #region Declaration + + protected string gxTv_SdtEmisor_Rucemisor; + protected bool gxTv_SdtEmisor_Rucemisor_N; + + + protected string gxTv_SdtEmisor_Rznsoc; + protected bool gxTv_SdtEmisor_Rznsoc_N; + + + protected string gxTv_SdtEmisor_Nomcomercial; + protected bool gxTv_SdtEmisor_Nomcomercial_N; + + + protected string gxTv_SdtEmisor_Giroemis; + protected bool gxTv_SdtEmisor_Giroemis_N; + + + protected string gxTv_SdtEmisor_Departamento; + protected bool gxTv_SdtEmisor_Departamento_N; + + + + #endregion + } + +} \ No newline at end of file diff --git a/dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj b/dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj index 942399345..c69cdadb0 100644 --- a/dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj +++ b/dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj @@ -164,7 +164,6 @@ -