public void ThrowsIfEnumerableIsNull() { // Arrange ICollection <int>?collection = new List <int>(); // Act // Assert _ = Assert.ThrowsException <ArgumentNullException>(() => ICollectionExtension.AddRange(collection, null !)); }
/// <summary> /// Returns node's value for the given context. /// </summary> /// <param name="context">Context to evaluate expressions against.</param> /// <param name="evalContext">Current expression evaluation context.</param> /// <returns>Node's value.</returns> protected override object Get(object context, EvaluationContext evalContext) { var methodName = getText(); var argValues = ResolveArguments(evalContext); // resolve method, if necessary lock (this) { ICollectionExtension localCollectionExtension = null; // check if it is a collection and the methodname denotes a collection processor if ((context == null || context is ICollection)) { // predefined collection processor? if (!_collectionProcessorMap.TryGetValue(methodName, out localCollectionExtension) && evalContext.Variables != null) { // user-defined collection processor? object temp; evalContext.Variables.TryGetValue(methodName, out temp); localCollectionExtension = temp as ICollectionExtension; } } if (localCollectionExtension != null) { return(localCollectionExtension.Execute((ICollection)context, argValues)); } // try extension methods IMethodCallExtension methodCallExtension = null; if (!_extensionMethodProcessorMap.TryGetValue(methodName, out methodCallExtension) && evalContext.Variables != null) { // user-defined extension method? object temp; evalContext.Variables.TryGetValue(methodName, out temp); methodCallExtension = temp as IMethodCallExtension; } if (methodCallExtension != null) { return(methodCallExtension.Execute(context, argValues)); } // try instance method if (context != null) { // calculate checksum, if the cached method matches the current context if (_initialized) { var calculatedHash = CalculateMethodHash(context.GetType(), argValues); _initialized = (calculatedHash == _cachedInstanceMethodHash); } if (!_initialized) { Initialize(methodName, argValues, context); _initialized = true; } } } if (_cachedInstanceMethod != null) { var paramValues = (_cachedIsParamArray) ? ReflectionUtils.PackageParamArray(argValues, _argumentCount, _paramArrayType) : argValues; return(_cachedInstanceMethod.Invoke(context, paramValues)); } throw new ArgumentException(string.Format("Method '{0}' with the specified number and types of arguments does not exist.", methodName)); }
public static void Clear(this ICollectionExtension extension, string reason) { Console.WriteLine("The collection should be cleared!"); Console.WriteLine("Reason: {0}", reason); extension.Clear(); }