1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Collections.Generic; 6 using System.Reflection; 7 8 namespace System.Linq.Expressions 9 { 10 /// <summary> 11 /// Strongly-typed and parameterized exception factory. 12 /// </summary> 13 internal static class Error 14 { 15 /// <summary> 16 /// ArgumentException with message like "reducible nodes must override Expression.Reduce()" 17 /// </summary> ReducibleMustOverrideReduce()18 internal static Exception ReducibleMustOverrideReduce() 19 { 20 return new ArgumentException(Strings.ReducibleMustOverrideReduce); 21 } 22 /// <summary> 23 /// ArgumentException with message like "Argument count must be greater than number of named arguments." 24 /// </summary> ArgCntMustBeGreaterThanNameCnt()25 internal static Exception ArgCntMustBeGreaterThanNameCnt() 26 { 27 return new ArgumentException(Strings.ArgCntMustBeGreaterThanNameCnt); 28 } 29 /// <summary> 30 /// InvalidOperationException with message like "An IDynamicMetaObjectProvider {0} created an invalid DynamicMetaObject instance." 31 /// </summary> InvalidMetaObjectCreated(object p0)32 internal static Exception InvalidMetaObjectCreated(object p0) 33 { 34 return new InvalidOperationException(Strings.InvalidMetaObjectCreated(p0)); 35 } 36 /// <summary> 37 /// System.Reflection.AmbiguousMatchException with message like "More than one key matching '{0}' was found in the ExpandoObject." 38 /// </summary> AmbiguousMatchInExpandoObject(object p0)39 internal static Exception AmbiguousMatchInExpandoObject(object p0) 40 { 41 return new AmbiguousMatchException(Strings.AmbiguousMatchInExpandoObject(p0)); 42 } 43 /// <summary> 44 /// ArgumentException with message like "An element with the same key '{0}' already exists in the ExpandoObject." 45 /// </summary> SameKeyExistsInExpando(object key)46 internal static Exception SameKeyExistsInExpando(object key) 47 { 48 return new ArgumentException(Strings.SameKeyExistsInExpando(key), nameof(key)); 49 } 50 /// <summary> 51 /// System.Collections.Generic.KeyNotFoundException with message like "The specified key '{0}' does not exist in the ExpandoObject." 52 /// </summary> KeyDoesNotExistInExpando(object p0)53 internal static Exception KeyDoesNotExistInExpando(object p0) 54 { 55 return new KeyNotFoundException(Strings.KeyDoesNotExistInExpando(p0)); 56 } 57 /// <summary> 58 /// InvalidOperationException with message like "Collection was modified; enumeration operation may not execute." 59 /// </summary> CollectionModifiedWhileEnumerating()60 internal static Exception CollectionModifiedWhileEnumerating() 61 { 62 return new InvalidOperationException(Strings.CollectionModifiedWhileEnumerating); 63 } 64 /// <summary> 65 /// NotSupportedException with message like "Collection is read-only." 66 /// </summary> CollectionReadOnly()67 internal static Exception CollectionReadOnly() 68 { 69 return new NotSupportedException(Strings.CollectionReadOnly); 70 } 71 /// <summary> 72 /// ArgumentException with message like "node cannot reduce to itself or null" 73 /// </summary> MustReduceToDifferent()74 internal static Exception MustReduceToDifferent() 75 { 76 return new ArgumentException(Strings.MustReduceToDifferent); 77 } 78 /// <summary> 79 /// InvalidOperationException with message like "The result type '{0}' of the binder '{1}' is not compatible with the result type '{2}' expected by the call site." 80 /// </summary> BinderNotCompatibleWithCallSite(object p0, object p1, object p2)81 internal static Exception BinderNotCompatibleWithCallSite(object p0, object p1, object p2) 82 { 83 return new InvalidOperationException(Strings.BinderNotCompatibleWithCallSite(p0, p1, p2)); 84 } 85 /// <summary> 86 /// InvalidOperationException with message like "The result of the dynamic binding produced by the object with type '{0}' for the binder '{1}' needs at least one restriction." 87 /// </summary> DynamicBindingNeedsRestrictions(object p0, object p1)88 internal static Exception DynamicBindingNeedsRestrictions(object p0, object p1) 89 { 90 return new InvalidOperationException(Strings.DynamicBindingNeedsRestrictions(p0, p1)); 91 } 92 /// <summary> 93 /// InvalidCastException with message like "The result type '{0}' of the dynamic binding produced by the object with type '{1}' for the binder '{2}' is not compatible with the result type '{3}' expected by the call site." 94 /// </summary> DynamicObjectResultNotAssignable(object p0, object p1, object p2, object p3)95 internal static Exception DynamicObjectResultNotAssignable(object p0, object p1, object p2, object p3) 96 { 97 return new InvalidCastException(Strings.DynamicObjectResultNotAssignable(p0, p1, p2, p3)); 98 } 99 /// <summary> 100 /// InvalidCastException with message like "The result type '{0}' of the dynamic binding produced by binder '{1}' is not compatible with the result type '{2}' expected by the call site." 101 /// </summary> DynamicBinderResultNotAssignable(object p0, object p1, object p2)102 internal static Exception DynamicBinderResultNotAssignable(object p0, object p1, object p2) 103 { 104 return new InvalidCastException(Strings.DynamicBinderResultNotAssignable(p0, p1, p2)); 105 } 106 /// <summary> 107 /// InvalidOperationException with message like "Bind cannot return null." 108 /// </summary> BindingCannotBeNull()109 internal static Exception BindingCannotBeNull() 110 { 111 return new InvalidOperationException(Strings.BindingCannotBeNull); 112 } 113 /// <summary> 114 /// ArgumentException with message like "cannot assign from the reduced node type to the original node type" 115 /// </summary> ReducedNotCompatible()116 internal static Exception ReducedNotCompatible() 117 { 118 return new ArgumentException(Strings.ReducedNotCompatible); 119 } 120 /// <summary> 121 /// ArgumentException with message like "Setter must have parameters." 122 /// </summary> SetterHasNoParams(string paramName)123 internal static Exception SetterHasNoParams(string paramName) 124 { 125 return new ArgumentException(Strings.SetterHasNoParams, paramName); 126 } 127 /// <summary> 128 /// ArgumentException with message like "Property cannot have a managed pointer type." 129 /// </summary> PropertyCannotHaveRefType(string paramName)130 internal static Exception PropertyCannotHaveRefType(string paramName) 131 { 132 return new ArgumentException(Strings.PropertyCannotHaveRefType, paramName); 133 } 134 /// <summary> 135 /// ArgumentException with message like "Indexing parameters of getter and setter must match." 136 /// </summary> IndexesOfSetGetMustMatch(string paramName)137 internal static Exception IndexesOfSetGetMustMatch(string paramName) 138 { 139 return new ArgumentException(Strings.IndexesOfSetGetMustMatch, paramName); 140 } 141 /// <summary> 142 /// InvalidOperationException with message like "Type parameter is {0}. Expected a delegate." 143 /// </summary> TypeParameterIsNotDelegate(object p0)144 internal static Exception TypeParameterIsNotDelegate(object p0) 145 { 146 return new InvalidOperationException(Strings.TypeParameterIsNotDelegate(p0)); 147 } 148 /// <summary> 149 /// ArgumentException with message like "First argument of delegate must be CallSite" 150 /// </summary> FirstArgumentMustBeCallSite()151 internal static Exception FirstArgumentMustBeCallSite() 152 { 153 return new ArgumentException(Strings.FirstArgumentMustBeCallSite); 154 } 155 /// <summary> 156 /// ArgumentException with message like "Accessor method should not have VarArgs." 157 /// </summary> AccessorsCannotHaveVarArgs(string paramName)158 internal static Exception AccessorsCannotHaveVarArgs(string paramName) 159 { 160 return new ArgumentException(Strings.AccessorsCannotHaveVarArgs, paramName); 161 } 162 /// <summary> 163 /// ArgumentException with message like "Accessor indexes cannot be passed ByRef." 164 /// </summary> AccessorsCannotHaveByRefArgs(string paramName)165 private static Exception AccessorsCannotHaveByRefArgs(string paramName) 166 { 167 return new ArgumentException(Strings.AccessorsCannotHaveByRefArgs, paramName); 168 } 169 /// <summary> 170 /// ArgumentException with message like "Accessor indexes cannot be passed ByRef." 171 /// </summary> AccessorsCannotHaveByRefArgs(string paramName, int index)172 internal static Exception AccessorsCannotHaveByRefArgs(string paramName, int index) 173 { 174 return AccessorsCannotHaveByRefArgs(GetParamName(paramName, index)); 175 } 176 /// <summary> 177 /// ArgumentException with message like "Type must be derived from System.Delegate" 178 /// </summary> TypeMustBeDerivedFromSystemDelegate()179 internal static Exception TypeMustBeDerivedFromSystemDelegate() 180 { 181 return new ArgumentException(Strings.TypeMustBeDerivedFromSystemDelegate); 182 } 183 /// <summary> 184 /// InvalidOperationException with message like "No or Invalid rule produced" 185 /// </summary> NoOrInvalidRuleProduced()186 internal static Exception NoOrInvalidRuleProduced() 187 { 188 return new InvalidOperationException(Strings.NoOrInvalidRuleProduced); 189 } 190 /// <summary> 191 /// ArgumentException with message like "Bounds count cannot be less than 1" 192 /// </summary> BoundsCannotBeLessThanOne(string paramName)193 internal static Exception BoundsCannotBeLessThanOne(string paramName) 194 { 195 return new ArgumentException(Strings.BoundsCannotBeLessThanOne, paramName); 196 } 197 /// <summary> 198 /// ArgumentException with message like "Type must not be ByRef" 199 /// </summary> TypeMustNotBeByRef(string paramName)200 internal static Exception TypeMustNotBeByRef(string paramName) 201 { 202 return new ArgumentException(Strings.TypeMustNotBeByRef, paramName); 203 } 204 205 /// <summary> 206 /// ArgumentException with message like "Type must not be a pointer type" 207 /// </summary> TypeMustNotBePointer(string paramName)208 internal static Exception TypeMustNotBePointer(string paramName) 209 { 210 return new ArgumentException(Strings.TypeMustNotBePointer, paramName); 211 } 212 213 /// <summary> 214 /// ArgumentException with message like "Setter should have void type." 215 /// </summary> SetterMustBeVoid(string paramName)216 internal static Exception SetterMustBeVoid(string paramName) 217 { 218 return new ArgumentException(Strings.SetterMustBeVoid, paramName); 219 } 220 221 /// <summary> 222 /// ArgumentException with message like "Property type must match the value type of getter" 223 /// </summary> PropertyTypeMustMatchGetter(string paramName)224 internal static Exception PropertyTypeMustMatchGetter(string paramName) 225 { 226 return new ArgumentException(Strings.PropertyTypeMustMatchGetter, paramName); 227 } 228 229 /// <summary> 230 /// ArgumentException with message like "Property type must match the value type of setter" 231 /// </summary> PropertyTypeMustMatchSetter(string paramName)232 internal static Exception PropertyTypeMustMatchSetter(string paramName) 233 { 234 return new ArgumentException(Strings.PropertyTypeMustMatchSetter, paramName); 235 } 236 /// <summary> 237 /// ArgumentException with message like "Both accessors must be static." 238 /// </summary> BothAccessorsMustBeStatic(string paramName)239 internal static Exception BothAccessorsMustBeStatic(string paramName) 240 { 241 return new ArgumentException(Strings.BothAccessorsMustBeStatic, paramName); 242 } 243 /// <summary> 244 /// ArgumentException with message like "Static field requires null instance, non-static field requires non-null instance." 245 /// </summary> OnlyStaticFieldsHaveNullInstance(string paramName)246 internal static Exception OnlyStaticFieldsHaveNullInstance(string paramName) 247 { 248 return new ArgumentException(Strings.OnlyStaticFieldsHaveNullInstance, paramName); 249 } 250 /// <summary> 251 /// ArgumentException with message like "Static property requires null instance, non-static property requires non-null instance." 252 /// </summary> OnlyStaticPropertiesHaveNullInstance(string paramName)253 internal static Exception OnlyStaticPropertiesHaveNullInstance(string paramName) 254 { 255 return new ArgumentException(Strings.OnlyStaticPropertiesHaveNullInstance, paramName); 256 } 257 /// <summary> 258 /// ArgumentException with message like "Static method requires null instance, non-static method requires non-null instance." 259 /// </summary> OnlyStaticMethodsHaveNullInstance()260 internal static Exception OnlyStaticMethodsHaveNullInstance() 261 { 262 return new ArgumentException(Strings.OnlyStaticMethodsHaveNullInstance); 263 } 264 /// <summary> 265 /// ArgumentException with message like "Property cannot have a void type." 266 /// </summary> PropertyTypeCannotBeVoid(string paramName)267 internal static Exception PropertyTypeCannotBeVoid(string paramName) 268 { 269 return new ArgumentException(Strings.PropertyTypeCannotBeVoid, paramName); 270 } 271 /// <summary> 272 /// ArgumentException with message like "Can only unbox from an object or interface type to a value type." 273 /// </summary> InvalidUnboxType(string paramName)274 internal static Exception InvalidUnboxType(string paramName) 275 { 276 return new ArgumentException(Strings.InvalidUnboxType, paramName); 277 } 278 /// <summary> 279 /// ArgumentException with message like "Expression must be writeable" 280 /// </summary> ExpressionMustBeWriteable(string paramName)281 internal static Exception ExpressionMustBeWriteable(string paramName) 282 { 283 return new ArgumentException(Strings.ExpressionMustBeWriteable, paramName); 284 } 285 /// <summary> 286 /// ArgumentException with message like "Argument must not have a value type." 287 /// </summary> ArgumentMustNotHaveValueType(string paramName)288 internal static Exception ArgumentMustNotHaveValueType(string paramName) 289 { 290 return new ArgumentException(Strings.ArgumentMustNotHaveValueType, paramName); 291 } 292 /// <summary> 293 /// ArgumentException with message like "must be reducible node" 294 /// </summary> MustBeReducible()295 internal static Exception MustBeReducible() 296 { 297 return new ArgumentException(Strings.MustBeReducible); 298 } 299 /// <summary> 300 /// ArgumentException with message like "All test values must have the same type." 301 /// </summary> AllTestValuesMustHaveSameType(string paramName)302 internal static Exception AllTestValuesMustHaveSameType(string paramName) 303 { 304 return new ArgumentException(Strings.AllTestValuesMustHaveSameType, paramName); 305 } 306 /// <summary> 307 /// ArgumentException with message like "All case bodies and the default body must have the same type." 308 /// </summary> AllCaseBodiesMustHaveSameType(string paramName)309 internal static Exception AllCaseBodiesMustHaveSameType(string paramName) 310 { 311 return new ArgumentException(Strings.AllCaseBodiesMustHaveSameType, paramName); 312 } 313 /// <summary> 314 /// ArgumentException with message like "Default body must be supplied if case bodies are not System.Void." 315 /// </summary> DefaultBodyMustBeSupplied(string paramName)316 internal static Exception DefaultBodyMustBeSupplied(string paramName) 317 { 318 return new ArgumentException(Strings.DefaultBodyMustBeSupplied, paramName); 319 } 320 /// <summary> 321 /// ArgumentException with message like "Label type must be System.Void if an expression is not supplied" 322 /// </summary> LabelMustBeVoidOrHaveExpression(string paramName)323 internal static Exception LabelMustBeVoidOrHaveExpression(string paramName) 324 { 325 return new ArgumentException(Strings.LabelMustBeVoidOrHaveExpression, paramName); 326 } 327 /// <summary> 328 /// ArgumentException with message like "Type must be System.Void for this label argument" 329 /// </summary> LabelTypeMustBeVoid(string paramName)330 internal static Exception LabelTypeMustBeVoid(string paramName) 331 { 332 return new ArgumentException(Strings.LabelTypeMustBeVoid, paramName); 333 } 334 /// <summary> 335 /// ArgumentException with message like "Quoted expression must be a lambda" 336 /// </summary> QuotedExpressionMustBeLambda(string paramName)337 internal static Exception QuotedExpressionMustBeLambda(string paramName) 338 { 339 return new ArgumentException(Strings.QuotedExpressionMustBeLambda, paramName); 340 } 341 /// <summary> 342 /// ArgumentException with message like "Variable '{0}' uses unsupported type '{1}'. Reference types are not supported for variables." 343 /// </summary> VariableMustNotBeByRef(object p0, object p1, string paramName)344 internal static Exception VariableMustNotBeByRef(object p0, object p1, string paramName) 345 { 346 return new ArgumentException(Strings.VariableMustNotBeByRef(p0, p1), paramName); 347 } 348 /// <summary> 349 /// ArgumentException with message like "Variable '{0}' uses unsupported type '{1}'. Reference types are not supported for variables." 350 /// </summary> VariableMustNotBeByRef(object p0, object p1, string paramName, int index)351 internal static Exception VariableMustNotBeByRef(object p0, object p1, string paramName, int index) 352 { 353 return VariableMustNotBeByRef(p0, p1, GetParamName(paramName, index)); 354 } 355 /// <summary> 356 /// ArgumentException with message like "Found duplicate parameter '{0}'. Each ParameterExpression in the list must be a unique object." 357 /// </summary> DuplicateVariable(object p0, string paramName)358 private static Exception DuplicateVariable(object p0, string paramName) 359 { 360 return new ArgumentException(Strings.DuplicateVariable(p0), paramName); 361 } 362 /// <summary> 363 /// ArgumentException with message like "Found duplicate parameter '{0}'. Each ParameterExpression in the list must be a unique object." 364 /// </summary> DuplicateVariable(object p0, string paramName, int index)365 internal static Exception DuplicateVariable(object p0, string paramName, int index) 366 { 367 return DuplicateVariable(p0, GetParamName(paramName, index)); 368 } 369 /// <summary> 370 /// ArgumentException with message like "Start and End must be well ordered" 371 /// </summary> StartEndMustBeOrdered()372 internal static Exception StartEndMustBeOrdered() 373 { 374 return new ArgumentException(Strings.StartEndMustBeOrdered); 375 } 376 /// <summary> 377 /// ArgumentException with message like "fault cannot be used with catch or finally clauses" 378 /// </summary> FaultCannotHaveCatchOrFinally(string paramName)379 internal static Exception FaultCannotHaveCatchOrFinally(string paramName) 380 { 381 return new ArgumentException(Strings.FaultCannotHaveCatchOrFinally, paramName); 382 } 383 /// <summary> 384 /// ArgumentException with message like "try must have at least one catch, finally, or fault clause" 385 /// </summary> TryMustHaveCatchFinallyOrFault()386 internal static Exception TryMustHaveCatchFinallyOrFault() 387 { 388 return new ArgumentException(Strings.TryMustHaveCatchFinallyOrFault); 389 } 390 /// <summary> 391 /// ArgumentException with message like "Body of catch must have the same type as body of try." 392 /// </summary> BodyOfCatchMustHaveSameTypeAsBodyOfTry()393 internal static Exception BodyOfCatchMustHaveSameTypeAsBodyOfTry() 394 { 395 return new ArgumentException(Strings.BodyOfCatchMustHaveSameTypeAsBodyOfTry); 396 } 397 /// <summary> 398 /// InvalidOperationException with message like "Extension node must override the property {0}." 399 /// </summary> ExtensionNodeMustOverrideProperty(object p0)400 internal static Exception ExtensionNodeMustOverrideProperty(object p0) 401 { 402 return new InvalidOperationException(Strings.ExtensionNodeMustOverrideProperty(p0)); 403 } 404 /// <summary> 405 /// ArgumentException with message like "User-defined operator method '{0}' must be static." 406 /// </summary> UserDefinedOperatorMustBeStatic(object p0, string paramName)407 internal static Exception UserDefinedOperatorMustBeStatic(object p0, string paramName) 408 { 409 return new ArgumentException(Strings.UserDefinedOperatorMustBeStatic(p0), paramName); 410 } 411 /// <summary> 412 /// ArgumentException with message like "User-defined operator method '{0}' must not be void." 413 /// </summary> UserDefinedOperatorMustNotBeVoid(object p0, string paramName)414 internal static Exception UserDefinedOperatorMustNotBeVoid(object p0, string paramName) 415 { 416 return new ArgumentException(Strings.UserDefinedOperatorMustNotBeVoid(p0), paramName); 417 } 418 /// <summary> 419 /// InvalidOperationException with message like "No coercion operator is defined between types '{0}' and '{1}'." 420 /// </summary> CoercionOperatorNotDefined(object p0, object p1)421 internal static Exception CoercionOperatorNotDefined(object p0, object p1) 422 { 423 return new InvalidOperationException(Strings.CoercionOperatorNotDefined(p0, p1)); 424 } 425 /// <summary> 426 /// InvalidOperationException with message like "The unary operator {0} is not defined for the type '{1}'." 427 /// </summary> UnaryOperatorNotDefined(object p0, object p1)428 internal static Exception UnaryOperatorNotDefined(object p0, object p1) 429 { 430 return new InvalidOperationException(Strings.UnaryOperatorNotDefined(p0, p1)); 431 } 432 /// <summary> 433 /// InvalidOperationException with message like "The binary operator {0} is not defined for the types '{1}' and '{2}'." 434 /// </summary> BinaryOperatorNotDefined(object p0, object p1, object p2)435 internal static Exception BinaryOperatorNotDefined(object p0, object p1, object p2) 436 { 437 return new InvalidOperationException(Strings.BinaryOperatorNotDefined(p0, p1, p2)); 438 } 439 /// <summary> 440 /// InvalidOperationException with message like "Reference equality is not defined for the types '{0}' and '{1}'." 441 /// </summary> ReferenceEqualityNotDefined(object p0, object p1)442 internal static Exception ReferenceEqualityNotDefined(object p0, object p1) 443 { 444 return new InvalidOperationException(Strings.ReferenceEqualityNotDefined(p0, p1)); 445 } 446 /// <summary> 447 /// InvalidOperationException with message like "The operands for operator '{0}' do not match the parameters of method '{1}'." 448 /// </summary> OperandTypesDoNotMatchParameters(object p0, object p1)449 internal static Exception OperandTypesDoNotMatchParameters(object p0, object p1) 450 { 451 return new InvalidOperationException(Strings.OperandTypesDoNotMatchParameters(p0, p1)); 452 } 453 /// <summary> 454 /// InvalidOperationException with message like "The return type of overload method for operator '{0}' does not match the parameter type of conversion method '{1}'." 455 /// </summary> OverloadOperatorTypeDoesNotMatchConversionType(object p0, object p1)456 internal static Exception OverloadOperatorTypeDoesNotMatchConversionType(object p0, object p1) 457 { 458 return new InvalidOperationException(Strings.OverloadOperatorTypeDoesNotMatchConversionType(p0, p1)); 459 } 460 /// <summary> 461 /// InvalidOperationException with message like "Conversion is not supported for arithmetic types without operator overloading." 462 /// </summary> ConversionIsNotSupportedForArithmeticTypes()463 internal static Exception ConversionIsNotSupportedForArithmeticTypes() 464 { 465 return new InvalidOperationException(Strings.ConversionIsNotSupportedForArithmeticTypes); 466 } 467 /// <summary> 468 /// ArgumentException with message like "Argument type cannot be void" 469 /// </summary> ArgumentTypeCannotBeVoid()470 internal static Exception ArgumentTypeCannotBeVoid() 471 { 472 return new ArgumentException(Strings.ArgumentTypeCannotBeVoid); 473 } 474 /// <summary> 475 /// ArgumentException with message like "Argument must be array" 476 /// </summary> ArgumentMustBeArray(string paramName)477 internal static Exception ArgumentMustBeArray(string paramName) 478 { 479 return new ArgumentException(Strings.ArgumentMustBeArray, paramName); 480 } 481 /// <summary> 482 /// ArgumentException with message like "Argument must be boolean" 483 /// </summary> ArgumentMustBeBoolean(string paramName)484 internal static Exception ArgumentMustBeBoolean(string paramName) 485 { 486 return new ArgumentException(Strings.ArgumentMustBeBoolean, paramName); 487 } 488 /// <summary> 489 /// ArgumentException with message like "The user-defined equality method '{0}' must return a boolean value." 490 /// </summary> EqualityMustReturnBoolean(object p0, string paramName)491 internal static Exception EqualityMustReturnBoolean(object p0, string paramName) 492 { 493 return new ArgumentException(Strings.EqualityMustReturnBoolean(p0), paramName); 494 } 495 /// <summary> 496 /// ArgumentException with message like "Argument must be either a FieldInfo or PropertyInfo" 497 /// </summary> ArgumentMustBeFieldInfoOrPropertyInfo(string paramName)498 internal static Exception ArgumentMustBeFieldInfoOrPropertyInfo(string paramName) 499 { 500 return new ArgumentException(Strings.ArgumentMustBeFieldInfoOrPropertyInfo, paramName); 501 } 502 /// <summary> 503 /// ArgumentException with message like "Argument must be either a FieldInfo, PropertyInfo or MethodInfo" 504 /// </summary> ArgumentMustBeFieldInfoOrPropertyInfoOrMethod(string paramName)505 private static Exception ArgumentMustBeFieldInfoOrPropertyInfoOrMethod(string paramName) 506 { 507 return new ArgumentException(Strings.ArgumentMustBeFieldInfoOrPropertyInfoOrMethod, paramName); 508 } 509 /// <summary> 510 /// ArgumentException with message like "Argument must be either a FieldInfo, PropertyInfo or MethodInfo" 511 /// </summary> ArgumentMustBeFieldInfoOrPropertyInfoOrMethod(string paramName, int index)512 internal static Exception ArgumentMustBeFieldInfoOrPropertyInfoOrMethod(string paramName, int index) 513 { 514 return ArgumentMustBeFieldInfoOrPropertyInfoOrMethod(GetParamName(paramName, index)); 515 } 516 517 /// <summary> 518 /// ArgumentException with message like "Argument must be an instance member" 519 /// </summary> ArgumentMustBeInstanceMember(string paramName)520 private static Exception ArgumentMustBeInstanceMember(string paramName) 521 { 522 return new ArgumentException(Strings.ArgumentMustBeInstanceMember, paramName); 523 } 524 /// <summary> 525 /// ArgumentException with message like "Argument must be an instance member" 526 /// </summary> ArgumentMustBeInstanceMember(string paramName, int index)527 internal static Exception ArgumentMustBeInstanceMember(string paramName, int index) 528 { 529 return ArgumentMustBeInstanceMember(GetParamName(paramName, index)); 530 } 531 /// <summary> 532 /// ArgumentException with message like "Argument must be of an integer type" 533 /// </summary> ArgumentMustBeInteger(string paramName)534 private static Exception ArgumentMustBeInteger(string paramName) 535 { 536 return new ArgumentException(Strings.ArgumentMustBeInteger, paramName); 537 } 538 /// <summary> 539 /// ArgumentException with message like "Argument must be of an integer type" 540 /// </summary> ArgumentMustBeInteger(string paramName, int index)541 internal static Exception ArgumentMustBeInteger(string paramName, int index) 542 { 543 return ArgumentMustBeInteger(GetParamName(paramName, index)); 544 } 545 /// <summary> 546 /// ArgumentException with message like "Argument for array index must be of type Int32" 547 /// </summary> ArgumentMustBeArrayIndexType(string paramName)548 internal static Exception ArgumentMustBeArrayIndexType(string paramName) 549 { 550 return new ArgumentException(Strings.ArgumentMustBeArrayIndexType, paramName); 551 } 552 /// <summary> 553 /// ArgumentException with message like "Argument for array index must be of type Int32" 554 /// </summary> ArgumentMustBeArrayIndexType(string paramName, int index)555 internal static Exception ArgumentMustBeArrayIndexType(string paramName, int index) 556 { 557 return ArgumentMustBeArrayIndexType(GetParamName(paramName, index)); 558 } 559 /// <summary> 560 /// ArgumentException with message like "Argument must be single-dimensional, zero-based array type" 561 /// </summary> ArgumentMustBeSingleDimensionalArrayType(string paramName)562 internal static Exception ArgumentMustBeSingleDimensionalArrayType(string paramName) 563 { 564 return new ArgumentException(Strings.ArgumentMustBeSingleDimensionalArrayType, paramName); 565 } 566 /// <summary> 567 /// ArgumentException with message like "Argument types do not match" 568 /// </summary> ArgumentTypesMustMatch()569 internal static Exception ArgumentTypesMustMatch() 570 { 571 return new ArgumentException(Strings.ArgumentTypesMustMatch); 572 } 573 /// <summary> 574 /// ArgumentException with message like "Argument types do not match" 575 /// </summary> ArgumentTypesMustMatch(string paramName)576 internal static Exception ArgumentTypesMustMatch(string paramName) 577 { 578 return new ArgumentException(Strings.ArgumentTypesMustMatch, paramName); 579 } 580 /// <summary> 581 /// InvalidOperationException with message like "Cannot auto initialize elements of value type through property '{0}', use assignment instead" 582 /// </summary> CannotAutoInitializeValueTypeElementThroughProperty(object p0)583 internal static Exception CannotAutoInitializeValueTypeElementThroughProperty(object p0) 584 { 585 return new InvalidOperationException(Strings.CannotAutoInitializeValueTypeElementThroughProperty(p0)); 586 } 587 /// <summary> 588 /// InvalidOperationException with message like "Cannot auto initialize members of value type through property '{0}', use assignment instead" 589 /// </summary> CannotAutoInitializeValueTypeMemberThroughProperty(object p0)590 internal static Exception CannotAutoInitializeValueTypeMemberThroughProperty(object p0) 591 { 592 return new InvalidOperationException(Strings.CannotAutoInitializeValueTypeMemberThroughProperty(p0)); 593 } 594 /// <summary> 595 /// ArgumentException with message like "The type used in TypeAs Expression must be of reference or nullable type, {0} is neither" 596 /// </summary> IncorrectTypeForTypeAs(object p0, string paramName)597 internal static Exception IncorrectTypeForTypeAs(object p0, string paramName) 598 { 599 return new ArgumentException(Strings.IncorrectTypeForTypeAs(p0), paramName); 600 } 601 /// <summary> 602 /// InvalidOperationException with message like "Coalesce used with type that cannot be null" 603 /// </summary> CoalesceUsedOnNonNullType()604 internal static Exception CoalesceUsedOnNonNullType() 605 { 606 return new InvalidOperationException(Strings.CoalesceUsedOnNonNullType); 607 } 608 /// <summary> 609 /// InvalidOperationException with message like "An expression of type '{0}' cannot be used to initialize an array of type '{1}'" 610 /// </summary> ExpressionTypeCannotInitializeArrayType(object p0, object p1)611 internal static Exception ExpressionTypeCannotInitializeArrayType(object p0, object p1) 612 { 613 return new InvalidOperationException(Strings.ExpressionTypeCannotInitializeArrayType(p0, p1)); 614 } 615 616 /// <summary> 617 /// ArgumentException with message like " Argument type '{0}' does not match the corresponding member type '{1}'" 618 /// </summary> ArgumentTypeDoesNotMatchMember(object p0, object p1, string paramName)619 private static Exception ArgumentTypeDoesNotMatchMember(object p0, object p1, string paramName) 620 { 621 return new ArgumentException(Strings.ArgumentTypeDoesNotMatchMember(p0, p1), paramName); 622 } 623 /// <summary> 624 /// ArgumentException with message like " Argument type '{0}' does not match the corresponding member type '{1}'" 625 /// </summary> ArgumentTypeDoesNotMatchMember(object p0, object p1, string paramName, int index)626 internal static Exception ArgumentTypeDoesNotMatchMember(object p0, object p1, string paramName, int index) 627 { 628 return ArgumentTypeDoesNotMatchMember(p0, p1, GetParamName(paramName, index)); 629 } 630 /// <summary> 631 /// ArgumentException with message like " The member '{0}' is not declared on type '{1}' being created" 632 /// </summary> ArgumentMemberNotDeclOnType(object p0, object p1, string paramName)633 private static Exception ArgumentMemberNotDeclOnType(object p0, object p1, string paramName) 634 { 635 return new ArgumentException(Strings.ArgumentMemberNotDeclOnType(p0, p1), paramName); 636 } 637 /// <summary> 638 /// ArgumentException with message like " The member '{0}' is not declared on type '{1}' being created" 639 /// </summary> ArgumentMemberNotDeclOnType(object p0, object p1, string paramName, int index)640 internal static Exception ArgumentMemberNotDeclOnType(object p0, object p1, string paramName, int index) 641 { 642 return ArgumentMemberNotDeclOnType(p0, p1, GetParamName(paramName, index)); 643 } 644 645 /// <summary> 646 /// ArgumentException with message like "Expression of type '{0}' cannot be used for return type '{1}'" 647 /// </summary> ExpressionTypeDoesNotMatchReturn(object p0, object p1)648 internal static Exception ExpressionTypeDoesNotMatchReturn(object p0, object p1) 649 { 650 return new ArgumentException(Strings.ExpressionTypeDoesNotMatchReturn(p0, p1)); 651 } 652 /// <summary> 653 /// ArgumentException with message like "Expression of type '{0}' cannot be used for assignment to type '{1}'" 654 /// </summary> ExpressionTypeDoesNotMatchAssignment(object p0, object p1)655 internal static Exception ExpressionTypeDoesNotMatchAssignment(object p0, object p1) 656 { 657 return new ArgumentException(Strings.ExpressionTypeDoesNotMatchAssignment(p0, p1)); 658 } 659 /// <summary> 660 /// ArgumentException with message like "Expression of type '{0}' cannot be used for label of type '{1}'" 661 /// </summary> ExpressionTypeDoesNotMatchLabel(object p0, object p1)662 internal static Exception ExpressionTypeDoesNotMatchLabel(object p0, object p1) 663 { 664 return new ArgumentException(Strings.ExpressionTypeDoesNotMatchLabel(p0, p1)); 665 } 666 /// <summary> 667 /// ArgumentException with message like "Expression of type '{0}' cannot be invoked" 668 /// </summary> ExpressionTypeNotInvocable(object p0, string paramName)669 internal static Exception ExpressionTypeNotInvocable(object p0, string paramName) 670 { 671 return new ArgumentException(Strings.ExpressionTypeNotInvocable(p0), paramName); 672 } 673 /// <summary> 674 /// ArgumentException with message like "Field '{0}' is not defined for type '{1}'" 675 /// </summary> FieldNotDefinedForType(object p0, object p1)676 internal static Exception FieldNotDefinedForType(object p0, object p1) 677 { 678 return new ArgumentException(Strings.FieldNotDefinedForType(p0, p1)); 679 } 680 /// <summary> 681 /// ArgumentException with message like "Instance field '{0}' is not defined for type '{1}'" 682 /// </summary> InstanceFieldNotDefinedForType(object p0, object p1)683 internal static Exception InstanceFieldNotDefinedForType(object p0, object p1) 684 { 685 return new ArgumentException(Strings.InstanceFieldNotDefinedForType(p0, p1)); 686 } 687 /// <summary> 688 /// ArgumentException with message like "Field '{0}.{1}' is not defined for type '{2}'" 689 /// </summary> FieldInfoNotDefinedForType(object p0, object p1, object p2)690 internal static Exception FieldInfoNotDefinedForType(object p0, object p1, object p2) 691 { 692 return new ArgumentException(Strings.FieldInfoNotDefinedForType(p0, p1, p2)); 693 } 694 /// <summary> 695 /// ArgumentException with message like "Incorrect number of indexes" 696 /// </summary> IncorrectNumberOfIndexes()697 internal static Exception IncorrectNumberOfIndexes() 698 { 699 return new ArgumentException(Strings.IncorrectNumberOfIndexes); 700 } 701 /// <summary> 702 /// ArgumentException with message like "Incorrect number of parameters supplied for lambda declaration" 703 /// </summary> IncorrectNumberOfLambdaDeclarationParameters()704 internal static Exception IncorrectNumberOfLambdaDeclarationParameters() 705 { 706 return new ArgumentException(Strings.IncorrectNumberOfLambdaDeclarationParameters); 707 } 708 709 /// <summary> 710 /// ArgumentException with message like " Incorrect number of members for constructor" 711 /// </summary> IncorrectNumberOfMembersForGivenConstructor()712 internal static Exception IncorrectNumberOfMembersForGivenConstructor() 713 { 714 return new ArgumentException(Strings.IncorrectNumberOfMembersForGivenConstructor); 715 } 716 /// <summary> 717 /// ArgumentException with message like "Incorrect number of arguments for the given members " 718 /// </summary> IncorrectNumberOfArgumentsForMembers()719 internal static Exception IncorrectNumberOfArgumentsForMembers() 720 { 721 return new ArgumentException(Strings.IncorrectNumberOfArgumentsForMembers); 722 } 723 /// <summary> 724 /// ArgumentException with message like "Lambda type parameter must be derived from System.MulticastDelegate" 725 /// </summary> LambdaTypeMustBeDerivedFromSystemDelegate(string paramName)726 internal static Exception LambdaTypeMustBeDerivedFromSystemDelegate(string paramName) 727 { 728 return new ArgumentException(Strings.LambdaTypeMustBeDerivedFromSystemDelegate, paramName); 729 } 730 /// <summary> 731 /// ArgumentException with message like "Member '{0}' not field or property" 732 /// </summary> MemberNotFieldOrProperty(object p0, string paramName)733 internal static Exception MemberNotFieldOrProperty(object p0, string paramName) 734 { 735 return new ArgumentException(Strings.MemberNotFieldOrProperty(p0), paramName); 736 } 737 /// <summary> 738 /// ArgumentException with message like "Method {0} contains generic parameters" 739 /// </summary> MethodContainsGenericParameters(object p0, string paramName)740 internal static Exception MethodContainsGenericParameters(object p0, string paramName) 741 { 742 return new ArgumentException(Strings.MethodContainsGenericParameters(p0), paramName); 743 } 744 /// <summary> 745 /// ArgumentException with message like "Method {0} is a generic method definition" 746 /// </summary> MethodIsGeneric(object p0, string paramName)747 internal static Exception MethodIsGeneric(object p0, string paramName) 748 { 749 return new ArgumentException(Strings.MethodIsGeneric(p0), paramName); 750 } 751 /// <summary> 752 /// ArgumentException with message like "The method '{0}.{1}' is not a property accessor" 753 /// </summary> MethodNotPropertyAccessor(object p0, object p1, string paramName)754 private static Exception MethodNotPropertyAccessor(object p0, object p1, string paramName) 755 { 756 return new ArgumentException(Strings.MethodNotPropertyAccessor(p0, p1), paramName); 757 } 758 /// <summary> 759 /// ArgumentException with message like "The method '{0}.{1}' is not a property accessor" 760 /// </summary> MethodNotPropertyAccessor(object p0, object p1, string paramName, int index)761 internal static Exception MethodNotPropertyAccessor(object p0, object p1, string paramName, int index) 762 { 763 return MethodNotPropertyAccessor(p0, p1, GetParamName(paramName, index)); 764 } 765 /// <summary> 766 /// ArgumentException with message like "The property '{0}' has no 'get' accessor" 767 /// </summary> PropertyDoesNotHaveGetter(object p0, string paramName)768 internal static Exception PropertyDoesNotHaveGetter(object p0, string paramName) 769 { 770 return new ArgumentException(Strings.PropertyDoesNotHaveGetter(p0), paramName); 771 } 772 /// <summary> 773 /// ArgumentException with message like "The property '{0}' has no 'get' accessor" 774 /// </summary> PropertyDoesNotHaveGetter(object p0, string paramName, int index)775 internal static Exception PropertyDoesNotHaveGetter(object p0, string paramName, int index) 776 { 777 return PropertyDoesNotHaveGetter(p0, GetParamName(paramName, index)); 778 } 779 /// <summary> 780 /// ArgumentException with message like "The property '{0}' has no 'set' accessor" 781 /// </summary> PropertyDoesNotHaveSetter(object p0, string paramName)782 internal static Exception PropertyDoesNotHaveSetter(object p0, string paramName) 783 { 784 return new ArgumentException(Strings.PropertyDoesNotHaveSetter(p0), paramName); 785 } 786 /// <summary> 787 /// ArgumentException with message like "The property '{0}' has no 'get' or 'set' accessors" 788 /// </summary> PropertyDoesNotHaveAccessor(object p0, string paramName)789 internal static Exception PropertyDoesNotHaveAccessor(object p0, string paramName) 790 { 791 return new ArgumentException(Strings.PropertyDoesNotHaveAccessor(p0), paramName); 792 } 793 /// <summary> 794 /// ArgumentException with message like "'{0}' is not a member of type '{1}'" 795 /// </summary> NotAMemberOfType(object p0, object p1, string paramName)796 internal static Exception NotAMemberOfType(object p0, object p1, string paramName) 797 { 798 return new ArgumentException(Strings.NotAMemberOfType(p0, p1), paramName); 799 } 800 /// <summary> 801 /// ArgumentException with message like "'{0}' is not a member of type '{1}'" 802 /// </summary> NotAMemberOfType(object p0, object p1, string paramName, int index)803 internal static Exception NotAMemberOfType(object p0, object p1, string paramName, int index) 804 { 805 return NotAMemberOfType(p0, p1, GetParamName(paramName, index)); 806 } 807 808 /// <summary> 809 /// ArgumentException with message like "'{0}' is not a member of any type" 810 /// </summary> NotAMemberOfAnyType(object p0, string paramName)811 internal static Exception NotAMemberOfAnyType(object p0, string paramName) 812 { 813 return new ArgumentException(Strings.NotAMemberOfAnyType(p0), paramName); 814 } 815 816 /// <summary> 817 /// ArgumentException with message like "ParameterExpression of type '{0}' cannot be used for delegate parameter of type '{1}'" 818 /// </summary> ParameterExpressionNotValidAsDelegate(object p0, object p1)819 internal static Exception ParameterExpressionNotValidAsDelegate(object p0, object p1) 820 { 821 return new ArgumentException(Strings.ParameterExpressionNotValidAsDelegate(p0, p1)); 822 } 823 /// <summary> 824 /// ArgumentException with message like "Property '{0}' is not defined for type '{1}'" 825 /// </summary> PropertyNotDefinedForType(object p0, object p1, string paramName)826 internal static Exception PropertyNotDefinedForType(object p0, object p1, string paramName) 827 { 828 return new ArgumentException(Strings.PropertyNotDefinedForType(p0, p1), paramName); 829 } 830 /// <summary> 831 /// ArgumentException with message like "Instance property '{0}' is not defined for type '{1}'" 832 /// </summary> InstancePropertyNotDefinedForType(object p0, object p1, string paramName)833 internal static Exception InstancePropertyNotDefinedForType(object p0, object p1, string paramName) 834 { 835 return new ArgumentException(Strings.InstancePropertyNotDefinedForType(p0, p1), paramName); 836 } 837 /// <summary> 838 /// ArgumentException with message like "Instance property '{0}' that takes no argument is not defined for type '{1}'" 839 /// </summary> InstancePropertyWithoutParameterNotDefinedForType(object p0, object p1)840 internal static Exception InstancePropertyWithoutParameterNotDefinedForType(object p0, object p1) 841 { 842 return new ArgumentException(Strings.InstancePropertyWithoutParameterNotDefinedForType(p0, p1)); 843 } 844 /// <summary> 845 /// ArgumentException with message like "Instance property '{0}{1}' is not defined for type '{2}'" 846 /// </summary> InstancePropertyWithSpecifiedParametersNotDefinedForType(object p0, object p1, object p2, string paramName)847 internal static Exception InstancePropertyWithSpecifiedParametersNotDefinedForType(object p0, object p1, object p2, string paramName) 848 { 849 return new ArgumentException(Strings.InstancePropertyWithSpecifiedParametersNotDefinedForType(p0, p1, p2), paramName); 850 } 851 /// <summary> 852 /// ArgumentException with message like "Method '{0}' declared on type '{1}' cannot be called with instance of type '{2}'" 853 /// </summary> InstanceAndMethodTypeMismatch(object p0, object p1, object p2)854 internal static Exception InstanceAndMethodTypeMismatch(object p0, object p1, object p2) 855 { 856 return new ArgumentException(Strings.InstanceAndMethodTypeMismatch(p0, p1, p2)); 857 } 858 859 /// <summary> 860 /// ArgumentException with message like "Type '{0}' does not have a default constructor" 861 /// </summary> TypeMissingDefaultConstructor(object p0, string paramName)862 internal static Exception TypeMissingDefaultConstructor(object p0, string paramName) 863 { 864 return new ArgumentException(Strings.TypeMissingDefaultConstructor(p0), paramName); 865 } 866 867 /// <summary> 868 /// ArgumentException with message like "Element initializer method must be named 'Add'" 869 /// </summary> ElementInitializerMethodNotAdd(string paramName)870 internal static Exception ElementInitializerMethodNotAdd(string paramName) 871 { 872 return new ArgumentException(Strings.ElementInitializerMethodNotAdd, paramName); 873 } 874 /// <summary> 875 /// ArgumentException with message like "Parameter '{0}' of element initializer method '{1}' must not be a pass by reference parameter" 876 /// </summary> ElementInitializerMethodNoRefOutParam(object p0, object p1, string paramName)877 internal static Exception ElementInitializerMethodNoRefOutParam(object p0, object p1, string paramName) 878 { 879 return new ArgumentException(Strings.ElementInitializerMethodNoRefOutParam(p0, p1), paramName); 880 } 881 /// <summary> 882 /// ArgumentException with message like "Element initializer method must have at least 1 parameter" 883 /// </summary> ElementInitializerMethodWithZeroArgs(string paramName)884 internal static Exception ElementInitializerMethodWithZeroArgs(string paramName) 885 { 886 return new ArgumentException(Strings.ElementInitializerMethodWithZeroArgs, paramName); 887 } 888 /// <summary> 889 /// ArgumentException with message like "Element initializer method must be an instance method" 890 /// </summary> ElementInitializerMethodStatic(string paramName)891 internal static Exception ElementInitializerMethodStatic(string paramName) 892 { 893 return new ArgumentException(Strings.ElementInitializerMethodStatic, paramName); 894 } 895 /// <summary> 896 /// ArgumentException with message like "Type '{0}' is not IEnumerable" 897 /// </summary> TypeNotIEnumerable(object p0, string paramName)898 internal static Exception TypeNotIEnumerable(object p0, string paramName) 899 { 900 return new ArgumentException(Strings.TypeNotIEnumerable(p0), paramName); 901 } 902 903 /// <summary> 904 /// ArgumentException with message like "Unhandled binary: {0}" 905 /// </summary> UnhandledBinary(object p0, string paramName)906 internal static Exception UnhandledBinary(object p0, string paramName) 907 { 908 return new ArgumentException(Strings.UnhandledBinary(p0), paramName); 909 } 910 /// <summary> 911 /// ArgumentException with message like "Unhandled binding " 912 /// </summary> UnhandledBinding()913 internal static Exception UnhandledBinding() 914 { 915 return new ArgumentException(Strings.UnhandledBinding); 916 } 917 /// <summary> 918 /// ArgumentException with message like "Unhandled Binding Type: {0}" 919 /// </summary> UnhandledBindingType(object p0)920 internal static Exception UnhandledBindingType(object p0) 921 { 922 return new ArgumentException(Strings.UnhandledBindingType(p0)); 923 } 924 925 /// <summary> 926 /// ArgumentException with message like "Unhandled unary: {0}" 927 /// </summary> UnhandledUnary(object p0, string paramName)928 internal static Exception UnhandledUnary(object p0, string paramName) 929 { 930 return new ArgumentException(Strings.UnhandledUnary(p0), paramName); 931 } 932 /// <summary> 933 /// ArgumentException with message like "Unknown binding type" 934 /// </summary> UnknownBindingType(int index)935 internal static Exception UnknownBindingType(int index) 936 { 937 return new ArgumentException(Strings.UnknownBindingType, $"bindings[{index}]"); 938 } 939 /// <summary> 940 /// ArgumentException with message like "The user-defined operator method '{1}' for operator '{0}' must have identical parameter and return types." 941 /// </summary> UserDefinedOpMustHaveConsistentTypes(object p0, object p1)942 internal static Exception UserDefinedOpMustHaveConsistentTypes(object p0, object p1) 943 { 944 return new ArgumentException(Strings.UserDefinedOpMustHaveConsistentTypes(p0, p1)); 945 } 946 /// <summary> 947 /// ArgumentException with message like "The user-defined operator method '{1}' for operator '{0}' must return the same type as its parameter or a derived type." 948 /// </summary> UserDefinedOpMustHaveValidReturnType(object p0, object p1)949 internal static Exception UserDefinedOpMustHaveValidReturnType(object p0, object p1) 950 { 951 return new ArgumentException(Strings.UserDefinedOpMustHaveValidReturnType(p0, p1)); 952 } 953 /// <summary> 954 /// ArgumentException with message like "The user-defined operator method '{1}' for operator '{0}' must have associated boolean True and False operators." 955 /// </summary> LogicalOperatorMustHaveBooleanOperators(object p0, object p1)956 internal static Exception LogicalOperatorMustHaveBooleanOperators(object p0, object p1) 957 { 958 return new ArgumentException(Strings.LogicalOperatorMustHaveBooleanOperators(p0, p1)); 959 } 960 /// <summary> 961 /// InvalidOperationException with message like "No method '{0}' on type '{1}' is compatible with the supplied arguments." 962 /// </summary> MethodWithArgsDoesNotExistOnType(object p0, object p1)963 internal static Exception MethodWithArgsDoesNotExistOnType(object p0, object p1) 964 { 965 return new InvalidOperationException(Strings.MethodWithArgsDoesNotExistOnType(p0, p1)); 966 } 967 /// <summary> 968 /// InvalidOperationException with message like "No generic method '{0}' on type '{1}' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. " 969 /// </summary> GenericMethodWithArgsDoesNotExistOnType(object p0, object p1)970 internal static Exception GenericMethodWithArgsDoesNotExistOnType(object p0, object p1) 971 { 972 return new InvalidOperationException(Strings.GenericMethodWithArgsDoesNotExistOnType(p0, p1)); 973 } 974 /// <summary> 975 /// InvalidOperationException with message like "More than one method '{0}' on type '{1}' is compatible with the supplied arguments." 976 /// </summary> MethodWithMoreThanOneMatch(object p0, object p1)977 internal static Exception MethodWithMoreThanOneMatch(object p0, object p1) 978 { 979 return new InvalidOperationException(Strings.MethodWithMoreThanOneMatch(p0, p1)); 980 } 981 /// <summary> 982 /// InvalidOperationException with message like "More than one property '{0}' on type '{1}' is compatible with the supplied arguments." 983 /// </summary> PropertyWithMoreThanOneMatch(object p0, object p1)984 internal static Exception PropertyWithMoreThanOneMatch(object p0, object p1) 985 { 986 return new InvalidOperationException(Strings.PropertyWithMoreThanOneMatch(p0, p1)); 987 } 988 /// <summary> 989 /// ArgumentException with message like "An incorrect number of type arguments were specified for the declaration of a Func type." 990 /// </summary> IncorrectNumberOfTypeArgsForFunc(string paramName)991 internal static Exception IncorrectNumberOfTypeArgsForFunc(string paramName) 992 { 993 return new ArgumentException(Strings.IncorrectNumberOfTypeArgsForFunc, paramName); 994 } 995 /// <summary> 996 /// ArgumentException with message like "An incorrect number of type arguments were specified for the declaration of an Action type." 997 /// </summary> IncorrectNumberOfTypeArgsForAction(string paramName)998 internal static Exception IncorrectNumberOfTypeArgsForAction(string paramName) 999 { 1000 return new ArgumentException(Strings.IncorrectNumberOfTypeArgsForAction, paramName); 1001 } 1002 /// <summary> 1003 /// ArgumentException with message like "Argument type cannot be System.Void." 1004 /// </summary> ArgumentCannotBeOfTypeVoid(string paramName)1005 internal static Exception ArgumentCannotBeOfTypeVoid(string paramName) 1006 { 1007 return new ArgumentException(Strings.ArgumentCannotBeOfTypeVoid, paramName); 1008 } 1009 /// <summary> 1010 /// ArgumentOutOfRangeException with message like "{0} must be greater than or equal to {1}" 1011 /// </summary> OutOfRange(string paramName, object p1)1012 internal static Exception OutOfRange(string paramName, object p1) 1013 { 1014 return new ArgumentOutOfRangeException(paramName, Strings.OutOfRange(paramName, p1)); 1015 } 1016 /// <summary> 1017 /// InvalidOperationException with message like "Cannot redefine label '{0}' in an inner block." 1018 /// </summary> LabelTargetAlreadyDefined(object p0)1019 internal static Exception LabelTargetAlreadyDefined(object p0) 1020 { 1021 return new InvalidOperationException(Strings.LabelTargetAlreadyDefined(p0)); 1022 } 1023 /// <summary> 1024 /// InvalidOperationException with message like "Cannot jump to undefined label '{0}'." 1025 /// </summary> LabelTargetUndefined(object p0)1026 internal static Exception LabelTargetUndefined(object p0) 1027 { 1028 return new InvalidOperationException(Strings.LabelTargetUndefined(p0)); 1029 } 1030 /// <summary> 1031 /// InvalidOperationException with message like "Control cannot leave a finally block." 1032 /// </summary> ControlCannotLeaveFinally()1033 internal static Exception ControlCannotLeaveFinally() 1034 { 1035 return new InvalidOperationException(Strings.ControlCannotLeaveFinally); 1036 } 1037 /// <summary> 1038 /// InvalidOperationException with message like "Control cannot leave a filter test." 1039 /// </summary> ControlCannotLeaveFilterTest()1040 internal static Exception ControlCannotLeaveFilterTest() 1041 { 1042 return new InvalidOperationException(Strings.ControlCannotLeaveFilterTest); 1043 } 1044 /// <summary> 1045 /// InvalidOperationException with message like "Cannot jump to ambiguous label '{0}'." 1046 /// </summary> AmbiguousJump(object p0)1047 internal static Exception AmbiguousJump(object p0) 1048 { 1049 return new InvalidOperationException(Strings.AmbiguousJump(p0)); 1050 } 1051 /// <summary> 1052 /// InvalidOperationException with message like "Control cannot enter a try block." 1053 /// </summary> ControlCannotEnterTry()1054 internal static Exception ControlCannotEnterTry() 1055 { 1056 return new InvalidOperationException(Strings.ControlCannotEnterTry); 1057 } 1058 /// <summary> 1059 /// InvalidOperationException with message like "Control cannot enter an expression--only statements can be jumped into." 1060 /// </summary> ControlCannotEnterExpression()1061 internal static Exception ControlCannotEnterExpression() 1062 { 1063 return new InvalidOperationException(Strings.ControlCannotEnterExpression); 1064 } 1065 /// <summary> 1066 /// InvalidOperationException with message like "Cannot jump to non-local label '{0}' with a value. Only jumps to labels defined in outer blocks can pass values." 1067 /// </summary> NonLocalJumpWithValue(object p0)1068 internal static Exception NonLocalJumpWithValue(object p0) 1069 { 1070 return new InvalidOperationException(Strings.NonLocalJumpWithValue(p0)); 1071 } 1072 1073 #if FEATURE_COMPILE_TO_METHODBUILDER 1074 /// <summary> 1075 /// InvalidOperationException with message like "CompileToMethod cannot compile constant '{0}' because it is a non-trivial value, such as a live object. Instead, create an expression tree that can construct this value." 1076 /// </summary> CannotCompileConstant(object p0)1077 internal static Exception CannotCompileConstant(object p0) 1078 { 1079 return new InvalidOperationException(Strings.CannotCompileConstant(p0)); 1080 } 1081 /// <summary> 1082 /// NotSupportedException with message like "Dynamic expressions are not supported by CompileToMethod. Instead, create an expression tree that uses System.Runtime.CompilerServices.CallSite." 1083 /// </summary> CannotCompileDynamic()1084 internal static Exception CannotCompileDynamic() 1085 { 1086 return new NotSupportedException(Strings.CannotCompileDynamic); 1087 } 1088 /// <summary> 1089 /// ArgumentException with message like "MethodBuilder does not have a valid TypeBuilder" 1090 /// </summary> MethodBuilderDoesNotHaveTypeBuilder()1091 internal static Exception MethodBuilderDoesNotHaveTypeBuilder() 1092 { 1093 return new ArgumentException(Strings.MethodBuilderDoesNotHaveTypeBuilder); 1094 } 1095 #endif 1096 /// <summary> 1097 /// InvalidOperationException with message like "Invalid lvalue for assignment: {0}." 1098 /// </summary> InvalidLvalue(ExpressionType p0)1099 internal static Exception InvalidLvalue(ExpressionType p0) 1100 { 1101 return new InvalidOperationException(Strings.InvalidLvalue(p0)); 1102 } 1103 1104 /// <summary> 1105 /// InvalidOperationException with message like "variable '{0}' of type '{1}' referenced from scope '{2}', but it is not defined" 1106 /// </summary> UndefinedVariable(object p0, object p1, object p2)1107 internal static Exception UndefinedVariable(object p0, object p1, object p2) 1108 { 1109 return new InvalidOperationException(Strings.UndefinedVariable(p0, p1, p2)); 1110 } 1111 /// <summary> 1112 /// InvalidOperationException with message like "Cannot close over byref parameter '{0}' referenced in lambda '{1}'" 1113 /// </summary> CannotCloseOverByRef(object p0, object p1)1114 internal static Exception CannotCloseOverByRef(object p0, object p1) 1115 { 1116 return new InvalidOperationException(Strings.CannotCloseOverByRef(p0, p1)); 1117 } 1118 /// <summary> 1119 /// InvalidOperationException with message like "Unexpected VarArgs call to method '{0}'" 1120 /// </summary> UnexpectedVarArgsCall(object p0)1121 internal static Exception UnexpectedVarArgsCall(object p0) 1122 { 1123 return new InvalidOperationException(Strings.UnexpectedVarArgsCall(p0)); 1124 } 1125 /// <summary> 1126 /// InvalidOperationException with message like "Rethrow statement is valid only inside a Catch block." 1127 /// </summary> RethrowRequiresCatch()1128 internal static Exception RethrowRequiresCatch() 1129 { 1130 return new InvalidOperationException(Strings.RethrowRequiresCatch); 1131 } 1132 /// <summary> 1133 /// InvalidOperationException with message like "Try expression is not allowed inside a filter body." 1134 /// </summary> TryNotAllowedInFilter()1135 internal static Exception TryNotAllowedInFilter() 1136 { 1137 return new InvalidOperationException(Strings.TryNotAllowedInFilter); 1138 } 1139 /// <summary> 1140 /// InvalidOperationException with message like "When called from '{0}', rewriting a node of type '{1}' must return a non-null value of the same type. Alternatively, override '{2}' and change it to not visit children of this type." 1141 /// </summary> MustRewriteToSameNode(object p0, object p1, object p2)1142 internal static Exception MustRewriteToSameNode(object p0, object p1, object p2) 1143 { 1144 return new InvalidOperationException(Strings.MustRewriteToSameNode(p0, p1, p2)); 1145 } 1146 /// <summary> 1147 /// InvalidOperationException with message like "Rewriting child expression from type '{0}' to type '{1}' is not allowed, because it would change the meaning of the operation. If this is intentional, override '{2}' and change it to allow this rewrite." 1148 /// </summary> MustRewriteChildToSameType(object p0, object p1, object p2)1149 internal static Exception MustRewriteChildToSameType(object p0, object p1, object p2) 1150 { 1151 return new InvalidOperationException(Strings.MustRewriteChildToSameType(p0, p1, p2)); 1152 } 1153 /// <summary> 1154 /// InvalidOperationException with message like "Rewritten expression calls operator method '{0}', but the original node had no operator method. If this is intentional, override '{1}' and change it to allow this rewrite." 1155 /// </summary> MustRewriteWithoutMethod(object p0, object p1)1156 internal static Exception MustRewriteWithoutMethod(object p0, object p1) 1157 { 1158 return new InvalidOperationException(Strings.MustRewriteWithoutMethod(p0, p1)); 1159 } 1160 /// <summary> 1161 /// NotSupportedException with message like "TryExpression is not supported as an argument to method '{0}' because it has an argument with by-ref type. Construct the tree so the TryExpression is not nested inside of this expression." 1162 /// </summary> TryNotSupportedForMethodsWithRefArgs(object p0)1163 internal static Exception TryNotSupportedForMethodsWithRefArgs(object p0) 1164 { 1165 return new NotSupportedException(Strings.TryNotSupportedForMethodsWithRefArgs(p0)); 1166 } 1167 /// <summary> 1168 /// NotSupportedException with message like "TryExpression is not supported as a child expression when accessing a member on type '{0}' because it is a value type. Construct the tree so the TryExpression is not nested inside of this expression." 1169 /// </summary> TryNotSupportedForValueTypeInstances(object p0)1170 internal static Exception TryNotSupportedForValueTypeInstances(object p0) 1171 { 1172 return new NotSupportedException(Strings.TryNotSupportedForValueTypeInstances(p0)); 1173 } 1174 1175 /// <summary> 1176 /// ArgumentException with message like "Test value of type '{0}' cannot be used for the comparison method parameter of type '{1}'" 1177 /// </summary> TestValueTypeDoesNotMatchComparisonMethodParameter(object p0, object p1)1178 internal static Exception TestValueTypeDoesNotMatchComparisonMethodParameter(object p0, object p1) 1179 { 1180 return new ArgumentException(Strings.TestValueTypeDoesNotMatchComparisonMethodParameter(p0, p1)); 1181 } 1182 /// <summary> 1183 /// ArgumentException with message like "Switch value of type '{0}' cannot be used for the comparison method parameter of type '{1}'" 1184 /// </summary> SwitchValueTypeDoesNotMatchComparisonMethodParameter(object p0, object p1)1185 internal static Exception SwitchValueTypeDoesNotMatchComparisonMethodParameter(object p0, object p1) 1186 { 1187 return new ArgumentException(Strings.SwitchValueTypeDoesNotMatchComparisonMethodParameter(p0, p1)); 1188 } 1189 1190 #if FEATURE_COMPILE_TO_METHODBUILDER && FEATURE_PDB_GENERATOR 1191 /// <summary> 1192 /// NotSupportedException with message like "DebugInfoGenerator created by CreatePdbGenerator can only be used with LambdaExpression.CompileToMethod." 1193 /// </summary> PdbGeneratorNeedsExpressionCompiler()1194 internal static Exception PdbGeneratorNeedsExpressionCompiler() 1195 { 1196 return new NotSupportedException(Strings.PdbGeneratorNeedsExpressionCompiler); 1197 } 1198 #endif 1199 1200 /// <summary> 1201 /// The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method. 1202 /// </summary> ArgumentOutOfRange(string paramName)1203 internal static Exception ArgumentOutOfRange(string paramName) 1204 { 1205 return new ArgumentOutOfRangeException(paramName); 1206 } 1207 1208 /// <summary> 1209 /// The exception that is thrown when an invoked method is not supported, or when there is an attempt to read, seek, or write to a stream that does not support the invoked functionality. 1210 /// </summary> NotSupported()1211 internal static Exception NotSupported() 1212 { 1213 return new NotSupportedException(); 1214 } 1215 1216 /// <summary> 1217 /// ArgumentException with message like "The constructor should not be static" 1218 /// </summary> NonStaticConstructorRequired(string paramName)1219 internal static Exception NonStaticConstructorRequired(string paramName) 1220 { 1221 return new ArgumentException(Strings.NonStaticConstructorRequired, paramName); 1222 } 1223 1224 /// <summary> 1225 /// InvalidOperationException with message like "Can't compile a NewExpression with a constructor declared on an abstract class" 1226 /// </summary> NonAbstractConstructorRequired()1227 internal static Exception NonAbstractConstructorRequired() 1228 { 1229 return new InvalidOperationException(Strings.NonAbstractConstructorRequired); 1230 } 1231 1232 /// <summary> 1233 /// InvalidProgramException with default message. 1234 /// </summary> InvalidProgram()1235 internal static Exception InvalidProgram() 1236 { 1237 return new InvalidProgramException(); 1238 } 1239 1240 /// <summary> 1241 /// InvalidOperationException with message like "Enumeration has either not started or has already finished." 1242 /// </summary> EnumerationIsDone()1243 internal static Exception EnumerationIsDone() 1244 { 1245 return new InvalidOperationException(Strings.EnumerationIsDone); 1246 } 1247 1248 /// <summary> 1249 /// ArgumentException with message like "Type {0} contains generic parameters" 1250 /// </summary> TypeContainsGenericParameters(object p0, string paramName)1251 private static Exception TypeContainsGenericParameters(object p0, string paramName) 1252 { 1253 return new ArgumentException(Strings.TypeContainsGenericParameters(p0), paramName); 1254 } 1255 1256 /// <summary> 1257 /// ArgumentException with message like "Type {0} contains generic parameters" 1258 /// </summary> TypeContainsGenericParameters(object p0, string paramName, int index)1259 internal static Exception TypeContainsGenericParameters(object p0, string paramName, int index) 1260 { 1261 return TypeContainsGenericParameters(p0, GetParamName(paramName, index)); 1262 } 1263 1264 /// <summary> 1265 /// ArgumentException with message like "Type {0} is a generic type definition" 1266 /// </summary> TypeIsGeneric(object p0, string paramName)1267 internal static Exception TypeIsGeneric(object p0, string paramName) 1268 { 1269 return new ArgumentException(Strings.TypeIsGeneric(p0), paramName); 1270 } 1271 1272 /// <summary> 1273 /// ArgumentException with message like "Type {0} is a generic type definition" 1274 /// </summary> TypeIsGeneric(object p0, string paramName, int index)1275 internal static Exception TypeIsGeneric(object p0, string paramName, int index) 1276 { 1277 return TypeIsGeneric(p0, GetParamName(paramName, index)); 1278 } 1279 1280 /// <summary> 1281 /// ArgumentException with message like "Incorrect number of arguments for constructor" 1282 /// </summary> IncorrectNumberOfConstructorArguments()1283 internal static Exception IncorrectNumberOfConstructorArguments() 1284 { 1285 return new ArgumentException(Strings.IncorrectNumberOfConstructorArguments); 1286 } 1287 1288 /// <summary> 1289 /// ArgumentException with message like "Expression of type '{0}' cannot be used for parameter of type '{1}' of method '{2}'" 1290 /// </summary> ExpressionTypeDoesNotMatchMethodParameter(object p0, object p1, object p2, string paramName)1291 internal static Exception ExpressionTypeDoesNotMatchMethodParameter(object p0, object p1, object p2, string paramName) 1292 { 1293 return new ArgumentException(Strings.ExpressionTypeDoesNotMatchMethodParameter(p0, p1, p2), paramName); 1294 } 1295 1296 /// <summary> 1297 /// ArgumentException with message like "Expression of type '{0}' cannot be used for parameter of type '{1}' of method '{2}'" 1298 /// </summary> ExpressionTypeDoesNotMatchMethodParameter(object p0, object p1, object p2, string paramName, int index)1299 internal static Exception ExpressionTypeDoesNotMatchMethodParameter(object p0, object p1, object p2, string paramName, int index) 1300 { 1301 return ExpressionTypeDoesNotMatchMethodParameter(p0, p1, p2, GetParamName(paramName, index)); 1302 } 1303 1304 /// <summary> 1305 /// ArgumentException with message like "Expression of type '{0}' cannot be used for parameter of type '{1}'" 1306 /// </summary> ExpressionTypeDoesNotMatchParameter(object p0, object p1, string paramName)1307 internal static Exception ExpressionTypeDoesNotMatchParameter(object p0, object p1, string paramName) 1308 { 1309 return new ArgumentException(Strings.ExpressionTypeDoesNotMatchParameter(p0, p1), paramName); 1310 } 1311 1312 /// <summary> 1313 /// ArgumentException with message like "Expression of type '{0}' cannot be used for parameter of type '{1}'" 1314 /// </summary> ExpressionTypeDoesNotMatchParameter(object p0, object p1, string paramName, int index)1315 internal static Exception ExpressionTypeDoesNotMatchParameter(object p0, object p1, string paramName, int index) 1316 { 1317 return ExpressionTypeDoesNotMatchParameter(p0, p1, GetParamName(paramName, index)); 1318 } 1319 1320 /// <summary> 1321 /// InvalidOperationException with message like "Incorrect number of arguments supplied for lambda invocation" 1322 /// </summary> IncorrectNumberOfLambdaArguments()1323 internal static Exception IncorrectNumberOfLambdaArguments() 1324 { 1325 return new InvalidOperationException(Strings.IncorrectNumberOfLambdaArguments); 1326 } 1327 1328 /// <summary> 1329 /// ArgumentException with message like "Incorrect number of arguments supplied for call to method '{0}'" 1330 /// </summary> IncorrectNumberOfMethodCallArguments(object p0, string paramName)1331 internal static Exception IncorrectNumberOfMethodCallArguments(object p0, string paramName) 1332 { 1333 return new ArgumentException(Strings.IncorrectNumberOfMethodCallArguments(p0), paramName); 1334 } 1335 1336 /// <summary> 1337 /// ArgumentException with message like "Expression of type '{0}' cannot be used for constructor parameter of type '{1}'" 1338 /// </summary> ExpressionTypeDoesNotMatchConstructorParameter(object p0, object p1, string paramName)1339 internal static Exception ExpressionTypeDoesNotMatchConstructorParameter(object p0, object p1, string paramName) 1340 { 1341 return new ArgumentException(Strings.ExpressionTypeDoesNotMatchConstructorParameter(p0, p1), paramName); 1342 } 1343 1344 1345 /// <summary> 1346 /// ArgumentException with message like "Expression of type '{0}' cannot be used for constructor parameter of type '{1}'" 1347 /// </summary> ExpressionTypeDoesNotMatchConstructorParameter(object p0, object p1, string paramName, int index)1348 internal static Exception ExpressionTypeDoesNotMatchConstructorParameter(object p0, object p1, string paramName, int index) 1349 { 1350 return ExpressionTypeDoesNotMatchConstructorParameter(p0, p1, GetParamName(paramName, index)); 1351 } 1352 1353 /// <summary> 1354 /// ArgumentException with message like "Expression must be readable" 1355 /// </summary> ExpressionMustBeReadable(string paramName)1356 internal static Exception ExpressionMustBeReadable(string paramName) 1357 { 1358 return new ArgumentException(Strings.ExpressionMustBeReadable, paramName); 1359 } 1360 1361 /// <summary> 1362 /// ArgumentException with message like "Expression must be readable" 1363 /// </summary> ExpressionMustBeReadable(string paramName, int index)1364 internal static Exception ExpressionMustBeReadable(string paramName, int index) 1365 { 1366 return ExpressionMustBeReadable(GetParamName(paramName, index)); 1367 } 1368 InvalidArgumentValue(string paramName)1369 internal static Exception InvalidArgumentValue(string paramName) 1370 { 1371 return new ArgumentException(Strings.InvalidArgumentValue, paramName); 1372 } 1373 NonEmptyCollectionRequired(string paramName)1374 internal static Exception NonEmptyCollectionRequired(string paramName) 1375 { 1376 return new ArgumentException(Strings.NonEmptyCollectionRequired, paramName); 1377 } 1378 InvalidNullValue(Type type, string paramName)1379 internal static Exception InvalidNullValue(Type type, string paramName) 1380 { 1381 return new ArgumentException(Strings.InvalidNullValue(type), paramName); 1382 } 1383 InvalidTypeException(object value, Type type, string paramName)1384 internal static Exception InvalidTypeException(object value, Type type, string paramName) 1385 { 1386 return new ArgumentException(Strings.InvalidObjectType(value?.GetType() as object ?? "null", type), paramName); 1387 } 1388 GetParamName(string paramName, int index)1389 private static string GetParamName(string paramName, int index) 1390 { 1391 if (index >= 0) 1392 { 1393 return $"{paramName}[{index}]"; 1394 } 1395 1396 return paramName; 1397 } 1398 } 1399 } 1400