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

Conversation

SGuyGe
Copy link
Contributor

@SGuyGe SGuyGe commented Feb 16, 2016

"System.Collections.Stack",
"System.Globalization.CultureInfo",
"System.Version",
private static string[] s_knownSerializableGenericTypeNames = new string[] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is parsing this and converting it to a Dictionary even necessary? Why not a pre-parsed dictionary? e.g.:

private static readonly Dictionary<string, string[]> s_knownSerializableGenericTypes = new Dictionary<string, string[]>
{
    { "System.Collections.Generic.KeyValuePair`2", Array.Empty<string>() },
    { "System.Collections.Generic.Queue`1", new[] { "_syncRoot" } },
    { "System.Collections.Generic.Stack`1", new[] { "_syncRoot" } },
    { "System.Collections.ObjectModel.ReadOnlyCollection`1", new[] { "_syncRoot" } },
    { "System.Collections.ObjectModel.ReadOnlyDictionary`2", new[] { "_syncRoot", "_keys", "_values" } },
    { "System.Tuple`1", Array.Empty<string>() },

    ... etc. ...
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why not just have a single Dictionary for both generic and non-generic types...

Then change IsKnownSerializableType to something like:

        internal static bool IsKnownSerializableType(Type type)
        {
            // Applies to known types that DCS understands how to serialize/deserialize
            //

            TypeInfo typeInfo = type.GetTypeInfo();
            string fullName = typeInfo.IsGenericType && !typeInfo.IsGenericTypeDefinition ?
                typeInfo.GetGenericTypeDefinition().FullName :
                type.FullName;

            return s_knownSerializableTypes.ContainsKey(fullName) ||
                Globals.TypeOfException.IsAssignableFrom(type);
        }

{ "System.Collections.Generic.Queue`1", new[] { "_syncRoot" } },
{ "System.Collections.Generic.Stack`1", new[] {"_syncRoot" } },
{ "System.Collections.ObjectModel.ReadOnlyCollection`1", new [] {"_syncRoot" } },
{ "System.Collections.ObjectModel.ReadOnlyDictionary`2", new [] {"_syncRoot", "_keys","_values" } },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: for consistency, in the above two lines, new [] can be new[] (without the space between new and []).

private static string GetGeneralTypeName(Type type)
{
TypeInfo typeInfo = type.GetTypeInfo();
return type.GetTypeInfo().IsGenericType && !typeInfo.IsGenericParameter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed this previously: type.GetTypeInfo().IsGenericType -> typeInfo.IsGenericType

…ation, this is prerequisite for dotnet#2.

2) Adding support for ReadOnlyDictionary.
@khdang
Copy link
Member

khdang commented Feb 17, 2016

LGTM

@shmao
Copy link
Contributor

shmao commented Feb 17, 2016

LGTM.

@SGuyGe
Copy link
Contributor Author

SGuyGe commented Feb 17, 2016

@dotnet-bot test this please

2 similar comments
@SGuyGe
Copy link
Contributor Author

SGuyGe commented Feb 17, 2016

@dotnet-bot test this please

@SGuyGe
Copy link
Contributor Author

SGuyGe commented Feb 17, 2016

@dotnet-bot test this please

@weshaggard
Copy link
Member

@dotnet-bot test Innerloop OSX Release Build and Test
@dotnet-bot test Innerloop Ubuntu Debug Build and Test

SGuyGe added a commit that referenced this pull request Feb 17, 2016
1) Adding support for excluding [NonSerialized] members from serialization, this is prerequisite for #2; 2) Adding support for ReadOnlyDictionary.
@SGuyGe SGuyGe merged commit 650b049 into dotnet:master Feb 17, 2016
@SGuyGe SGuyGe deleted the NonSerialized branch April 27, 2016 22:20
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
1) Adding support for excluding [NonSerialized] members from serialization, this is prerequisite for dotnet/corefx#2; 2) Adding support for ReadOnlyDictionary.

Commit migrated from dotnet/corefx@650b049
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants