System.Linq.Expressions.Error.OnlyStaticMethodsHaveNullInstance C# (CSharp) Method

OnlyStaticMethodsHaveNullInstance() static private method

ArgumentException with message like "Static method requires null instance, non-static method requires non-null instance."
static private OnlyStaticMethodsHaveNullInstance ( ) : Exception
return Exception
        internal static Exception OnlyStaticMethodsHaveNullInstance()
        {
            return new ArgumentException(Strings.OnlyStaticMethodsHaveNullInstance);
        }
        /// <summary>

Usage Example

Esempio n. 1
0
        private static void ValidateAccessor(Expression instance, MethodInfo method, ParameterInfo[] indexes, ref ReadOnlyCollection <Expression> arguments)
        {
            ContractUtils.RequiresNotNull(arguments, "arguments");

            ValidateMethodInfo(method);
            if ((method.CallingConvention & CallingConventions.VarArgs) != 0)
            {
                throw Error.AccessorsCannotHaveVarArgs();
            }

            if (method.IsStatic)
            {
                if (instance != null)
                {
                    throw Error.OnlyStaticMethodsHaveNullInstance();
                }
            }
            else
            {
                if (instance == null)
                {
                    throw Error.OnlyStaticMethodsHaveNullInstance();
                }

                RequiresCanRead(instance, "instance");
                ValidateCallInstanceType(instance.Type, method);
            }

            ValidateAccessorArgumentTypes(method, indexes, ref arguments);
        }
Error