Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FastInvokerBuilder.cs
Go to the documentation of this file.
3
5
6internal static class FastInvokerBuilder
7{
8 public delegate void Setter(ref object obj, object value);
9
10 public delegate object Getter(object obj);
11
13
15
16 private static readonly MethodInfo s_createGetterInternal = typeof(FastInvokerBuilder).GetMethod("CreateGetterInternal", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
17
18 private static readonly MethodInfo s_createSetterInternal = typeof(FastInvokerBuilder).GetMethod("CreateSetterInternal", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
19
20 private static readonly MethodInfo s_make = typeof(FastInvokerBuilder).GetMethod("Make", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
21
22 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod", Justification = "The call to MakeGenericMethod is safe due to the fact that we are preserving the constructors of type which is what Make() is doing.")]
23 public static Func<object> GetMakeNewInstanceFunc([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type type)
24 {
25 return s_make.MakeGenericMethod(type).CreateDelegate<Func<object>>();
26 }
27
28 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod", Justification = "The call to MakeGenericMethod is safe due to the fact that FastInvokerBuilder.CreateGetterInternal<T, T1> is not annotated.")]
30 {
31 if (memberInfo is PropertyInfo propertyInfo)
32 {
33 Func<PropertyInfo, Getter> func = s_createGetterInternal.MakeGenericMethod(propertyInfo.DeclaringType, propertyInfo.PropertyType).CreateDelegate<Func<PropertyInfo, Getter>>();
34 return func(propertyInfo);
35 }
37 if ((object)fieldInfo != null)
38 {
39 return (object obj) => fieldInfo.GetValue(obj);
40 }
42 }
43
44 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod", Justification = "The call to MakeGenericMethod is safe due to the fact that FastInvokerBuilder.CreateSetterInternal<T, T1> is not annotated.")]
46 {
48 {
49 PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
50 if (propertyInfo.CanWrite)
51 {
52 Func<PropertyInfo, Setter> func = s_createSetterInternal.MakeGenericMethod(propertyInfo.DeclaringType, propertyInfo.PropertyType).CreateDelegate<Func<PropertyInfo, Setter>>();
53 return func(propertyInfo);
54 }
56 }
58 {
60 return delegate(ref object obj, object val)
61 {
63 };
64 }
66 }
67
68 private static object Make<T>() where T : new()
69 {
70 T val = new T();
71 return val;
72 }
73
75 {
76 if (typeof(DeclaringType).IsGenericType && typeof(DeclaringType).GetGenericTypeDefinition() == typeof(KeyValue<, >))
77 {
78 if (propInfo.Name == "Key")
79 {
80 return (object obj) => ((IKeyValue)obj).Key;
81 }
82 return (object obj) => ((IKeyValue)obj).Value;
83 }
84 if (typeof(DeclaringType).IsValueType)
85 {
87 return delegate(object obj)
88 {
89 DeclaringType obj2 = (DeclaringType)obj;
90 return getMethod2(ref obj2);
91 };
92 }
94 return (object obj) => getMethod((DeclaringType)obj);
95 }
96
98 {
99 if (typeof(DeclaringType).IsGenericType && typeof(DeclaringType).GetGenericTypeDefinition() == typeof(KeyValue<, >))
100 {
101 if (propInfo.Name == "Key")
102 {
103 return delegate(ref object obj, object val)
104 {
105 ((IKeyValue)obj).Key = val;
106 };
107 }
108 return delegate(ref object obj, object val)
109 {
110 ((IKeyValue)obj).Value = val;
111 };
112 }
113 if (typeof(DeclaringType).IsValueType)
114 {
116 return delegate(ref object obj, object val)
117 {
118 DeclaringType obj2 = (DeclaringType)obj;
119 setMethod2(ref obj2, (PropertyType)val);
120 obj = obj2;
121 };
122 }
123 Action<DeclaringType, PropertyType> setMethod = propInfo.SetMethod.CreateDelegate<Action<DeclaringType, PropertyType>>();
124 return delegate(ref object obj, object val)
125 {
126 setMethod((DeclaringType)obj, (PropertyType)val);
127 };
128 }
129}
void SetValue(object? obj, object? value)
Definition FieldInfo.cs:108
object? GetValue(object? obj)
static string GetClrTypeFullName(Type type)
static Func< object > GetMakeNewInstanceFunc([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type type)
static Setter CreateSetter(MemberInfo memberInfo)
delegate void StructSetDelegate< T, TArg >(ref T obj, TArg value)
delegate TResult StructGetDelegate< T, out TResult >(ref T obj)
static Getter CreateGetterInternal< DeclaringType, PropertyType >(PropertyInfo propInfo)
delegate void Setter(ref object obj, object value)
static Getter CreateGetter(MemberInfo memberInfo)
static Setter CreateSetterInternal< DeclaringType, PropertyType >(PropertyInfo propInfo)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string NoSetMethodForProperty
Definition SR.cs:218
static string InvalidMember
Definition SR.cs:154
Definition SR.cs:7