/// <summary>
        /// Determines if the value is valid for the specified attribute
        /// </summary>
        /// <param name="value">
        /// The variable value to validate.
        /// </param>
        /// <param name="attribute">
        /// The attribute to use to validate that value.
        /// </param>
        /// <returns>
        /// True if the value is valid with respect to the attribute, or false otherwise.
        /// </returns>
        internal static bool IsValidValue(object value, Attribute attribute)
        {
            bool result = true;

            ValidateArgumentsAttribute validationAttribute = attribute as ValidateArgumentsAttribute;

            if (validationAttribute != null)
            {
                try
                {
                    // Get an EngineIntrinsics instance using the context of the thread.

                    ExecutionContext context = Runspaces.LocalPipeline.GetExecutionContextFromTLS();
                    EngineIntrinsics engine  = null;

                    if (context != null)
                    {
                        engine = context.EngineIntrinsics;
                    }

                    validationAttribute.InternalValidate(value, engine);
                }
                catch (ValidationMetadataException)
                {
                    result = false;
                }
            }
            return(result);
        } // IsValidValue
示例#2
0
        internal static bool IsValidValue(object value, Attribute attribute)
        {
            bool flag = true;
            ValidateArgumentsAttribute attribute2 = attribute as ValidateArgumentsAttribute;

            if (attribute2 != null)
            {
                try
                {
                    ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS();
                    EngineIntrinsics engineIntrinsics        = null;
                    if (executionContextFromTLS != null)
                    {
                        engineIntrinsics = executionContextFromTLS.EngineIntrinsics;
                    }
                    attribute2.InternalValidate(value, engineIntrinsics);
                }
                catch (ValidationMetadataException)
                {
                    flag = false;
                }
            }
            return(flag);
        }