numl.Model.StringProperty.ImportExclusions C# (CSharp) Method

ImportExclusions() public method

import exclusion list from file.
public ImportExclusions ( string file ) : void
file string .
return void
        public void ImportExclusions(string file)
        {
            // add exclusions
            if (!string.IsNullOrEmpty(file) && !string.IsNullOrWhiteSpace(file) && File.Exists(file))
            {
                Regex regex;
                if (SplitType == StringSplitType.Word)
                    regex = new Regex(@"\w+", RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase);
                else
                    regex = new Regex(@"\w", RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase);

                List<string> exclusionList = new List<string>();
                using (StreamReader sr = File.OpenText(file))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        var match = regex.Match(line);
                        // found something not already in list...
                        if (match.Success && !exclusionList.Contains(match.Value.Trim().ToUpperInvariant()))
                            exclusionList.Add(match.Value.Trim().ToUpperInvariant());
                    }
                }

                Exclude = exclusionList.OrderBy(s => s).ToArray();
            }
            else
                Exclude = new string[] { };
        }

Usage Example

Example #1
0
 /// <summary>Adds string property to descriptor with previously chained name.</summary>
 /// <param name="splitType">How to split string.</param>
 /// <param name="separator">(Optional) Separator to use.</param>
 /// <param name="exclusions">(Optional) file describing strings to exclude.</param>
 /// <returns>descriptor with added property.</returns>
 public Descriptor AsString(StringSplitType splitType, string separator = " ", string exclusions = null)
 {
     StringProperty p = new StringProperty();
     p.Name = _name;
     p.SplitType = splitType;
     p.Separator = separator;
     p.ImportExclusions(exclusions);
     p.AsEnum = _label;
     AddProperty(p);
     return _descriptor;
 }
All Usage Examples Of numl.Model.StringProperty::ImportExclusions