/// <summary>
        /// Returns the set of Primitive, if you will, <see cref="TOption"/> values.
        /// Does not matter what the leading value was, only that it was of type
        /// <see cref="TOption"/>. We intentionally avoid referencing any of the Derived
        /// masks for purposes of returning the Simple ones.
        /// </summary>
        /// <param name="_"></param>
        /// <param name="includeNone"></param>
        /// <returns></returns>
        public static IEnumerable <TOption> SimpleValues(this TOption _, bool includeNone = false)
        {
            if (includeNone)
            {
                yield return(NoFloatingPointRenderingOption);
            }

            yield return(FloatingPointGeneral);

            yield return(FloatingPointRoundTrip);

            yield return(FloatingPointFixed);

            yield return(FloatingPointScientific);

            yield return(FloatingPointUpperCase);

            yield return(FloatingPointLowerCase);

            yield return(FloatingPointForceLeadingDot);

            yield return(FloatingPointForceTrailingDot);

            yield return(FloatingPointForceSignage);
        }
Example #2
0
        /// <summary>
        /// Returns the <paramref name="value"/> Rendered according to the
        /// <paramref name="options"/>.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static string RenderLong(this long value, TOption options)
        {
            VerifyOption("More than one format specified.", options, None
                         , HexadecimalInteger, OctalInteger, DecimalInteger);
            VerifyOption("More than one case specified.", options, None
                         , LowerCaseInteger, UpperCaseInteger);

            var formatMask = HexadecimalInteger.AggregateMask(OctalInteger, DecimalInteger);
            var toBase     = IntegerFormatBases[options & formatMask];
            var s          = IntegerPrefixes[options & formatMask] + Convert.ToString(value, toBase);

            var caseMask = LowerCaseInteger.AggregateMask(UpperCaseInteger);
            var rendered = IntegerCaseCallbacks[options & caseMask].Invoke(s);

            // Includes Decimal as well as Octal use cases.
            bool IsDigit(char c)
            {
                const string digits = "0123456789";

                return(digits.Contains(c));
            }

            // Including a check on the Value itself for cross verification.
            if (value >= 0 &&
                IsDigit(rendered.First()) &&
                options.Intersects(IntegerForcedSignage) &&
                !options.Intersects(OctalInteger.AggregateMask(HexadecimalInteger)))
            {
                // This is the only case it can be at this point.
                rendered = $"+{rendered}";
            }

            return(rendered);
        }
Example #3
0
        public bool HasOption <TOption>()
            where TOption : IOption, new()
        {
            var option = new TOption();

            return(_options
                   .Any(AnyOption(option.ShortOption, option.LongOption)));
        }
Example #4
0
        public static string RenderComments(this TOption options, TOption commentMask)
        {
            if (options == WithLineSeparatorMask)
            {
                throw new InvalidOperationException(
                          "Cannot specify both New Line and Carriage Return New Line rendering options."
                          );
            }

            return(options.Intersects(commentMask)
                ? $"{options.RenderMultiLineComment()} {options.RenderSingleLineComment()}"
                : "");
        }
Example #5
0
        /// <summary>
        /// Verifies that the <paramref name="option"/> aligns with the Aggregate
        /// <paramref name="masks"/>.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="option"></param>
        /// <param name="masks"></param>
        private static void VerifyOption(string message, TOption option, params TOption[] masks)
        {
            if (!masks.Any())
            {
                throw new InvalidOperationException("At least one mask expected.");
            }

            if (masks.Contains(option & masks.AggregateMask()))
            {
                return;
            }

            throw new InvalidOperationException(message);
        }
Example #6
0
            public void Set(ref TOption target, string valueText)
            {
                var propertyType = PropertyInfo.PropertyType;

                try
                {
                    var value = Convert(propertyType, valueText);
                    PropertyInfo.SetValue(target, value);
                }
                catch (ArgumentException ex)
                {
                    throw new AnalysisException(PropertyInfo, ex.Message, ex);
                }
            }
Example #7
0
        public static IEnumerable <TOption> UnmaskOptions(this TOption value, bool includeNone = true)
        {
            if (includeNone)
            {
                yield return(NoIntegerRenderingOption);
            }

            foreach (var x in value.SimpleValues())
            {
                if ((value & x) == x)
                {
                    yield return(x);
                }
            }
        }
Example #8
0
        private static string RenderSingleLineComment(this TOption options, bool silent = true)
        {
            if (options.Intersects(SingleLineComment) &&
                options.Intersects(EmbeddedComments) &&
                options.Intersects(CommentSameLine))
            {
                if (silent)
                {
                    return("");
                }

                throw new InvalidOperationException("Cannot support Single Same Line Embedded Comments.");
            }

            return(options.Intersects(SingleLineComment)
                ? $"// {SampleGuid:D}"
                : "");
        }
Example #9
0
        /// <summary>
        /// Returns the set of Primitive, if you will, <see cref="TOption"/> values.
        /// Does not matter what the leading value was, only that it was of type
        /// <see cref="TOption"/>. We intentionally avoid referencing any of the Derived
        /// masks for purposes of returning the Simple ones.
        /// </summary>
        /// <param name="_"></param>
        /// <param name="includeNone"></param>
        /// <returns></returns>
        public static IEnumerable <TOption> SimpleValues(this TOption _, bool includeNone = false)
        {
            if (includeNone)
            {
                yield return(NoIntegerRenderingOption);
            }

            yield return(HexadecimalInteger);

            yield return(OctalInteger);

            yield return(DecimalInteger);

            yield return(UpperCaseInteger);

            yield return(LowerCaseInteger);

            yield return(IntegerForcedSignage);
        }
Example #10
0
            public async Task <TOut> ExecuteAsync(TIn input, TOption option)
            {
                if (this.isDisposed)
                {
                    throw new ObjectDisposedException(this.ToString());
                }

                string inputString  = Helper.Serilize(input);
                string optionString = Helper.Serilize(option);

                var inputs = new ValueSet();

                inputs.Add(AbstractPlugin <object, object, object> .START_KEY, inputString);
                inputs.Add(AbstractPlugin <object, object, object> .OPTION_KEY, optionString);
                inputs.Add(AbstractPlugin <object, object, object> .ID_KEY, this.id);

                var response = await this.connection.SendMessageAsync(inputs);

                if (response.Status != AppServiceResponseStatus.Success)
                {
                    throw new Exceptions.ConnectionFailureException(response.Status);
                }
                if (response.Message.ContainsKey(AbstractPlugin <object, object, object> .ERROR_KEY))
                {
                    throw new Exceptions.PluginException(response.Message[AbstractPlugin <object, object, object> .ERROR_KEY] as string);
                }
                if (!response.Message.ContainsKey(AbstractPlugin <object, object, object> .RESULT_KEY))
                {
                    return(default(TOut));
                }
                var outputString = response.Message[AbstractPlugin <object, object, object> .RESULT_KEY] as string;

                if (String.IsNullOrWhiteSpace(outputString))
                {
                    return(default(TOut));
                }

                var output = Helper.DeSerilize <TOut>(outputString);

                return(output);
            }
        /// <summary>
        /// Given the formatted <paramref name="s"/> and optional <paramref name="signage"/>,
        /// Extrapolates the Signage as well as the remaining <paramref name="rendered"/>.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="options"></param>
        /// <param name="signage"></param>
        /// <param name="rendered"></param>
        private static void ExtrapolateSignage(this string s, TOption options, out char?signage, out string rendered)
        {
            signage = null;

            const char plusSign = '+';

            if (s.Any() && GetRange('-', plusSign).Contains(s.First()))
            {
                signage = s.First();
            }

            const TOption signageMask = FloatingPointForceSignage;

            // This is the appropriate time to calculate Rendered.
            rendered = signage.HasValue ? s.Substring(1) : s;

            // Because we turn around and may Force a Signage that was not there to begin with.
            if (options.Intersects(signageMask) && !signage.HasValue)
            {
                signage = plusSign;
            }
        }
Example #12
0
        public static IEnumerable <TOption> SimpleValues(this TOption _, bool includeNone = false)
        {
            if (includeNone)
            {
                yield return(ZedValue);
            }

            yield return(CommentBefore);

            yield return(CommentAfter);

            yield return(CommentSameLine);

            yield return(EmbeddedComments);

            yield return(WithLineSeparatorNewLine);

            yield return(WithLineSeparatorCarriageReturnNewLine);

            yield return(SingleLineComment);

            yield return(MultiLineComment);
        }
Example #13
0
 private static string RenderMultiLineComment(this TOption options)
 => options.Intersects(MultiLineComment)
         ? options.Intersects(EmbeddedComments)
             ? $"/* {SampleGuid:D} */"
             : $"/* {SampleGuid:D}{options.RenderLineSeparator()} * {SampleGuid:D} */"
         : "";
Example #14
0
 public static string RenderLineSeparator(this TOption options)
 => options.Intersects(WithLineSeparatorNewLine)
         ? $"{NewLine}"
         : options.Intersects(WithLineSeparatorCarriageReturnNewLine)
             ? $"{CarriageReturn}{NewLine}"
             : "";
Example #15
0
 public abstract bool IsSameAs(TOption Other);
Example #16
0
 /// <summary>
 /// Returns whether <paramref name="options"/> and <paramref name="mask"/> Intersect.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="mask"></param>
 /// <returns></returns>
 private static bool Intersects(this TOption options, TOption mask) => (options & mask) != None;
Example #17
0
 /// <summary>
 /// Returns the Mask combining <paramref name="option"/> and <paramref name="others"/>.
 /// </summary>
 /// <param name="option"></param>
 /// <param name="others"></param>
 /// <returns></returns>
 public static TOption AggregateMask(this TOption option, params TOption[] others)
 => others.Aggregate(option, (g, x) => g | x);
        public static string RenderDouble(this double value, TOption options)
        {
#pragma warning disable 618
            VerifyOption("More than one format specified.", options, None
                         , FloatingPointGeneral, FloatingPointRoundTrip, FloatingPointScientific, FloatingPointFixed);
#pragma warning restore 618
            VerifyOption("More than one case specified.", options, None
                         , FloatingPointLowerCase, FloatingPointUpperCase);
            VerifyOption("More than one dot specified.", options, None
                         , FloatingPointForceLeadingDot, FloatingPointForceTrailingDot);

            // Includes both "Format" as well as Case.
#pragma warning disable 618
            var formatMask = FloatingPointGeneral.AggregateMask(FloatingPointLowerCase, FloatingPointUpperCase
                                                                , FloatingPointRoundTrip, FloatingPointScientific, FloatingPointFixed);
#pragma warning restore 618
            var dotMask = FloatingPointForceLeadingDot.AggregateMask(FloatingPointForceTrailingDot);

            // ReSharper disable once UnusedParameter.Local
            // Receiving a y here for debugging purposes since value cannot be seen by the breakpoints.
            string RenderWithDot(double y, string s, TOption o)
            {
                // Scientific format Cannot be Rendered with a Dot.
                bool ShallNotRenderWithDot() => "eE".Any(e => s.IndexOf(e) >= 0);

                if (ShallNotRenderWithDot())
                {
                    return(s);
                }

                const char zed = '0', dot = '.';

                var hasDot = s.IndexOf(dot) >= 0;

                // ReSharper disable once SwitchStatementMissingSomeCases
                // Normalize the Options, ensure that we yield at least a Trailing Dot.
                switch (o == None ? FloatingPointForceTrailingDot : o)
                {
                // We can safely trim Leading Zed no matter what.
                case FloatingPointForceLeadingDot:

                    // Test case permitting the Leading will be a Dot.
                    while (s.Any() && s.First() == zed)
                    {
                        s = s.Substring(1);
                    }

                    // If there is Nothing remaining then that is ".0" or Dot Zed.
                    if (!s.Any())
                    {
                        s = $"{dot}{zed}";
                    }
                    else if (!hasDot)
                    {
                        /* However, Dot Digit is not the same given Digit.
                         * In this case, fall back on Trailing Dot. */
                        s += dot;
                    }

                    break;

                case FloatingPointForceTrailingDot:

                    // Trimming Trailing Zed is contingent upon Having a Dot.
                    if (hasDot)
                    {
                        // Test case permitting the Trailing will be a Dot.
                        while (s.Any() && s.Last() == zed)
                        {
                            s = s.Substring(0, s.Length - 1);
                        }
                    }
                    else
                    {
                        // Nothing to Trim. Does not Have a Dot therefore simply Append Dot.
                        s += dot;
                    }

                    break;
                }

                return(s);
            }

            var spec = FloatingPointSpecifiers[options & formatMask];
            value.ToString(spec).ExtrapolateSignage(options, out var signage, out var rendered);
            var renderedWithDot = RenderWithDot(value, rendered, options & dotMask);
            return(renderedWithDot.RenderWithPrependedSignage(signage));
        }
Example #19
0
 public override bool IsSameAs(TOption Other)
 {
     return(Value == ((TIntOption)Other).Value);
 }
Example #20
0
 public async Task <TOut> ExecuteAsync(TIn input, TOption options, IProgress <TProgress> progress = null, CancellationToken cancelTokem = default(CancellationToken))
 {
     using (var plugin = await GetPlugin(progress, cancelTokem))
         return(await plugin.ExecuteAsync(input, options));
 }
Example #21
0
 /// <summary>
 /// Renders Comments based on the <paramref name="option"/> and <paramref name="masks"/>.
 /// </summary>
 /// <param name="option"></param>
 /// <param name="masks"></param>
 /// <returns></returns>
 public static string RenderMaskedComments(this TOption option
                                           , params TOption[] masks)
 => string.Join($"{Space}", masks.Select(x => option.RenderComments(x)));
Example #22
0
 /// <summary>
 /// Returns whether <paramref name="mask"/> and <paramref name="options"/> Intersect.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="mask"></param>
 /// <returns></returns>
 public static bool Intersects(this TOption options, TOption mask) => (options & mask) != ZedValue;