/// <summary>
        /// Called by in business entity sub-classes in their property setters to set the value of the property.
        /// If the business Object is not in a loading state, this method performs validation on the property
        /// <example>Example:
        /// <code>
        ///   Set(ByVal Value As String)
        ///       MyBase.SetPropertyValue("SL_DatabaseConnection", _strSL_DatabaseConnection, Value)
        ///   End Set
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="propertyName">Property Name</param>
        /// <param name="currentValue">Current property value</param>
        /// <param name="newValue">New property value</param>
        protected void SetPropertyValue(String propertyName, ref String currentValue, String newValue)
        {
            if (currentValue == null)
            {
                if (newValue == null)
                {
                    return;
                }
            }
            else if (newValue != null && currentValue.Equals(newValue))
            {
                return;
            }

            if (!this.IsLoading)
            {
                _hasBeenValidated = false;
                _isDirty          = true;
                this.BeforePropertyChanged(propertyName);

                //only apply character casing rules after the Object is loaded.
                CharacterCasing characterCasing = SharedCharacterCasingRules.GetManager(this.GetType()).GetRuleForProperty(propertyName);

                currentValue = characterCasing != CharacterCasing.None ? FormatText.ApplyCharacterCasing(newValue, characterCasing) : newValue;

                CheckRulesForProperty(propertyName);
                InternalRaisePropertyChanged(propertyName);
                InternalRaisePropertyChanged(_STRING_ISDIRTY);
                InternalRaisePropertyChanged(_STRING_HASBEENVALIDATED);
                InternalRaisePropertyChanged(_STRING_ERROR);
                InternalRaisePropertyChanged(_STRING_HASERRORS);
                InternalRaisePropertyChanged(_STRING_HASNOERRORS);

                if (this.ThrowExceptionFromPropertySetters)
                {
                    String error = this[propertyName];

                    if (!(String.IsNullOrEmpty(error)))
                    {
                        throw new Exception(error);
                    }
                }

                this.AfterPropertyChanged(propertyName);
            }
            else
            {
                //since we are loading, just set the value
                currentValue = newValue;
            }
        }
Exemple #2
0
        /// <summary>
        /// Using the character case rule, formats the property value.
        /// </summary>
        /// <typeparam name="T">Entity class type to validate.</typeparam>
        /// <param name="target">The target instance class to validate.</param>
        /// <param name="propertyName">The property name on the target instance class to validate.</param>
        /// <param name="propertyValue">The property value.</param>
        /// <returns>Case corrected and formatted string.</returns>
        /// <exception cref="ArgumentNullException">Thrown when target is null.</exception>
        /// <exception cref="ArgumentNullEmptyWhiteSpaceException">Thrown when propertyName is null, empty, or white space.</exception>
        public String FormatPropertyValueUsingCharacterCaseRule <T>(T target, String propertyName, String propertyValue) where T : class
        {
            if (target is null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (String.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullEmptyWhiteSpaceException(nameof(propertyName));
            }
            var resultValue = propertyValue;
            var characterFormattingRulesManager = GetCharacterFormattingRulesManagerForTarget(target);

            if (characterFormattingRulesManager.HasRules && characterFormattingRulesManager.GetRuleForProperty(propertyName) is CharacterFormat characterFormat)
            {
                resultValue = characterFormat.CharacterCasing != CharacterCasing.None ? FormatText.ApplyCharacterCasing(propertyValue, characterFormat.CharacterCasing, characterFormat.PhoneExtension) : propertyValue;
                if (!String.IsNullOrWhiteSpace(resultValue) && characterFormat.RemoveSpace == RemoveSpace.MultipleSpaces)
                {
                    resultValue = Regex.Replace(resultValue, @"\s+", " ");
                }
                else if (!String.IsNullOrWhiteSpace(resultValue) && characterFormat.RemoveSpace == RemoveSpace.AllSpaces)
                {
                    resultValue = resultValue.Replace(" ", String.Empty).Trim();
                }
            }

            return(resultValue);
        }
Exemple #3
0
 /// <summary>
 /// Gets the name of the state.
 /// </summary>
 /// <param name="stateAbbreviation">The state abbreviation.</param>
 /// <returns></returns>
 public String GetStateName(String stateAbbreviation)
 {
     return(IsValid(stateAbbreviation) ? FormatText.ApplyCharacterCasing(_states[stateAbbreviation.ToUpper()], CharacterCasing.ProperName) : String.Format(Resources.StateAbbreviationValidator_GetStateName_State_abbreviation___0___is_not_valid_FormatString, stateAbbreviation));
 }
 /// <summary>
 /// Gets the name of the state.
 /// </summary>
 /// <param name="stateAbbreviation">The state abbreviation.</param>
 /// <returns>String state name that corresponds to the state abbreviation.</returns>
 public String GetStateName(String stateAbbreviation)
 {
     return(IsValid(stateAbbreviation) ? FormatText.ApplyCharacterCasing(_states[stateAbbreviation.ToUpper()], CharacterCasing.ProperName) : $"{stateAbbreviation} is not valid state abbreviation.");
 }
        /// <summary>
        /// Called by in business entity sub-classes in their property setters to set the value of the property.
        /// If the business Object is not in a loading state, this method performs validation on the property.
        /// This method also runs the String compression to remove extra spaces if the property is attributed with the CharacterFormattingAttribute.
        ///
        /// <example>Example:
        /// <code>
        ///   Set(ByVal Value As String)
        ///       MyBase.SetPropertyValue(ref _strSL_DatabaseConnection, Value)
        ///   End Set
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="currentValue">Current property value.</param>
        /// <param name="newValue">Value argument from the property Setter Set.</param>
        /// <param name="propertyName">Property Name.</param>
        protected void SetPropertyValue(ref String currentValue, String newValue, [CallerMemberName] String propertyName = null)
        {
            if (currentValue == null)
            {
                if (newValue == null)
                {
                    return;
                }
            }
            else if (newValue != null && currentValue.Equals(newValue))
            {
                return;
            }

            if (!this.IsLoading)
            {
                this.IsDirty = true;
                this.BeforePropertyChanged(propertyName);

                //only apply character casing rules after the Object is loaded.
                var characterFormat = SharedCharacterFormattingRules.GetManager(this.GetType()).GetRuleForProperty(propertyName);

                if (characterFormat != null)
                {
                    currentValue = characterFormat.CharacterCasing != CharacterCasing.None ? FormatText.ApplyCharacterCasing(newValue, characterFormat.CharacterCasing) : newValue;
                    if (!String.IsNullOrWhiteSpace(currentValue) && characterFormat.RemoveSpace == RemoveSpace.MultipleSpaces)
                    {
                        currentValue = Regex.Replace(currentValue, @"\s+", " ");
                    }
                    else if (!String.IsNullOrWhiteSpace(currentValue) && characterFormat.RemoveSpace == RemoveSpace.AllSpaces)
                    {
                        currentValue = currentValue.Replace(" ", String.Empty).Trim();
                    }
                }
                else
                {
                    currentValue = newValue;
                }

                CheckRulesForProperty(propertyName);
                InternalRaisePropertyChanged(propertyName);

                this.AfterPropertyChanged(propertyName);
            }
            else
            {
                //since we are loading, just set the value
                currentValue = newValue;
            }
        }