PaytonByrd.ProcessConfiguration.ParameterValidationError.CreateNotValid C# (CSharp) Method

CreateNotValid() public static method

public static CreateNotValid ( string pv_strDescription ) : ParameterValidationError
pv_strDescription string
return ParameterValidationError
        public static ParameterValidationError CreateNotValid(string pv_strDescription)
        {
            ParameterValidationError objResult = new ParameterValidationError();

            objResult.IsValid = false;
            objResult.Description = pv_strDescription;

            return objResult;
        }

Usage Example

Exemplo n.º 1
0
        public static ParameterValidationError Validate(
            object pv_objInstance,
            PropertyInfo pv_objPropertyInfo)
        {
            ArgumentAssert.IsGenericNotNull <object>(pv_objInstance, "pv_objInstance");
            ArgumentAssert.IsGenericNotNull <PropertyInfo>(pv_objPropertyInfo, "pv_objPropertyInfo");

            ParameterValidationError objResult = ParameterValidationError.CreateValid();

            object objValue = null;
            ProcessParameterAttribute objAttribute = null;

            try
            {
                List <ProcessParameterAttribute> objAttributes =
                    new List <ProcessParameterAttribute>(
                        (ProcessParameterAttribute[])
                        pv_objPropertyInfo.GetCustomAttributes(
                            typeof(ProcessParameterAttribute), false));

                if (objAttributes.Count > 0)
                {
                    objAttribute = objAttributes[0];
                    objValue     = pv_objPropertyInfo.GetValue(pv_objInstance, new object[0]);

                    if (objValue == null && objAttribute.m_blnParameterRequired)
                    {
                        return(ParameterValidationError.CreateNotValid(string.Format(
                                                                           Helpers.ResourceHelper.GetResource(CANNOT_BE_NULL_RESOURCE_ID),
                                                                           pv_objPropertyInfo.Name)));
                    }

                    if (objAttribute.m_strValidationExpression != ".*")
                    {
                        System.Text.RegularExpressions.Regex objRegex =
                            new System.Text.RegularExpressions.Regex(objAttribute.m_strValidationExpression);

                        if (!objRegex.IsMatch(objValue.ToString()))
                        {
                            return(ParameterValidationError.CreateNotValid(string.Format(
                                                                               Helpers.ResourceHelper.GetResource(DOES_NOT_MATCH_EXPRESSION_RESOURCE_ID),
                                                                               pv_objPropertyInfo.Name)));
                        }
                    }
                }
            }
            catch (Exception objException)
            {
                ParameterValidationError.CreateNotValid(objException.ToString());
            }

            return(objResult);
        }