Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1322449
Fix Private.Xml solution broken by https://github.com/dotnet/runtime/…
StephenMolloy Jun 28, 2022
fe3c017
Align DCS with 4.8 implementation - minus schema import/export.
StephenMolloy Jun 29, 2022
335adfe
External DCS Schema support groundwork. Before DC-tree work and other…
StephenMolloy Jul 3, 2022
6dfd3c4
Added public APIs, but not the DataContract tree yet.
StephenMolloy Jul 6, 2022
71d4ab4
All APIs in.
StephenMolloy Jul 7, 2022
4eb08fb
Cleanup.
StephenMolloy Jul 7, 2022
ec2518d
Addressed some nits and PR feedback on API.
StephenMolloy Jul 8, 2022
ec64156
Merge branch 'main' into dcs-alignment-with-schema-support
StephenMolloy Jul 8, 2022
1183287
API nit, more PR feedback.
StephenMolloy Jul 10, 2022
92b1d63
Fix HasRoot hiding issue.
StephenMolloy Jul 11, 2022
79da1a7
Add basic schema tests. Fix DataMember bug.
StephenMolloy Jul 12, 2022
9a13158
Add /// comments for new schema project.
StephenMolloy Jul 12, 2022
3b376ab
Fixing bad format in xml comment.
StephenMolloy Jul 12, 2022
2127ba8
Skip import test on Wasm.
StephenMolloy Jul 12, 2022
4c3417c
Obsolete old half-coded schema exporter.
StephenMolloy Jul 12, 2022
54b6b39
Add obsolete attribute in ref project as well.
StephenMolloy Jul 12, 2022
7308470
Removing obsolete for now, since it appears Syndication depends on ol…
StephenMolloy Jul 13, 2022
6be7bbc
Fix the DCJS ref project.
StephenMolloy Jul 13, 2022
446c993
API cleanup.
StephenMolloy Jul 14, 2022
8157957
Project file cleanup
StephenMolloy Jul 14, 2022
0956064
Merge branch 'main' into dcs-alignment-with-schema-support
ViktorHofer Jul 14, 2022
f1414b8
Fix mono issue with reflection access to non-public private fields.
StephenMolloy Jul 15, 2022
36267a6
Merge branch 'dcs-alignment-with-schema-support' of https://github.co…
StephenMolloy Jul 15, 2022
bf6d5dd
Addressing feedback from API review.
StephenMolloy Jul 29, 2022
df5f444
Merge branch 'main' into dcs-alignment-with-schema-support
StephenMolloy Jul 29, 2022
e868642
Port NetFx Export/Import test suites to Serializer test projects.
StephenMolloy Aug 2, 2022
24ca75c
Fix bugs found by newly ported tests.
StephenMolloy Aug 2, 2022
6b65e43
Merge branch 'dcs-alignment-with-schema-support' of https://github.co…
StephenMolloy Aug 2, 2022
ded55f6
Account for different newline sizes on different platforms.
StephenMolloy Aug 3, 2022
7462bea
Skip flaky test on wasm for now.
StephenMolloy Aug 3, 2022
7bbdbee
Non-draft PR feedback.
StephenMolloy Aug 11, 2022
be324a7
Gentle nudge for Azure pipeline, which seems to have gotten stuck.
StephenMolloy Aug 11, 2022
08d419c
Change DC.Members API. Drop KVP shennanigans.
StephenMolloy Aug 12, 2022
4f555bc
More PR feedback.
StephenMolloy Aug 12, 2022
80fd11b
Nudge Azure pipelines again. :(
StephenMolloy Aug 12, 2022
f8ebd1a
nudge
StephenMolloy Aug 12, 2022
01517c7
nudge again.
StephenMolloy Aug 13, 2022
b7100af
One more nudge.
StephenMolloy Aug 13, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand Down Expand Up @@ -63,12 +64,14 @@ internal ClassDataContract? BaseClassContract
set => _helper.BaseClassContract = value;
}

public override List<DataMember>? Members
internal List<DataMember>? Members
{
get => _helper.Members;
internal set => _helper.Members = value;
set => _helper.Members = value;
}

public override ReadOnlyCollection<DataMember> DataMembers => (Members == null) ? DataContract.s_emptyDataMemberList : Members.AsReadOnly();

internal XmlDictionaryString?[]? ChildElementNamespaces
{
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
Expand Down Expand Up @@ -1306,7 +1309,7 @@ internal override DataContract BindGenericParameters(DataContract[] paramContrac
xmlName = XmlName;
genericParams = paramContracts;

// NOTE TODO smolloy - this type-binding ('boundType') stuff is new here. We did not do this in NetFx. We used to use default constructors and let the
// NOTE TODO smolloy - this type-binding ('boundType') stuff is new. We did not do this in NetFx. We used to use default constructors and let the
// underlying type get filled in later. But default constructors for DataContracts runs afoul of requiring an underlying type. Our web of nullable
// notations make it hard to get around. But it also allows us to feel good about using .UnderlyingType from matching parameter contracts.
Type[] underlyingParamTypes = new Type[paramContracts.Length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Buffers.Binary;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
Expand Down Expand Up @@ -32,6 +33,8 @@ public abstract class DataContract
DynamicallyAccessedMemberTypes.PublicFields |
DynamicallyAccessedMemberTypes.PublicProperties;

internal static ReadOnlyCollection<DataMember> s_emptyDataMemberList = new List<DataMember>().AsReadOnly();

private XmlDictionaryString _name;
private XmlDictionaryString _ns;
private readonly DataContractCriticalHelper _helper;
Expand Down Expand Up @@ -251,11 +254,7 @@ public virtual bool IsDictionaryLike([NotNullWhen(true)] out string? keyName, [N
return false;
}

public virtual List<DataMember>? Members
{
get => null;
internal set { }
}
public virtual ReadOnlyCollection<DataMember> DataMembers => s_emptyDataMemberList;

internal virtual void WriteRootElement(XmlWriterDelegator writer, XmlDictionaryString name, XmlDictionaryString? ns)
{
Expand Down Expand Up @@ -2012,24 +2011,45 @@ private static void ImportKnownTypeAttributes(Type? type, Dictionary<Type, Type>
}
}

//For Json we need to add KeyValuePair<K,T> to KnownTypes if the UnderLyingType is a Dictionary<K,T>
try
AppContext.TryGetSwitch("Switch.System.Runtime.Serialization.DataContracts.Auto_Import_KVP", out bool autoImportKVP);
if (autoImportKVP)
{
if (DataContract.GetDataContract(type) is CollectionDataContract collectionDataContract && collectionDataContract.IsDictionary &&
collectionDataContract.ItemType.GetGenericTypeDefinition() == Globals.TypeOfKeyValue)
//For Json we need to add KeyValuePair<K,T> to KnownTypes if the UnderLyingType is a Dictionary<K,T>
//
// ^^^ Years later I think this is referring to how we treat dictionaries as collections of the
// 'KeyValue' struct we have internally. But Json for some reason needed contracts for KeyValuePair<K,T>
// as well. Possibly related to 'UseSimpleDictionaryFormat'? So we would import both KeyValue and KVP
// contracts and be happy.
// Years later, we've had and gotten rid of a KeyValuePair adapter, and I'm not sure I see a case where
// DCJS is failing with either dictionary format without this code. This seems extraneous at this
// point. Perhaps its there to bridge a potential mis-match between producer and consumer?
//
//
// Or, if I put more faith in the 'catch' comment - this was a case where DCSJ might have used
// an internal KV struct because KVP was missing [Serializable], but regular DCS was using a
// KVPAdapter class? And now KVP does have [Serializable] so we don't need either of those workarounds
// anymore. We already dropped KVPAdapter in this PR. We can probably drop this workaround as well.
// This seems the more likely explaination for this block.
//
// TODO smolloy - discuss potential removal of this altogether.
try
{
DataContract itemDataContract = DataContract.GetDataContract(Globals.TypeOfKeyValuePair.MakeGenericType(collectionDataContract.ItemType.GetGenericArguments()));
knownDataContracts ??= new DataContractDictionary();
if (DataContract.GetDataContract(type) is CollectionDataContract collectionDataContract && collectionDataContract.IsDictionary &&
collectionDataContract.ItemType.GetGenericTypeDefinition() == Globals.TypeOfKeyValue)
{
DataContract itemDataContract = DataContract.GetDataContract(Globals.TypeOfKeyValuePair.MakeGenericType(collectionDataContract.ItemType.GetGenericArguments()));
knownDataContracts ??= new DataContractDictionary();

knownDataContracts.TryAdd(itemDataContract.XmlName, itemDataContract);
knownDataContracts.TryAdd(itemDataContract.XmlName, itemDataContract);
}
}
catch (InvalidDataContractException)
{
//Ignore any InvalidDataContractException as this phase is a workaround for lack of ISerializable.
//InvalidDataContractException may happen as we walk the type hierarchy back to Object and encounter
//types that may not be valid DC. This step is purely for KeyValuePair and shouldn't fail the (de)serialization.
//Any IDCE in this case fails the serialization/deserialization process which is not the optimal experience.
}
}
catch (InvalidDataContractException)
{
//Ignore any InvalidDataContractException as this phase is a workaround for lack of ISerializable.
//InvalidDataContractException may happen as we walk the type hierarchy back to Object and encounter
//types that may not be valid DC. This step is purely for KeyValuePair and shouldn't fail the (de)serialization.
//Any IDCE in this case fails the serialization/deserialization process which is not the optimal experience.
}

type = type.BaseType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand Down Expand Up @@ -43,13 +44,14 @@ internal XmlQualifiedName BaseContractName
set => _helper.BaseContractName = value;
}

[NotNull]
public override List<DataMember>? Members
internal List<DataMember> Members
{
get => _helper.Members;
internal set => _helper.Members = value!;
set => _helper.Members = value;
}

public override ReadOnlyCollection<DataMember> DataMembers => (Members == null) ? DataContract.s_emptyDataMemberList : Members.AsReadOnly();

internal List<long>? Values
{
get => _helper.Values;
Expand Down
Loading