Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FSharpCoreReflectionProxy.cs
Go to the documentation of this file.
4
6
7internal sealed class FSharpCoreReflectionProxy
8{
9 public enum FSharpKind
10 {
12 Option,
14 List,
15 Set,
16 Map,
17 Record,
18 Union
19 }
20
22
24 {
25 None = 0,
26 SumType = 1,
27 RecordType = 2,
28 ObjectType = 3,
29 Field = 4,
30 Exception = 5,
31 Closure = 6,
32 Module = 7,
33 UnionCase = 8,
34 Value = 9,
35 KindMask = 31,
37 }
38
40
42
44
45 private readonly Type _fsharpOptionType;
46
47 private readonly Type _fsharpValueOptionType;
48
49 private readonly Type _fsharpListType;
50
51 private readonly Type _fsharpSetType;
52
53 private readonly Type _fsharpMapType;
54
55 private readonly MethodInfo _fsharpListCtor;
56
57 private readonly MethodInfo _fsharpSetCtor;
58
59 private readonly MethodInfo _fsharpMapCtor;
60
62
63 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
64 public static bool IsFSharpType(Type type)
65 {
66 if (s_singletonInstance == null)
67 {
69 if ((object)fSharpCoreAssembly != null)
70 {
71 if (s_singletonInstance == null)
72 {
74 }
75 return true;
76 }
77 return false;
78 }
79 return s_singletonInstance.GetFSharpCompilationMappingAttribute(type) != null;
80 }
81
82 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
84 {
85 Type type = fsharpCoreAssembly.GetType("Microsoft.FSharp.Core.CompilationMappingAttribute");
86 _sourceConstructFlagsGetter = type.GetMethod("get_SourceConstructFlags", BindingFlags.Instance | BindingFlags.Public);
88 _fsharpOptionType = fsharpCoreAssembly.GetType("Microsoft.FSharp.Core.FSharpOption`1");
89 _fsharpValueOptionType = fsharpCoreAssembly.GetType("Microsoft.FSharp.Core.FSharpValueOption`1");
90 _fsharpListType = fsharpCoreAssembly.GetType("Microsoft.FSharp.Collections.FSharpList`1");
91 _fsharpSetType = fsharpCoreAssembly.GetType("Microsoft.FSharp.Collections.FSharpSet`1");
92 _fsharpMapType = fsharpCoreAssembly.GetType("Microsoft.FSharp.Collections.FSharpMap`2");
93 _fsharpListCtor = fsharpCoreAssembly.GetType("Microsoft.FSharp.Collections.ListModule")?.GetMethod("OfSeq", BindingFlags.Static | BindingFlags.Public);
94 _fsharpSetCtor = fsharpCoreAssembly.GetType("Microsoft.FSharp.Collections.SetModule")?.GetMethod("OfSeq", BindingFlags.Static | BindingFlags.Public);
95 _fsharpMapCtor = fsharpCoreAssembly.GetType("Microsoft.FSharp.Collections.MapModule")?.GetMethod("OfSeq", BindingFlags.Static | BindingFlags.Public);
96 }
97
98 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
100 {
103 {
104 return FSharpKind.Unrecognized;
105 }
106 if (type.IsGenericType)
107 {
108 Type genericTypeDefinition = type.GetGenericTypeDefinition();
110 {
111 return FSharpKind.Option;
112 }
114 {
115 return FSharpKind.ValueOption;
116 }
118 {
119 return FSharpKind.List;
120 }
122 {
123 return FSharpKind.Set;
124 }
126 {
127 return FSharpKind.Map;
128 }
129 }
131 {
134 _ => FSharpKind.Unrecognized,
135 };
136 }
137
138 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
140 {
141 MethodInfo methodInfo = EnsureMemberExists(typeof(TFSharpOption).GetMethod("get_Value", BindingFlags.Instance | BindingFlags.Public), "Microsoft.FSharp.Core.FSharpOption<T>.get_Value()");
143 }
144
145 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
151
152 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
158
159 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
161 {
162 MethodInfo methodInfo = EnsureMemberExists(typeof(TFSharpOption).GetMethod("Some", BindingFlags.Static | BindingFlags.Public), "Microsoft.FSharp.Core.FSharpValueOption<T>.ValueSome(T value)");
164 }
165
166 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
168 {
169 return CreateDelegate<Func<IEnumerable<TElement>, TFSharpList>>(EnsureMemberExists(_fsharpListCtor, "Microsoft.FSharp.Collections.ListModule.OfSeq<T>(IEnumerable<T> source)").MakeGenericMethod(typeof(TElement)));
170 }
171
172 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
174 {
175 return CreateDelegate<Func<IEnumerable<TElement>, TFSharpSet>>(EnsureMemberExists(_fsharpSetCtor, "Microsoft.FSharp.Collections.SetModule.OfSeq<T>(IEnumerable<T> source)").MakeGenericMethod(typeof(TElement)));
176 }
177
178 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
180 {
181 return CreateDelegate<Func<IEnumerable<Tuple<TKey, TValue>>, TFSharpMap>>(EnsureMemberExists(_fsharpMapCtor, "Microsoft.FSharp.Collections.MapModule.OfSeq<TKey, TValue>(IEnumerable<Tuple<TKey, TValue>> source)").MakeGenericMethod(typeof(TKey), typeof(TValue)));
182 }
183
188
197
199 {
200 object[] customAttributes = type.GetCustomAttributes(inherit: true);
201 for (int i = 0; i < customAttributes.Length; i++)
202 {
204 Type type2 = attribute.GetType();
205 if (type2.FullName == "Microsoft.FSharp.Core.CompilationMappingAttribute")
206 {
207 return type2.Assembly;
208 }
209 }
210 return null;
211 }
212
217
226}
static ? Attribute GetCustomAttribute(MemberInfo element, Type attributeType)
Definition Attribute.cs:411
static ? Delegate CreateDelegate(Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure)
Definition Delegate.cs:152
object? Invoke(object? obj, object?[]? parameters)
delegate TResult StructGetter< TStruct, TResult >(ref TStruct @this)
SourceConstructFlags GetSourceConstructFlags(Attribute compilationMappingAttribute)
TMemberInfo EnsureMemberExists< TMemberInfo >(TMemberInfo memberInfo, string memberName)
Func< IEnumerable< Tuple< TKey, TValue > >, TFSharpMap > CreateFSharpMapConstructor< TFSharpMap, TKey, TValue >()
Func< IEnumerable< TElement >, TFSharpList > CreateFSharpListConstructor< TFSharpList, TElement >()
Func< IEnumerable< TElement >, TFSharpSet > CreateFSharpSetConstructor< TFSharpSet, TElement >()
static void ThrowMissingMemberException_MissingFSharpCoreMember(string missingFsharpCoreMember)