|
3 | 3 | usingSystem.Runtime.Serialization;
|
4 | 4 | usingSystem.Runtime.Serialization.Formatters.Binary;
|
5 | 5 | usingSystem.IO;
|
| 6 | +usingSystem.Collections.Generic; |
6 | 7 |
|
7 |
| -namespacePython.Runtime |
| 8 | +namespacePython.Runtime; |
| 9 | + |
| 10 | +[Serializable] |
| 11 | +internalstructMaybeType:ISerializable |
8 | 12 | {
|
9 |
| -[Serializable] |
10 |
| -internalstructMaybeType:ISerializable |
11 |
| -{ |
12 |
| -publicstaticimplicitoperatorMaybeType(Typeob)=>new(ob); |
| 13 | +publicstaticimplicitoperatorMaybeType(Typeob)=>new(ob); |
13 | 14 |
|
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; |
18 | 19 |
|
19 |
| -publicstringDeletedMessage |
| 20 | +publicstringDeletedMessage |
| 21 | +{ |
| 22 | +get |
20 | 23 | {
|
21 |
| -get |
22 |
| -{ |
23 |
| -return$"The .NET Type{name} no longer exists"; |
24 |
| -} |
| 24 | +return$"The .NET Type{name} no longer exists"; |
25 | 25 | }
|
| 26 | +} |
26 | 27 |
|
27 |
| -publicTypeValue |
| 28 | +publicTypeValue |
| 29 | +{ |
| 30 | +get |
28 | 31 | {
|
29 |
| -get |
| 32 | +if(type==null) |
30 | 33 | {
|
31 |
| -if(type==null) |
32 |
| -{ |
33 |
| -thrownewSerializationException(DeletedMessage); |
34 |
| -} |
35 |
| -returntype; |
| 34 | +thrownewSerializationException(DeletedMessage); |
36 | 35 | }
|
| 36 | +returntype; |
37 | 37 | }
|
| 38 | +} |
38 | 39 |
|
39 |
| -publicstringName=>name; |
40 |
| -publicboolValid=>type!=null; |
| 40 | +publicstringName=>name; |
| 41 | +publicboolValid=>type!=null; |
41 | 42 |
|
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 | +} |
46 | 47 |
|
47 |
| -publicMaybeType(Typetp) |
48 |
| -{ |
49 |
| -type=tp; |
50 |
| -name=tp.AssemblyQualifiedName; |
51 |
| -} |
| 48 | +publicMaybeType(Typetp) |
| 49 | +{ |
| 50 | +type=tp; |
| 51 | +name=tp.AssemblyQualifiedName; |
| 52 | +} |
52 | 53 |
|
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 | +} |
58 | 59 |
|
59 |
| -publicvoidGetObjectData(SerializationInfoserializationInfo,StreamingContextcontext) |
60 |
| -{ |
61 |
| -serializationInfo.AddValue(SerializationName,name); |
62 |
| -} |
| 60 | +publicvoidGetObjectData(SerializationInfoserializationInfo,StreamingContextcontext) |
| 61 | +{ |
| 62 | +serializationInfo.AddValue(SerializationName,name); |
63 | 63 | }
|
64 | 64 | }
|
| 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 | +} |