public void TestLookupCaseSensitive()
        {
            var prefixMap = new Dictionary <string, string>
            {
                ["A"]   = "Result A",
                ["AB"]  = "Result AB",
                ["ABC"] = "Result ABC",
                // The ABCD is missing !!!
                ["ABCDE"] = "Result ABCDE",
                ["ABCX"]  = "Result ABCX",
                ["ABCDX"] = "Result ABCDX"
            };

            var prefixLookup = new PrefixLookup(prefixMap, true);

            prefixLookup.FindLongestMatchingPrefix("MisMatch").Should().BeNull();

            prefixLookup.FindLongestMatchingPrefix("A").Should().Be("Result A");
            prefixLookup.FindLongestMatchingPrefix("AB").Should().Be("Result AB");
            prefixLookup.FindLongestMatchingPrefix("ABC").Should().Be("Result ABC");
            prefixLookup.FindLongestMatchingPrefix("ABCD").Should().Be("Result ABC");
            prefixLookup.FindLongestMatchingPrefix("ABCDE").Should().Be("Result ABCDE");

            prefixLookup.FindLongestMatchingPrefix("ABCD").Should().Be("Result ABC");
            prefixLookup.FindLongestMatchingPrefix("AB Something").Should().Be("Result AB");
            prefixLookup.FindLongestMatchingPrefix("AAAA").Should().Be("Result A");

            prefixLookup.FindLongestMatchingPrefix("AB€").Should().Be("Result AB");
            prefixLookup.FindLongestMatchingPrefix("AB\t").Should().Be("Result AB");
        }
        public void TestLookupSpeed()
        {
            var prefixMap = new Dictionary <string, string>
            {
                ["1"] = "Result 1"
            };

            for (var i = 10; i < 1000; i++)
            {
                prefixMap["" + i] = "Something";
            }
            var prefixLookup = new PrefixLookup(prefixMap, false);

            long iterations = 100_000_000;

            var stopWatch = Stopwatch.StartNew();

            for (var i = 0; i < iterations; i++)
            {
                prefixLookup.FindLongestMatchingPrefix("999");
            }
            stopWatch.Stop();
            Log.Info(string.Format("Speed stats: {0} runs took {1}ms --> {2}us",
                                   iterations, stopWatch.ElapsedMilliseconds, stopWatch.Elapsed.TotalMilliseconds * 1000));
            prefixLookup.FindLongestMatchingPrefix("1").Should().Be("Result 1");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StepLookupPrefix"/> class.
 /// This is used only for binary deserialization.
 /// </summary>
 /// <param name="info">The info <see cref="SerializationInfo"/>.</param>
 /// <param name="context">The context <see cref="StreamingContext"/>.</param>
 public StepLookupPrefix(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     this.lookupName   = (string)info.GetValue(nameof(this.lookupName), typeof(string));
     this.prefixLookup = (PrefixLookup)info.GetValue(nameof(this.prefixLookup), typeof(PrefixLookup));
     this.defaultValue = (string)info.GetValue(nameof(this.defaultValue), typeof(string));
 }
        public XamlWriterInternalBase(XamlSchemaContext schemaContext, XamlWriterStateManager manager)
        {
            this.sctx    = schemaContext;
            this.manager = manager;
            var p = new PrefixLookup(sctx)
            {
                IsCollectingNamespaces = true
            };                                                                             // it does not raise unknown namespace error.

            service_provider = new ValueSerializerContext(p, schemaContext, AmbientProvider);
        }
        protected XamlWriterInternalBase(XamlSchemaContext schemaContext, XamlWriterStateManager manager)
        {
            this.sctx    = schemaContext;
            this.manager = manager;
            var p = new PrefixLookup(sctx)
            {
                IsCollectingNamespaces = true
            };                                                                            // it does not raise unknown namespace error.

            service_provider = ValueSerializerContext.Create(p, schemaContext, this, this, this, this, this as IXamlObjectWriterFactory);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StepLookupPrefix"/> class.
 /// </summary>
 /// <param name="lookupName">The name of the lookup, a conventional name associated to the lookup, used to define operations.</param>
 /// <param name="prefixList">The dictionary you want use for prefix lookup.</param>
 /// <param name="defaultValue">The default value to be used in case of no lookup found.</param>
 public StepLookupPrefix(string lookupName, IDictionary <string, string> prefixList, string defaultValue)
 {
     this.lookupName   = lookupName;
     this.defaultValue = defaultValue;
     this.prefixLookup = new PrefixLookup(prefixList, false);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="StepIsInLookupPrefix"/> class.
 /// </summary>
 /// <param name="lookupName">The name of the lookup, a conventional name associated to the lookup, used to define operations.</param>
 /// <param name="prefixList">The dictionary of prefix/values you want use for lookup.</param>
 public StepIsInLookupPrefix(string lookupName, IDictionary <string, string> prefixList)
 {
     this.lookupName   = lookupName;
     this.prefixLookup = new PrefixLookup(prefixList, false);
 }