Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit536c341

Browse files
committed
Explicitly compare MaybeType objects by name
1 parent5c50b20 commit536c341

File tree

2 files changed

+53
-43
lines changed

2 files changed

+53
-43
lines changed

‎src/runtime/ClassManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
usingSystem.Diagnostics;
44
usingSystem.Linq;
55
usingSystem.Reflection;
6-
usingSystem.Runtime.InteropServices;
76
usingSystem.Security;
87

98
usingPython.Runtime.StateSerialization;
@@ -33,7 +32,9 @@ internal class ClassManager
3332
BindingFlags.Public|
3433
BindingFlags.NonPublic;
3534

36-
internalstaticDictionary<MaybeType,ReflectedClrType>cache=new(capacity:128);
35+
internalstaticDictionary<MaybeType,ReflectedClrType>cache=new(
36+
capacity:128,comparer:newMaybeTypeComparer()
37+
);
3738
privatestaticreadonlyTypedtype;
3839

3940
privateClassManager()

‎src/runtime/StateSerialization/MaybeType.cs

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,71 @@
33
usingSystem.Runtime.Serialization;
44
usingSystem.Runtime.Serialization.Formatters.Binary;
55
usingSystem.IO;
6+
usingSystem.Collections.Generic;
67

7-
namespacePython.Runtime
8+
namespacePython.Runtime;
9+
10+
[Serializable]
11+
internalstructMaybeType:ISerializable
812
{
9-
[Serializable]
10-
internalstructMaybeType:ISerializable
11-
{
12-
publicstaticimplicitoperatorMaybeType(Typeob)=>new(ob);
13+
publicstaticimplicitoperatorMaybeType(Typeob)=>new(ob);
1314

14-
// The AssemblyQualifiedName of the serialized Type
15-
conststringSerializationName="n";
16-
readonlystringname;
17-
readonlyTypetype;
15+
// The AssemblyQualifiedName of the serialized Type
16+
conststringSerializationName="n";
17+
readonlystringname;
18+
readonlyTypetype;
1819

19-
publicstringDeletedMessage
20+
publicstringDeletedMessage
21+
{
22+
get
2023
{
21-
get
22-
{
23-
return$"The .NET Type{name} no longer exists";
24-
}
24+
return$"The .NET Type{name} no longer exists";
2525
}
26+
}
2627

27-
publicTypeValue
28+
publicTypeValue
29+
{
30+
get
2831
{
29-
get
32+
if(type==null)
3033
{
31-
if(type==null)
32-
{
33-
thrownewSerializationException(DeletedMessage);
34-
}
35-
returntype;
34+
thrownewSerializationException(DeletedMessage);
3635
}
36+
returntype;
3737
}
38+
}
3839

39-
publicstringName=>name;
40-
publicboolValid=>type!=null;
40+
publicstringName=>name;
41+
publicboolValid=>type!=null;
4142

42-
publicoverridestringToString()
43-
{
44-
return(type!=null?type.ToString():$"missing type:{name}");
45-
}
43+
publicoverridestringToString()
44+
{
45+
return(type!=null?type.ToString():$"missing type:{name}");
46+
}
4647

47-
publicMaybeType(Typetp)
48-
{
49-
type=tp;
50-
name=tp.AssemblyQualifiedName;
51-
}
48+
publicMaybeType(Typetp)
49+
{
50+
type=tp;
51+
name=tp.AssemblyQualifiedName;
52+
}
5253

53-
privateMaybeType(SerializationInfoserializationInfo,StreamingContextcontext)
54-
{
55-
name=(string)serializationInfo.GetValue(SerializationName,typeof(string));
56-
type=Type.GetType(name,throwOnError:false);
57-
}
54+
privateMaybeType(SerializationInfoserializationInfo,StreamingContextcontext)
55+
{
56+
name=(string)serializationInfo.GetValue(SerializationName,typeof(string));
57+
type=Type.GetType(name,throwOnError:false);
58+
}
5859

59-
publicvoidGetObjectData(SerializationInfoserializationInfo,StreamingContextcontext)
60-
{
61-
serializationInfo.AddValue(SerializationName,name);
62-
}
60+
publicvoidGetObjectData(SerializationInfoserializationInfo,StreamingContextcontext)
61+
{
62+
serializationInfo.AddValue(SerializationName,name);
6363
}
6464
}
65+
66+
[Serializable]
67+
internalclassMaybeTypeComparer:IEqualityComparer<MaybeType>
68+
{
69+
publicboolEquals(MaybeTypelhs,MaybeTyperhs)=>
70+
lhs.Name==rhs.Name;
71+
72+
publicintGetHashCode(MaybeTypet)=>t.Name.GetHashCode();
73+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp