Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ExpressionUtils.cs
Go to the documentation of this file.
7
9
10internal static class ExpressionUtils
11{
20
31
40
41 public static T ReturnObject<T>(object collectionOrT) where T : class
42 {
43 if (collectionOrT is T result)
44 {
45 return result;
46 }
48 }
49
51 {
54 Expression[] array = null;
55 int i = 0;
56 for (int num = parametersForValidation.Length; i < num; i++)
57 {
61 if (array == null && arguments2 != arguments[i])
62 {
64 for (int j = 0; j < i; j++)
65 {
66 array[j] = arguments[j];
67 }
68 }
69 if (array != null)
70 {
71 array[i] = arguments2;
72 }
73 }
74 if (array != null)
75 {
77 }
78 }
79
81 {
82 if (pis.Length != count)
83 {
84 switch (nodeKind)
85 {
86 case ExpressionType.New:
88 case ExpressionType.Invoke:
90 case ExpressionType.Call:
91 case ExpressionType.Dynamic:
93 default:
95 }
96 }
97 }
98
125
126 public static void RequiresCanRead(Expression expression, string paramName)
127 {
129 }
130
131 public static void RequiresCanRead(Expression expression, string paramName, int idx)
132 {
134 switch (expression.NodeType)
135 {
136 case ExpressionType.Index:
137 {
139 if (indexExpression.Indexer != null && !indexExpression.Indexer.CanRead)
140 {
142 }
143 break;
144 }
145 case ExpressionType.MemberAccess:
146 {
148 if (memberExpression.Member is PropertyInfo { CanRead: false })
149 {
151 }
152 break;
153 }
154 }
155 }
156
158 {
161 {
163 return true;
164 }
165 return false;
166 }
167
169 {
170 ParameterInfo[] array = method.GetParametersCached();
171 if (nodeKind == ExpressionType.Dynamic)
172 {
173 array = array.RemoveFirst();
174 }
175 return array;
176 }
177
178 internal static bool SameElements<T>(ICollection<T> replacement, IReadOnlyList<T> current) where T : class
179 {
180 if (replacement == current)
181 {
182 return true;
183 }
184 if (replacement == null)
185 {
186 return current.Count == 0;
187 }
188 return SameElementsInCollection(replacement, current);
189 }
190
191 internal static bool SameElements<T>(ref IEnumerable<T> replacement, IReadOnlyList<T> current) where T : class
192 {
193 if (replacement == current)
194 {
195 return true;
196 }
197 if (replacement == null)
198 {
199 return current.Count == 0;
200 }
202 if (collection == null)
203 {
204 collection = (ICollection<T>)(replacement = replacement.ToReadOnly());
205 }
206 return SameElementsInCollection(collection, current);
207 }
208
209 private static bool SameElementsInCollection<T>(ICollection<T> replacement, IReadOnlyList<T> current) where T : class
210 {
211 int count = current.Count;
212 if (replacement.Count != count)
213 {
214 return false;
215 }
216 if (count != 0)
217 {
218 int num = 0;
219 foreach (T item in replacement)
220 {
221 if (item != current[num])
222 {
223 return false;
224 }
225 num++;
226 }
227 }
228 return true;
229 }
230
232 {
233 if (((IParameterProvider)lambda).ParameterCount >= 65535)
234 {
235 throw Error.InvalidProgram();
236 }
237 }
238}
static void RequiresNotNull(object value, string paramName)
static void ValidateArgumentCount(MethodBase method, ExpressionType nodeKind, int count, ParameterInfo[] pis)
static void RequiresCanRead(Expression expression, string paramName)
static ReadOnlyCollection< ParameterExpression > ReturnReadOnly(IParameterProvider provider, ref object collection)
static bool TryQuote(Type parameterType, ref Expression argument)
static void ValidateArgumentCount(this LambdaExpression lambda)
static void RequiresCanRead(Expression expression, string paramName, int idx)
static ReadOnlyCollection< T > ReturnReadOnly< T >(ref IReadOnlyList< T > collection)
static ParameterInfo[] GetParametersForValidation(MethodBase method, ExpressionType nodeKind)
static T ReturnObject< T >(object collectionOrT)
static void ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ref ReadOnlyCollection< Expression > arguments, string methodParamName)
static Expression ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, string methodParamName, string argumentParamName, int index=-1)
static ReadOnlyCollection< Expression > ReturnReadOnly(IArgumentProvider provider, ref object collection)
static bool IsSameOrSubclass(Type type, Type subType)
Definition TypeUtils.cs:686
static void ValidateType(Type type, string paramName)
Definition TypeUtils.cs:695
static bool AreReferenceAssignable(Type dest, Type src)
Definition TypeUtils.cs:673
static Exception IncorrectNumberOfLambdaArguments()
Definition Error.cs:893
static Exception IncorrectNumberOfConstructorArguments()
Definition Error.cs:868
static Exception ExpressionTypeDoesNotMatchParameter(object p0, object p1, string paramName)
Definition Error.cs:883
static Exception ExpressionTypeDoesNotMatchMethodParameter(object p0, object p1, object p2, string paramName)
Definition Error.cs:873
static Exception IncorrectNumberOfMethodCallArguments(object p0, string paramName)
Definition Error.cs:898
static Exception ExpressionTypeDoesNotMatchConstructorParameter(object p0, object p1, string paramName)
Definition Error.cs:903
static Exception InvalidProgram()
Definition Error.cs:838
static Exception ExpressionMustBeReadable(string paramName)
Definition Error.cs:913
static UnaryExpression Quote(Expression expression)
static int CompareExchange(ref int location1, int value, int comparand)