Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields not assigned in FromXmlFile should retain the _N flag as true #1074

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ public class GxUserType : IGxXMLSerializable, ICloneable, IGxJSONAble, IGxJSONSe
static readonly IGXLogger log = GXLoggerFactory.GetLogger<GxUserType>();
protected ConcurrentDictionary<string,byte> dirties = new ConcurrentDictionary<string, byte>(StringComparer.OrdinalIgnoreCase);
private const string PROPERTY_PREFIX = "gxtpr_";
private const string FIELD_PREFIX = "gxTv_";
static object setupChannelObject = null;
static bool setupChannelInitialized;
[XmlIgnore]
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
29 changes: 29 additions & 0 deletions dotnet/test/DotNetCoreUnitTest/Domain/SdtXmlSerializationTest.cs
Original file line number Diff line number Diff line change
@@ -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 = "<Emisor xmlns=\"\">";
xml += " <RUCEmisor>212934610017</RUCEmisor>";
xml += " <RznSoc>ISL</RznSoc>";
xml += " <Departamento>MKT</Departamento>";
xml += "</Emisor>";

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");

}
}
}
272 changes: 272 additions & 0 deletions dotnet/test/DotNetCoreUnitTest/Domain/type_SdtEmisor.cs
Original file line number Diff line number Diff line change
@@ -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
}

}
1 change: 0 additions & 1 deletion dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@

<ItemGroup>
<Folder Include="ConfigMappings\" />
<Folder Include="Domain\" />
<Folder Include="Log\" />
<Folder Include="PDF\" />
<Folder Include="resources\xml\" />
Expand Down
Loading