Exemplo n.º 1
0
 public string EscMinLengthShortOf(string text, int minLength, char fillChar, PadSide padSide)
 {
     string s = EscNull(text);
     return (s.Length < minLength
         ? (padSide == PadSide.RIGHT ? s.PadRight(minLength, fillChar) : s.PadLeft(minLength, fillChar))
         : s);
 }
    public void In(
        [FriendlyName("Target", "The target string to be padded.")]
        string Target,

        [FriendlyName("Side", "Which side of the string to pad.")]
        [SocketState(false, false)]
        PadSide padSide,

        [FriendlyName("Width", "Specifies the total width of the Result string after padding. If the width specified is smaller thatn the Target string's current width, the original string is returned instead.")]
        [SocketState(false, false)]
        int TotalWidth,

        [FriendlyName("Pad Character", "(optional) Specify the character to use for padding. If none is provided, whitespace will be used by default. Note: If more than one character is provided in the string, only the first character will be used for padding.")]
        [SocketState(false, false)]
        string padCharString,

        [FriendlyName("Result", "Resulting padded string.")]
        out string Result
        )
    {
        // Convert the string into a char variable
        System.Char padChar;
        char[]      padCharTemp;
        if (padCharString == "")
        {
            string whitespace = " ";
            padCharTemp = whitespace.ToCharArray();
            padChar     = padCharTemp[0];
        }
        else
        {
            padCharTemp = padCharString.ToCharArray();
            padChar     = padCharTemp[0];
        }

        // Preform padding
        if (padSide == PadSide.Left)
        {
            Result = Target.PadLeft(TotalWidth, padChar);
        }
        else
        {
            Result = Target.PadRight(TotalWidth, padChar);
        }
    }
Exemplo n.º 3
0
        /// <summary>
        /// The chart data always needs to be "aligned," which is to say that the number of data points must
        /// match. This method takes the "parent" (main series) and tweaks the "child" (subordinate series such
        /// as an indicator that we have created). We will "pad" the child series using empty data points.
        /// </summary>
        /// <param name="parent">main chart series - contains the target count for datapoints</param>
        /// <param name="child">subordinate chart series - we will tweak it to match the "parent" series datapoint count</param>
        /// <param name="pad">side on which to pad with empty data points - PadLeft is the default</param>
        protected void AlignChartData(MSChart.Series parent, MSChart.Series child, PadSide pad = PadSide.PadLeft)
        {
            int pointsToAddCount = parent.Points.Count - child.Points.Count;

            switch (pad)
            {
            case PadSide.PadLeft:
                // In some instances, we may need to REMOVE points from the child to get the series aligned.
                if (pointsToAddCount >= 0)
                {
                    // Add points to the LEFT side of the child series.
                    for (int i = 0; i < pointsToAddCount; i++)
                    {
                        // Create an empty data point.
                        MSChart.DataPoint dpEmpty = new MSChart.DataPoint();
                        dpEmpty.IsEmpty = true;

                        child.Points.Insert(0, dpEmpty);
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                break;

            case PadSide.PadRight:
                throw new NotImplementedException();
                break;
            }

            // Go through the chart data points and make sure the X values are aligned.
            for (int i = 0; i < parent.Points.Count; i++)
            {
                child.Points[i].XValue = parent.Points[i].XValue;
            }
        }
Exemplo n.º 4
0
 public string EscMinMaxLengthOutOf(string text,
     int minLength, char fillChar, int maxLength, PadSide padSide)
 {
     return EscMaxLengthExceed(
         EscMinLengthShortOf(text, minLength, fillChar, padSide), maxLength);
 }