PaytonByrd.ProcessConfiguration.ProcessParameterAttribute.Validate C# (CSharp) Method

Validate() public static method

public static Validate ( object pv_objInstance, PropertyInfo pv_objPropertyInfo ) : ParameterValidationError
pv_objInstance object
pv_objPropertyInfo System.Reflection.PropertyInfo
return ParameterValidationError
        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;
        }
ProcessParameterAttribute