Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit f3c4f89

Browse files
committed
Merge pull request #2725 from dotnet-bot/from-tfs
Merge changes from TFS
2 parents 2df1b03 + b374a7a commit f3c4f89

File tree

3 files changed

+79
-5
lines changed

3 files changed

+79
-5
lines changed

src/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ClassDataContract.cs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ internal static ClassDataContract CreateClassDataContractForKeyValue(Type type,
344344
#if !NET_NATIVE
345345
return new ClassDataContract(type, ns, memberNames);
346346
#else
347-
return (ClassDataContract)DataContract.GetDataContractFromGeneratedAssembly(type);
347+
ClassDataContract cdc = (ClassDataContract)DataContract.GetDataContractFromGeneratedAssembly(type);
348+
ClassDataContract cloned = cdc.Clone();
349+
cloned.UpdateNamespaceAndMembers(type, ns, memberNames);
350+
return cloned;
348351
#endif
349352
}
350353

@@ -1437,6 +1440,38 @@ public int Compare(Member x, Member y)
14371440

14381441
internal static DataMemberConflictComparer Singleton = new DataMemberConflictComparer();
14391442
}
1443+
1444+
#if NET_NATIVE
1445+
internal ClassDataContractCriticalHelper Clone()
1446+
{
1447+
ClassDataContractCriticalHelper clonedHelper = new ClassDataContractCriticalHelper(this.UnderlyingType);
1448+
1449+
clonedHelper._baseContract = this._baseContract;
1450+
clonedHelper._childElementNamespaces = this._childElementNamespaces;
1451+
clonedHelper.ContractNamespaces = this.ContractNamespaces;
1452+
clonedHelper._hasDataContract = this._hasDataContract;
1453+
clonedHelper._isMethodChecked = this._isMethodChecked;
1454+
clonedHelper._isNonAttributedType = this._isNonAttributedType;
1455+
clonedHelper.IsReference = this.IsReference;
1456+
clonedHelper.IsValueType = this.IsValueType;
1457+
clonedHelper.MemberNames = this.MemberNames;
1458+
clonedHelper.MemberNamespaces = this.MemberNamespaces;
1459+
clonedHelper._members = this._members;
1460+
clonedHelper.Name = this.Name;
1461+
clonedHelper.Namespace = this.Namespace;
1462+
clonedHelper._onDeserialized = this._onDeserialized;
1463+
clonedHelper._onDeserializing = this._onDeserializing;
1464+
clonedHelper._onSerialized = this._onSerialized;
1465+
clonedHelper._onSerializing = this._onSerializing;
1466+
clonedHelper.StableName = this.StableName;
1467+
clonedHelper.TopLevelElementName = this.TopLevelElementName;
1468+
clonedHelper.TopLevelElementNamespace = this.TopLevelElementNamespace;
1469+
clonedHelper._xmlFormatReaderDelegate = this._xmlFormatReaderDelegate;
1470+
clonedHelper._xmlFormatWriterDelegate = this._xmlFormatWriterDelegate;
1471+
1472+
return clonedHelper;
1473+
}
1474+
#endif
14401475
}
14411476

14421477

@@ -1471,5 +1506,37 @@ internal Type ObjectType
14711506
}
14721507
}
14731508
#endif
1509+
1510+
#if NET_NATIVE
1511+
internal ClassDataContract Clone()
1512+
{
1513+
ClassDataContract clonedDc = new ClassDataContract(this.UnderlyingType);
1514+
clonedDc._helper = _helper.Clone();
1515+
clonedDc.ContractNamespaces = this.ContractNamespaces;
1516+
clonedDc.ChildElementNamespaces = this.ChildElementNamespaces;
1517+
clonedDc.MemberNames = this.MemberNames;
1518+
clonedDc.MemberNamespaces = this.MemberNamespaces;
1519+
clonedDc.XmlFormatWriterDelegate = this.XmlFormatWriterDelegate;
1520+
clonedDc.XmlFormatReaderDelegate = this.XmlFormatReaderDelegate;
1521+
return clonedDc;
1522+
}
1523+
1524+
internal void UpdateNamespaceAndMembers(Type type, XmlDictionaryString ns, string[] memberNames)
1525+
{
1526+
this.StableName = new XmlQualifiedName(GetStableName(type).Name, ns.Value);
1527+
this.Namespace = ns;
1528+
XmlDictionary dictionary = new XmlDictionary(1 + memberNames.Length);
1529+
this.Name = dictionary.Add(StableName.Name);
1530+
this.Namespace = ns;
1531+
this.ContractNamespaces = new XmlDictionaryString[] { ns };
1532+
this.MemberNames = new XmlDictionaryString[memberNames.Length];
1533+
this.MemberNamespaces = new XmlDictionaryString[memberNames.Length];
1534+
for (int i = 0; i < memberNames.Length; i++)
1535+
{
1536+
this.MemberNames[i] = dictionary.Add(memberNames[i]);
1537+
this.MemberNamespaces[i] = ns;
1538+
}
1539+
}
1540+
#endif
14741541
}
14751542
}

src/System.Private.DataContractSerialization/src/System/Runtime/Serialization/CollectionDataContract.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,7 @@ public DataContract ItemContract
258258
[SecuritySafeCritical]
259259
get
260260
{
261-
#if !NET_NATIVE
262261
return _itemContract ?? _helper.ItemContract;
263-
#else
264-
return _itemContract ?? DataContract.GetDataContractFromGeneratedAssembly(this.ItemType);
265-
#endif
266262
}
267263
/// <SecurityNote>
268264
/// Critical - sets the critical itemContract property
@@ -744,7 +740,11 @@ internal DataContract ItemContract
744740
}
745741
else
746742
{
743+
#if NET_NATIVE
744+
_itemContract = DataContract.GetDataContractFromGeneratedAssembly(ItemType);
745+
#else
747746
_itemContract = DataContract.GetDataContract(ItemType);
747+
#endif
748748
}
749749
}
750750
return _itemContract;

src/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonDataContract.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ public static JsonReadWriteDelegates GetGeneratedReadWriteDelegates(DataContract
5959
// with the restructuring for multi-file, this is no longer true - instead
6060
// this has become a normal method
6161
JsonReadWriteDelegates result;
62+
#if NET_NATIVE
63+
// The c passed in could be a clone which is different from the original key,
64+
// We'll need to get the original key data contract from generated assembly.
65+
DataContract keyDc = DataContract.GetDataContractFromGeneratedAssembly(c.UnderlyingType);
66+
return JsonReadWriteDelegates.GetJsonDelegates().TryGetValue(keyDc, out result) ? result : null;
67+
#else
6268
return JsonReadWriteDelegates.GetJsonDelegates().TryGetValue(c, out result) ? result : null;
69+
#endif
6370
}
6471

6572
internal static JsonReadWriteDelegates GetReadWriteDelegatesFromGeneratedAssembly(DataContract c)

0 commit comments

Comments
 (0)