System.ComponentModel.MaskedTextProvider.SetChar C# (CSharp) Method

SetChar() private method

Sets the character at the specified position in the test string to the specified value. SetChar increments the number of assigned characters in the test string.
private SetChar ( char input, int position, CharDescriptor charDescriptor ) : void
input char
position int
charDescriptor CharDescriptor
return void
        private void SetChar(char input, int position, CharDescriptor charDescriptor)
        {
            Debug.Assert(position >= 0 && position < _testString.Length, "Position out of range.");
            Debug.Assert(charDescriptor != null, "Null character descriptor.");

            // Get the character info from the char descriptor table.
            CharDescriptor charDex = _stringDescriptor[position];

            // If input is space or prompt and is to be escaped, we are actually resetting the position if assigned,
            // this doesn't affect literal positions.
            if (TestEscapeChar(input, position, charDescriptor))
            {
                ResetChar(position);
                return;
            }

            Debug.Assert(!IsLiteralPosition(charDex), "Setting char in literal position.");

            if (Char.IsLetter(input))
            {
                if (Char.IsUpper(input))
                {
                    if (charDescriptor.CaseConversion == CaseConversion.ToLower)
                    {
                        input = _culture.TextInfo.ToLower(input);
                    }
                }
                else // Char.IsLower( input )
                {
                    if (charDescriptor.CaseConversion == CaseConversion.ToUpper)
                    {
                        input = _culture.TextInfo.ToUpper(input);
                    }
                }
            }

            _testString[position] = input;

            if (!charDescriptor.IsAssigned) // if position not counted for already (replace case) we do it (add case).
            {
                charDescriptor.IsAssigned = true;
                _assignedCharCount++;

                if (charDescriptor.CharType == CharType.EditRequired)
                {
                    _requiredCharCount++;
                }
            }

            Debug.Assert(_assignedCharCount <= EditPositionCount, "Invalid count of assigned chars.");
        }

Same methods

MaskedTextProvider::SetChar ( char input, int position ) : void