-
Notifications
You must be signed in to change notification settings - Fork 62
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
Fix cross framework incompatibility for System.Drawing.Color #208
Changes from all commits
4f9a643
228aea6
92bbaa8
821133e
91a4d8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,18 +118,16 @@ private static Type GetTypeFromManifestName(Stream stream, DeserializerSession s | |
return TypeNameLookup.GetOrAdd(byteArr, b => | ||
{ | ||
var shortName = StringEx.FromUtf8Bytes(b.Bytes, 0, b.Bytes.Length); | ||
#if NET45 | ||
if (shortName.Contains("System.Private.CoreLib,%core%")) | ||
{ | ||
shortName = shortName.Replace("System.Private.CoreLib,%core%", "mscorlib,%core%"); | ||
} | ||
#endif | ||
#if NETSTANDARD | ||
if (shortName.Contains("mscorlib,%core%")) | ||
var overrides = session.Serializer.Options.CrossFrameworkPackageNameOverrides; | ||
|
||
var oldName = shortName; | ||
foreach (var adapter in overrides) | ||
{ | ||
shortName = shortName.Replace("mscorlib,%core%", "System.Private.CoreLib,%core%"); | ||
shortName = adapter(shortName); | ||
if (!ReferenceEquals(oldName, shortName)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimization, bail out as soon as there is a match, we will only allow one transformation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like it |
||
break; | ||
} | ||
#endif | ||
|
||
return LoadTypeByName(shortName); | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,22 @@ namespace Hyperion | |
{ | ||
public class SerializerOptions | ||
{ | ||
internal static List<Func<string, string>> DefaultPackageNameOverrides() | ||
{ | ||
return new List<Func<string, string>> | ||
{ | ||
#if NET45 | ||
str => str.Contains("System.Private.CoreLib,%core%") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
? str.Replace("System.Private.CoreLib,%core%", "mscorlib,%core%") | ||
: str | ||
#elif NETSTANDARD | ||
str => str.Contains("mscorlib,%core%") | ||
? str.Replace("mscorlib,%core%", "System.Private.CoreLib,%core%") | ||
: str | ||
#endif | ||
}; | ||
} | ||
|
||
internal static readonly Surrogate[] EmptySurrogates = new Surrogate[0]; | ||
|
||
|
||
|
@@ -53,8 +69,10 @@ public class SerializerOptions | |
internal readonly bool VersionTolerance; | ||
internal readonly Type[] KnownTypes; | ||
internal readonly Dictionary<Type, ushort> KnownTypesDict = new Dictionary<Type, ushort>(); | ||
internal readonly List<Func<string, string>> CrossFrameworkPackageNameOverrides = | ||
DefaultPackageNameOverrides(); | ||
|
||
public SerializerOptions(bool versionTolerance = false, bool preserveObjectReferences = false, IEnumerable<Surrogate> surrogates = null, IEnumerable<ValueSerializerFactory> serializerFactories = null, IEnumerable<Type> knownTypes = null, bool ignoreISerializable = false) | ||
public SerializerOptions(bool versionTolerance = false, bool preserveObjectReferences = false, IEnumerable<Surrogate> surrogates = null, IEnumerable<ValueSerializerFactory> serializerFactories = null, IEnumerable<Type> knownTypes = null, bool ignoreISerializable = false, IEnumerable<Func<string, string>> packageNameOverrides = null) | ||
{ | ||
VersionTolerance = versionTolerance; | ||
Surrogates = surrogates?.ToArray() ?? EmptySurrogates; | ||
|
@@ -72,6 +90,9 @@ public SerializerOptions(bool versionTolerance = false, bool preserveObjectRefer | |
|
||
PreserveObjectReferences = preserveObjectReferences; | ||
IgnoreISerializable = ignoreISerializable; | ||
|
||
if(packageNameOverrides != null) | ||
CrossFrameworkPackageNameOverrides.AddRange(packageNameOverrides); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM