コード例 #1
0
 public TokenParser(IEnumerable <TokenType> supportedTypes)
 {
     SupportedTypes = supportedTypes.ToArray();
     LongestSymbol  = SupportedTypes.Select(p =>
                                            Math.Max(
                                                p.EscapeOpen.Length + p.OpenSymbol.Length,
                                                p.EscapeClose.Length + p.CloseSymbol.Length))
                      .Max();
 }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the TypedPromptProvider class.
        /// </summary>
        static TypedPromptProvider()
        {
            DefaultTypedPromptFuncMap = new Dictionary <Type, Func <string, Dialog> >()
            {
                { typeof(string), GetTextPrompt },
                { typeof(int?), GetIntPrompt },
                { typeof(double?), GetDoublePrompt },
                { typeof(bool?), GetBoolPrompt },
                { typeof(DateTime?), GetDateTimePrompt },
            };

            // We enforce the type check here to ensure all types either class or nullables.
            // The null is required in PromptManager to see whether a property has been set or not.
            // Note: You can implement custom TypedPromptProvider which takes a type other than the ones
            //   supported by default. But it'll fail the below check. This is done by intention since
            //   I'd like to make sure all supported types have a default implementation.
            if (!DefaultTypedPromptFuncMap.ContainsKey(typeof(TProperty)))
            {
                var supportedTypes = string.Join(",", SupportedTypes.Select(t => (Nullable.GetUnderlyingType(t) ?? t).Name));
                var msg            = $"{typeof(TProperty).Name} is not supported by TypedPromptProvider. Supported types: {supportedTypes}.";
                throw new NotSupportedException(msg);
            }
        }