Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CallSiteBinder.cs
Go to the documentation of this file.
7
9
10public abstract class CallSiteBinder
11{
12 private sealed class LambdaSignature<T> where T : class
13 {
15
17
18 internal readonly LabelTarget ReturnLabel;
19
21 {
22 get
23 {
24 if (s_instance == null)
25 {
27 }
28 return s_instance;
29 }
30 }
31
33 {
35 if (!typeFromHandle.IsSubclassOf(typeof(MulticastDelegate)))
36 {
38 }
39 MethodInfo invokeMethod = typeFromHandle.GetInvokeMethod();
40 ParameterInfo[] parametersCached = invokeMethod.GetParametersCached();
41 if (parametersCached[0].ParameterType != typeof(CallSite))
42 {
44 }
45 ParameterExpression[] array = new ParameterExpression[parametersCached.Length - 1];
46 for (int i = 0; i < array.Length; i++)
47 {
48 array[i] = Expression.Parameter(parametersCached[i + 1].ParameterType, "$arg" + i);
49 }
51 ReturnLabel = Expression.Label(invokeMethod.GetReturnType());
52 }
53 }
54
56
57 public static LabelTarget UpdateLabel { get; } = Expression.Label("CallSiteBinder.UpdateLabel");
58
59
61
62 public virtual T? BindDelegate<T>(CallSite<T> site, object[] args) where T : class
63 {
64 return null;
65 }
66
67 internal T BindCore<T>(CallSite<T> site, object[] args) where T : class
68 {
69 T val = BindDelegate(site, args);
70 if (val != null)
71 {
72 return val;
73 }
74 LambdaSignature<T> instance = LambdaSignature<T>.Instance;
75 Expression expression = Bind(args, instance.Parameters, instance.ReturnLabel);
76 if (expression == null)
77 {
79 }
81 T val2 = expression2.Compile();
83 return val2;
84 }
85
86 protected void CacheTarget<T>(T target) where T : class
87 {
88 GetRuleCache<T>().AddRule(target);
89 }
90
103
105 {
106 if (Cache == null)
107 {
109 }
111 object value;
112 lock (cache)
113 {
114 if (!cache.TryGetValue(typeof(T), out value))
115 {
116 value = (cache[typeof(T)] = new RuleCache<T>());
117 }
118 }
119 return value as RuleCache<T>;
120 }
121}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static Exception NoOrInvalidRuleProduced()
Definition Error.cs:128
static Exception FirstArgumentMustBeCallSite()
Definition Error.cs:103
static Exception TypeParameterIsNotDelegate(object p0)
Definition Error.cs:98
static BlockExpression Block(Expression arg0, Expression arg1)
static DefaultExpression Default(Type type)
static LambdaExpression Lambda(Expression body, params ParameterExpression[]? parameters)
static MethodCallExpression Call(MethodInfo method)
static ParameterExpression Parameter(Type type)
static IndexExpression Property(Expression instance, string propertyName, params Expression[]? arguments)
static LabelExpression Label(LabelTarget target)
static ConditionalExpression Condition(Expression test, Expression ifTrue, Expression ifFalse)
static UnaryExpression Convert(Expression expression, Type type)
static InvocationExpression Invoke(Expression expression)
readonly ReadOnlyCollection< ParameterExpression > Parameters
static Expression< T > Stitch< T >(Expression binding, LambdaSignature< T > signature)
T BindCore< T >(CallSite< T > site, object[] args)
Expression Bind(object[] args, ReadOnlyCollection< ParameterExpression > parameters, LabelTarget returnLabel)
virtual ? T BindDelegate< T >(CallSite< T > site, object[] args)
static int CompareExchange(ref int location1, int value, int comparand)