Provides functionality for formatting a test string against a mask string. MaskedTextProvider is stateful, it keeps information about the input characters so multiple call to Add/Remove will work in the same buffer. Most of the operations are performed on a virtual string containing the input characters as opposed to the test string itself, since mask literals cannot be modified (i.e: replacing on a literal position will actually replace on the nearest edit position forward).
Inheritance: ICloneable
Example #1
1
 private static object CoerceText(DependencyObject d, object value)
 {
     MaskedTextBox textBox = (MaskedTextBox)d;
     MaskedTextProvider maskProvider = new MaskedTextProvider(textBox.Mask);
     maskProvider.Set((string)value);
     return maskProvider.ToDisplayString();            
 }
Example #2
0
        public static string Formatar(string valor, string mascara)
        {
            MaskedTextProvider mtpCnpj = new MaskedTextProvider(mascara);
            mtpCnpj.Set(valor);
            var formatted = mtpCnpj.ToString();
            if (formatted.IndexOf(" ") == -1) return formatted;

            mascara = mascara.Replace("0", "#").Replace(@"\", "");

            StringBuilder dado = new StringBuilder();
            foreach (char c in valor)
            {
                if (Char.IsNumber(c) || c == 'x' || c == 'X')
                    dado.Append(c);
            }

            int indMascara = mascara.Length;
            int indCampo = dado.Length;
            for (; indCampo > 0 && indMascara > 0; )
            {
                if (mascara[--indMascara] == '#')
                    indCampo -= 1;
            }

            StringBuilder saida = new StringBuilder();
            for (; indMascara < mascara.Length; indMascara++)
            {
                saida.Append((mascara[indMascara] == '#') ? dado[indCampo++] : mascara[indMascara]);
            }

            return saida.ToString();
        }
 public static bool IsValidMaskDescriptor(MaskDescriptor maskDescriptor, out string validationErrorDescription)
 {
     validationErrorDescription = string.Empty;
     if (maskDescriptor == null)
     {
         validationErrorDescription = System.Design.SR.GetString("MaskDescriptorNull");
         return false;
     }
     if ((string.IsNullOrEmpty(maskDescriptor.Mask) || string.IsNullOrEmpty(maskDescriptor.Name)) || string.IsNullOrEmpty(maskDescriptor.Sample))
     {
         validationErrorDescription = System.Design.SR.GetString("MaskDescriptorNullOrEmptyRequiredProperty");
         return false;
     }
     MaskedTextProvider maskedTextProvider = new MaskedTextProvider(maskDescriptor.Mask, maskDescriptor.Culture);
     MaskedTextBox box = new MaskedTextBox(maskedTextProvider) {
         SkipLiterals = true,
         ResetOnPrompt = true,
         ResetOnSpace = true,
         ValidatingType = maskDescriptor.ValidatingType,
         FormatProvider = maskDescriptor.Culture,
         Culture = maskDescriptor.Culture
     };
     box.TypeValidationCompleted += new TypeValidationEventHandler(MaskDescriptor.maskedTextBox1_TypeValidationCompleted);
     box.MaskInputRejected += new MaskInputRejectedEventHandler(MaskDescriptor.maskedTextBox1_MaskInputRejected);
     box.Text = maskDescriptor.Sample;
     if ((box.Tag == null) && (maskDescriptor.ValidatingType != null))
     {
         box.ValidateText();
     }
     if (box.Tag != null)
     {
         validationErrorDescription = box.Tag.ToString();
     }
     return (validationErrorDescription.Length == 0);
 }
		public void PasswordTest ()
		{

			MaskedTextProvider mtp = new MaskedTextProvider ("abcd", CultureInfo.GetCultureInfo ("es-AR"), false, '>', '^', false); 
			Assert.AreEqual (" bcd", mtp.ToString (), "#A1");
			
		}
 public void Clear()
 {
     base.CanRaiseFilterChanged = false;
     this.tsmiComparisionContains.PerformClick();
     this.MaskProvider = new MaskedTextProvider("aa", CultureInfo.InvariantCulture, true);
     this.tstbHex.Text = this.MaskProvider.ToDisplayString();
     base.CanRaiseFilterChanged = true;
 }
 public HexContentFilterControl()
 {
     this.components = null;
     this.InitializeComponent();
     this.InitializeToolStripItems();
     this.Clear();
     this.MaskProvider = new MaskedTextProvider("aa", CultureInfo.InvariantCulture, true);
 }
    public AutoCompletingMaskEventArgs( MaskedTextProvider maskedTextProvider, int startPosition, int selectionLength, string input )
    {
      m_autoCompleteStartPosition = -1;

      m_maskedTextProvider = maskedTextProvider;
      m_startPosition = startPosition;
      m_selectionLength = selectionLength;
      m_input = input;
    }
Example #8
0
 /// <summary>
 /// formata o CNPJ
 /// </summary>
 /// <param name="cnpj">valor a ser formatado</param>
 /// <returns></returns>
 public static string FormatCNPJ(string cnpj)
 {
     string ret = "";
     MaskedTextProvider mascara;
     cnpj = Functions.OnlyNumbers(cnpj, "-.,/").ToString();
     //cnpj
     //##.###.###/####-##
     mascara = new MaskedTextProvider(@"00\.000\.000/0000-00");
     mascara.Set(cnpj);
     ret = mascara.ToString();
     return ret;
 }
 //force the text of the control to use the mask
 private static object ForceText(DependencyObject sender, object value)
 {
     MaskedTextBox textBox = (MaskedTextBox) sender;
     if (textBox.Mask != null)
     {
         MaskedTextProvider provider = new MaskedTextProvider(textBox.Mask);
         provider.Set((string) value);
         return provider.ToDisplayString();
     }
     else
     {
         return value;
     }
 }
		public void DefaultCultureTest ()
		{
			CultureInfo currentUI = Thread.CurrentThread.CurrentUICulture;
			CultureInfo current = Thread.CurrentThread.CurrentCulture;

			try {
				Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US");
				Thread.CurrentThread.CurrentCulture = new CultureInfo ("es-ES");
				MaskedTextProvider mtp = new MaskedTextProvider ("mask");
				Assert.AreEqual ("es-ES", mtp.Culture.Name, "#01");
			} finally {
				Thread.CurrentThread.CurrentCulture = current;
				Thread.CurrentThread.CurrentUICulture = currentUI;
			}
		}
 public HexContentFilterControl(HexContentFilter filter)
 {
     this.components = null;
     if (filter == null)
     {
         throw new ArgumentNullException("filter");
     }
     this.InitializeComponent();
     this.InitializeToolStripItems();
     base.CanRaiseFilterChanged = false;
     CustomFilterControl.PerformDropDownClick(this.tsddContentComparision, filter.Comparision);
     this.MaskProvider = new MaskedTextProvider(CreateMask(filter.Sequence.Length * 2), CultureInfo.InvariantCulture, true);
     this.MaskProvider.Add(filter.SequenceAsString);
     this.tstbHex.Text = this.MaskProvider.ToDisplayString();
     base.CanRaiseFilterChanged = true;
 }
Example #12
0
        private void MaskedTextBoxLoaded(object sender, RoutedEventArgs e)
        {
            _provider = new MaskedTextProvider(!string.IsNullOrEmpty(InputMask) ? InputMask : " ", CultureInfo.CurrentCulture);

            _provider.Set(String.IsNullOrWhiteSpace(UnmaskedText) ? String.Empty : UnmaskedText);

            _provider.PromptChar = PromptChar;
            Text = _provider.ToDisplayString();

            DependencyPropertyDescriptor textProp = DependencyPropertyDescriptor.FromProperty(TextProperty,
                                                                                              typeof(MaskedTextBox));
            if (textProp != null)
            {
                textProp.AddValueChanged(this, (s, args) => UpdateText());
            }
            DataObject.AddPastingHandler(this, Pasting);
        }
        /// <devdoc>
        ///     Override version to be able to perform the operation on a cloned provider.
        /// </devdoc>
        private bool PlaceChar(MaskedTextProvider provider, char ch, int startPosition, int length, bool overwrite, 
            out MaskedTextResultHint hint)
        {
            Debug.Assert( !this.flagState[IS_NULL_MASK], "This method must be called when a Mask is provided." );

            this.caretTestPos = startPosition;

            if (startPosition < this.maskedTextProvider.Length)
            {
                if (length > 0)  // Replacing selection with input char.
                {
                    int endPos = startPosition + length - 1;
                    return provider.Replace(ch, startPosition, endPos, out this.caretTestPos, out hint);
                }
                else
                {
                    if (overwrite)
                    {
                        // overwrite character at next edit position from startPosition (inclusive).
                        return provider.Replace(ch, startPosition, out this.caretTestPos, out hint);
                    }
                    else // insert.
                    {
                        return provider.InsertAt(ch, startPosition, out this.caretTestPos, out hint);
                    }
                }
            }

            hint = MaskedTextResultHint.UnavailableEditPosition;
            return false;
        }
        /// <devdoc>
        ///     Replaces the current selection in the text box specified by the startPosition and selectionLen parameters
        ///     with the contents of the supplied string.
        /// </devdoc>
        private void Replace(string text, int startPosition, int selectionLen)
        {
            Debug.Assert( !this.flagState[IS_NULL_MASK], "This method must be called when a Mask is provided." );
            Debug.Assert(text != null, "text is null.");

            // Clone the MaskedTextProvider so text properties are not modified until the paste operation is
            // completed.  This is needed in case one of these properties is retreived in a MaskedInputRejected
            // event handler (clipboard text is attempted to be set into the input text char by char).

            MaskedTextProvider clonedProvider = (MaskedTextProvider) this.maskedTextProvider.Clone();

            // Cache the current caret position so we restore it in case the text does not change. VSW#498875.
            int currentCaretPos = this.caretTestPos;

            // First replace characters in the selection (if any and if any edit positions) until completed, or the test position falls 
            // outside the selection range, or there's no more room in the test string for editable characters.
            // Then insert any remaining characters from the input.

            MaskedTextResultHint hint = MaskedTextResultHint.NoEffect;
            int endPos = startPosition + selectionLen - 1;

            if( this.RejectInputOnFirstFailure )
            {
                bool succeeded; 

                succeeded = (startPosition > endPos) ?
                    clonedProvider.InsertAt(text, startPosition, out this.caretTestPos, out hint ) :
                    clonedProvider.Replace(text, startPosition, endPos, out this.caretTestPos, out hint);

                if( !succeeded )
                {
                    OnMaskInputRejected(new MaskInputRejectedEventArgs(this.caretTestPos, hint));
                }
            }
            else
            {
                // temp hint used to preserve the 'primary' operation hint (no side effects).
                MaskedTextResultHint tempHint = hint;
                int testPos;
                
                foreach (char ch in text)
                {
                    if( !this.maskedTextProvider.VerifyEscapeChar( ch, startPosition ))  // char won't be escaped, find and edit position for it.
                    {
                        // Observe that we look for a position w/o respecting the selection length, because the input text could be larger than
                        // the number of edit positions in the selection.
                        testPos = clonedProvider.FindEditPositionFrom(startPosition, forward);

                        if( testPos == MaskedTextProvider.InvalidIndex )
                        {
                            // this will continue to execute (fail) until the end of the text so we fire the event for each remaining char.
                            OnMaskInputRejected(new MaskInputRejectedEventArgs(startPosition, MaskedTextResultHint.UnavailableEditPosition));
                            continue;
                        }

                        startPosition = testPos;
                    }

                    int length = endPos >= startPosition ? 1 : 0;

                    // if length > 0 we are (re)placing the input char in the current startPosition, otherwise we are inserting the input.
                    bool replace = length > 0;

                    if (PlaceChar(clonedProvider, ch, startPosition, length, replace, out tempHint))
                    {
                        // caretTestPos is updated in PlaceChar call.
                        startPosition = this.caretTestPos + 1;

                        // place char will insert or replace a single character so the hint must be success, and that will be the final operation
                        // result hint.
                        if (tempHint == MaskedTextResultHint.Success && hint != tempHint)
                        {
                            hint = tempHint;
                        }
                    }
                    else
                    {
                        OnMaskInputRejected(new MaskInputRejectedEventArgs(startPosition, tempHint));
                    }
                }

                if (selectionLen > 0)
                {
                    // At this point we have processed all characters from the input text (if any) but still need to 
                    // remove remaining characters from the selected text (if editable and valid chars).

                    if (startPosition <= endPos)
                    {
                        if (!clonedProvider.RemoveAt(startPosition, endPos, out this.caretTestPos, out tempHint))
                        {
                            OnMaskInputRejected(new MaskInputRejectedEventArgs(this.caretTestPos, tempHint));
                        }

                        // If 'replace' is not actually performed (maybe the input is empty which means 'remove', hint will be whatever
                        // the 'remove' operation result hint is.
                        if (hint == MaskedTextResultHint.NoEffect && hint != tempHint)
                        {
                            hint = tempHint;
                        }
                    }
                }
            }

            bool updateText = TextOutput != clonedProvider.ToString();

            // Always set the mtp, the formatted text could be the same but the assigned positions may be different.
            this.maskedTextProvider = clonedProvider;
            
            // Update text if needed.
            if( updateText )
            {
                SetText();

                // Update caret position.
                this.caretTestPos = startPosition;
                base.SelectInternal( this.caretTestPos, 0, this.maskedTextProvider.Length );
            }
            else
            {
                this.caretTestPos = currentCaretPos;
            }

            return;
        }
        /// <devdoc>
        ///     Initializes the object with the specified MaskedTextProvider object and default
        ///     property values.
        /// </devdoc>
        private void Initialize(MaskedTextProvider maskedTextProvider)
        {
            Debug.Assert(maskedTextProvider != null, "Initializing from a null MaskProvider ref.");

            this.maskedTextProvider = maskedTextProvider;

            // set the initial display text.
            if (!this.flagState[IS_NULL_MASK])
            {
                SetWindowText();
            }

            // set default values.
            this.passwordChar = this.maskedTextProvider.PasswordChar;
            this.insertMode   = InsertKeyMode.Default;

            this.flagState[HIDE_PROMPT_ON_LEAVE         ] = false;
            this.flagState[BEEP_ON_ERROR                ] = false;
            this.flagState[USE_SYSTEM_PASSWORD_CHAR     ] = false;
            this.flagState[REJECT_INPUT_ON_FIRST_FAILURE] = false;

            // CutCopyMaskFormat - set same defaults as TextMaskFormat (IncludePromptAndLiterals).
            // It is a lot easier to handle this flags individually since that's the way the MaskedTextProvider does it.
            this.flagState[CUTCOPYINCLUDEPROMPT         ] = this.maskedTextProvider.IncludePrompt;
            this.flagState[CUTCOPYINCLUDELITERALS       ] = this.maskedTextProvider.IncludeLiterals;

            // fields for internal use.
            this.flagState[HANDLE_KEY_PRESS] = true;
            this.caretTestPos           = 0; 
        }
        /// <devdoc>
        ///     Constructs the MaskedTextBox with the specified MaskedTextProvider object.
        /// </devdoc>
        public MaskedTextBox(MaskedTextProvider maskedTextProvider)
        {
            if (maskedTextProvider == null)
            {
                throw new ArgumentNullException();
            }

            this.flagState[IS_NULL_MASK] = false;
            Initialize(maskedTextProvider);
        }
        private void UpdateText(MaskedTextProvider provider, int position)
        {
            if (provider == null)
                throw new ArgumentNullException("MaskedTextProvider", "Mask cannot be null.");

            Text = provider.ToDisplayString();

            SelectionStart = position;
        }
Example #18
0
 private MaskedTextProvider GetMaskProvider()
 {
     MaskedTextProvider maskProvider = new MaskedTextProvider(Mask);
     maskProvider.Set(Text);
     return maskProvider;
 }
		public MaskedTextBox (MaskedTextProvider maskedTextProvider)
		{
			if (maskedTextProvider == null) {
				throw new ArgumentNullException ();
			}
			provider = maskedTextProvider;
			is_empty_mask = false;
			Init ();
		}
		public MaskedTextBox ()
		{
			provider = new MaskedTextProvider ("<>", CultureInfo.CurrentCulture);
			is_empty_mask = true;
			Init ();
		}
 private void UpdateSortedListView(MaskDescriptorComparer.SortType sortType)
 {
     if (this.listViewCannedMasks.IsHandleCreated)
     {
         MaskDescriptor maskDex = null;
         if (this.listViewCannedMasks.SelectedItems.Count > 0)
         {
             int num = this.listViewCannedMasks.SelectedIndices[0];
             maskDex = this.maskDescriptors[num];
         }
         this.maskDescriptors.RemoveAt(this.maskDescriptors.Count - 1);
         this.maskDescriptors.Sort(new MaskDescriptorComparer(sortType, this.listViewSortOrder));
         System.Design.UnsafeNativeMethods.SendMessage(this.listViewCannedMasks.Handle, 11, false, 0);
         try
         {
             this.listViewCannedMasks.Items.Clear();
             string str = System.Design.SR.GetString("MaskDescriptorValidatingTypeNone");
             foreach (MaskDescriptor descriptor2 in this.maskDescriptors)
             {
                 string str2 = (descriptor2.ValidatingType != null) ? descriptor2.ValidatingType.Name : str;
                 MaskedTextProvider provider = new MaskedTextProvider(descriptor2.Mask, descriptor2.Culture);
                 provider.Add(descriptor2.Sample);
                 string str3 = provider.ToString(false, true);
                 this.listViewCannedMasks.Items.Add(new ListViewItem(new string[] { descriptor2.Name, str3, str2 }));
             }
             this.maskDescriptors.Add(this.customMaskDescriptor);
             this.listViewCannedMasks.Items.Add(new ListViewItem(new string[] { this.customMaskDescriptor.Name, "", str }));
             if (maskDex != null)
             {
                 this.SetSelectedMaskDescriptor(maskDex);
             }
         }
         finally
         {
             System.Design.UnsafeNativeMethods.SendMessage(this.listViewCannedMasks.Handle, 11, true, 0);
             this.listViewCannedMasks.Invalidate();
         }
     }
 }
        private void ResolveMaskProvider(string mask)
        {
            //do not create a mask provider if the Mask is empty, which can occur if the IncludePrompt and IncludeLiterals properties
            //are set prior to the Mask.
            if (String.IsNullOrEmpty(mask))
                return;

            MaskProvider = new MaskedTextProvider(mask)
            {
                IncludePrompt = this.IncludePrompt,
                IncludeLiterals = this.IncludeLiterals,
                PromptChar = this.PromptChar
            };
        }
 /// <devdoc>
 ///     Sets the underlying MaskedTextProvider object.  Used when the control is initialized
 ///     and one of its properties, backed up by the MaskedTextProvider, changes; this requires
 ///     recreating the provider because it is immutable.
 /// </devdoc>
 private void SetMaskedTextProvider( MaskedTextProvider newProvider )
 {
     SetMaskedTextProvider( newProvider, null);
 }
 /// <summary>
 /// Check if the received string value matches with the Introduction Mask for DateTime datatype.
 /// </summary>
 /// <param name="stringValue">String to be checked.</param>
 /// <returns>Returns true if the string matches with Introduction Mask.</returns>
 private bool IsValidDateTimeAccordingMask(string stringValue)
 {
     bool result = true;
     if (mMask != string.Empty)
     {
         MaskedTextProvider maskTextProvider = new MaskedTextProvider(ConvertMask2DisplayMask(mMask));
         result = maskTextProvider.VerifyString(stringValue);
     }
     return result;
 }
        /// <devdoc>
        ///     Overload to allow for passing the text when the mask is being changed from null,
        ///     in this case the maskedTextProvider holds backend info only (not the text).
        /// </devdoc>
        private void SetMaskedTextProvider( MaskedTextProvider newProvider, string textOnInitializingMask )
        {
            Debug.Assert( newProvider != null, "Initializing from a null MaskProvider ref." );
   
            // Set R/W properties.
            newProvider.IncludePrompt    = this.maskedTextProvider.IncludePrompt;
            newProvider.IncludeLiterals  = this.maskedTextProvider.IncludeLiterals;
            newProvider.SkipLiterals     = this.maskedTextProvider.SkipLiterals;
            newProvider.ResetOnPrompt    = this.maskedTextProvider.ResetOnPrompt;
            newProvider.ResetOnSpace     = this.maskedTextProvider.ResetOnSpace;

            // If mask not initialized and not initializing it, the new provider is just a property backend.
            // Change won't have any effect in text.
            if( this.flagState[IS_NULL_MASK] && textOnInitializingMask == null)
            {
                this.maskedTextProvider = newProvider;
                return;
            }

            int testPos = 0;
            bool raiseOnMaskInputRejected = false; // Raise if new provider rejects old text.
            MaskedTextResultHint hint = MaskedTextResultHint.NoEffect;
            MaskedTextProvider oldProvider = this.maskedTextProvider;
            
            // Attempt to add previous text.
            // If the mask is the same, we need to preserve the caret and character positions if the text is added successfully.
            bool preserveCharPos = oldProvider.Mask == newProvider.Mask;

            // Cache text output text before setting the new provider to determine whether we need to raise the TextChanged event.
            string oldText;

            // NOTE: Whenever changing the MTP, the text is lost if any character in the old text violates the new provider's mask.

            if( textOnInitializingMask != null ) // Changing Mask (from null), which is the only RO property that requires passing text.
            {
                oldText  = textOnInitializingMask;
                raiseOnMaskInputRejected = !newProvider.Set( textOnInitializingMask, out testPos, out hint );
            }
            else
            {
                oldText  = TextOutput;

                // We need to attempt to set the input characters one by one in the edit positions so they are not
                // escaped. 
                int assignedCount = oldProvider.AssignedEditPositionCount;
                int srcPos = 0;
                int dstPos = 0;

                while( assignedCount > 0 )
                {
                    srcPos = oldProvider.FindAssignedEditPositionFrom( srcPos, forward );
                    Debug.Assert( srcPos != MaskedTextProvider.InvalidIndex, "InvalidIndex unexpected at this time." );

                    if (preserveCharPos)
                    {
                        dstPos = srcPos;
                    }
                    else
                    {
                        dstPos = newProvider.FindEditPositionFrom(dstPos, forward);

                        if (dstPos == MaskedTextProvider.InvalidIndex)
                        {
                            newProvider.Clear();

                            testPos = newProvider.Length;
                            hint = MaskedTextResultHint.UnavailableEditPosition;
                            break;
                        }
                    }

                    if( !newProvider.Replace( oldProvider[srcPos], dstPos, out testPos, out hint ))
                    {
                        preserveCharPos = false;
                        newProvider.Clear();
                        break;
                    }

                    srcPos++;
                    dstPos++;
                    assignedCount--;
                }

                raiseOnMaskInputRejected = !MaskedTextProvider.GetOperationResultFromHint(hint);
            }


            // Set provider.
            this.maskedTextProvider = newProvider;

            if( this.flagState[IS_NULL_MASK] )
            {
                this.flagState[IS_NULL_MASK] = false;
            }

            // Raising events need to be done only after the new provider has been set so the MTB is in a state where properties 
            // can be queried from event handlers safely.
            if( raiseOnMaskInputRejected )
            {
                OnMaskInputRejected(new MaskInputRejectedEventArgs(testPos, hint));
            }

            if( newProvider.IsPassword )
            {
                // Reset native edit control so the MaskedTextBox will take control over the characters that
                // need to be replaced with the password char (the input text characters).
                // MTB takes over.
                SetEditControlPasswordChar('\0');
            }

            EventArgs e = EventArgs.Empty;

            if (textOnInitializingMask != null /*changing mask from null*/ || oldProvider.Mask != newProvider.Mask)
            {
                OnMaskChanged(e);
            }

            SetWindowText(GetFormattedDisplayString(), oldText != TextOutput, preserveCharPos);
        }
 /// <devdoc>
 ///     Constructs the MaskedTextBox with the specified MaskedTextProvider object.
 /// </devdoc>
 public MaskedTextBox()
 {
     MaskedTextProvider maskedTextProvider = new MaskedTextProvider(nullMask, CultureInfo.CurrentCulture);
     this.flagState[IS_NULL_MASK] = true;
     Initialize(maskedTextProvider);
 }
Example #27
0
        private void RefreshText(MaskedTextProvider maskProvider, int pos)
        { 
            // Refresh string.            
            this.Text = maskProvider.ToDisplayString();

            // Position cursor.
            this.SelectionStart = pos;
        }
        /// <devdoc>
        ///     Constructs the MaskedTextBox with the specified MaskedTextProvider object.
        /// </devdoc>
        public MaskedTextBox(string mask)
        {
            if (mask == null)
            {
                throw new ArgumentNullException();
            }

            MaskedTextProvider maskedTextProvider = new MaskedTextProvider(mask, CultureInfo.CurrentCulture);
            this.flagState[IS_NULL_MASK] = false;
            Initialize(maskedTextProvider);
        }
		public MaskedTextBox (string mask)
		{
			if (mask == null) {
				throw new ArgumentNullException ();
			}
			provider = new MaskedTextProvider (mask, CultureInfo.CurrentCulture);
			is_empty_mask = false;
			Init ();
		}
Example #30
0
        public object Clone()
        {
            MaskedTextProvider clonedProvider;
            Type providerType = this.GetType();

            if (providerType == maskTextProviderType)
            {
                clonedProvider = new MaskedTextProvider(
                                                        this.Mask,
                                                        this.Culture,
                                                        this.AllowPromptAsInput,
                                                        this.PromptChar,
                                                        this.PasswordChar,
                                                        this.AsciiOnly);
            }
            else // A derived Type instance used.
            {
                object[] parameters = new object[] 
                {
                    this.Mask,
                    this.Culture,
                    this.AllowPromptAsInput,
                    this.PromptChar,
                    this.PasswordChar,
                    this.AsciiOnly
                };

                clonedProvider = SecurityUtils.SecureCreateInstance(providerType, parameters) as MaskedTextProvider;
            }

            clonedProvider.ResetOnPrompt = false; 
            clonedProvider.ResetOnSpace  = false;
            clonedProvider.SkipLiterals  = false;

            for (int position = 0; position < this.testString.Length; position++)
            {
                CharDescriptor chDex = this.stringDescriptor[position];

                if (IsEditPosition(chDex) && chDex.IsAssigned)
                {
                    clonedProvider.Replace(this.testString[position], position);
                }
            }

            clonedProvider.ResetOnPrompt    = this.ResetOnPrompt;
            clonedProvider.ResetOnSpace     = this.ResetOnSpace;
            clonedProvider.SkipLiterals     = this.SkipLiterals;
            clonedProvider.IncludeLiterals  = this.IncludeLiterals;
            clonedProvider.IncludePrompt    = this.IncludePrompt;

            return clonedProvider;
        }