71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
|
|
namespace CPF.ReoGrid
|
|
{
|
|
public class TextAutoFillSectionEntry : IAutoFillSectionEntry
|
|
{
|
|
public object Value { get; }
|
|
|
|
public TextAutoFillSectionEntry(string value)
|
|
{
|
|
char[] digits = "0123456789".ToCharArray();
|
|
int num = value.IndexOfAny(digits);
|
|
bool flag = num == -1;
|
|
if (flag)
|
|
{
|
|
this.textLeftOfDigit = value;
|
|
}
|
|
else
|
|
{
|
|
this.hasDigit = true;
|
|
bool flag2 = num > 0;
|
|
if (flag2)
|
|
{
|
|
this.textLeftOfDigit = value.Substring(0, num);
|
|
value = value.Substring(num);
|
|
}
|
|
char[] array = value.TakeWhile((char c) => digits.Contains(c)).ToArray<char>();
|
|
this.textRightOfDigit = value.Substring(array.Length);
|
|
this.Value = double.Parse(new string(array));
|
|
}
|
|
}
|
|
|
|
public bool IsSequenceOf(IAutoFillSectionEntry otherEntry)
|
|
{
|
|
TextAutoFillSectionEntry textAutoFillSectionEntry = otherEntry as TextAutoFillSectionEntry;
|
|
bool flag = textAutoFillSectionEntry == null;
|
|
return !flag && (this.textLeftOfDigit.Equals(textAutoFillSectionEntry.textLeftOfDigit) && this.textRightOfDigit.Equals(textAutoFillSectionEntry.textRightOfDigit)) && this.hasDigit == textAutoFillSectionEntry.hasDigit;
|
|
}
|
|
|
|
public object GetIterationValue(object baseValue, object incrementPerIteration, int iteration)
|
|
{
|
|
string str = string.Empty;
|
|
bool flag = this.hasDigit;
|
|
if (flag)
|
|
{
|
|
double differenceToBaseValue = this.GetDifferenceToBaseValue(baseValue);
|
|
double num = (double)incrementPerIteration;
|
|
str = ((double)baseValue + differenceToBaseValue + num * (double)iteration).ToString();
|
|
}
|
|
return this.textLeftOfDigit + str + this.textRightOfDigit;
|
|
}
|
|
|
|
public object GetIncrementPerIteration(object baseValue, int numberOfEntries)
|
|
{
|
|
return (numberOfEntries > 1 && this.hasDigit) ? (this.GetDifferenceToBaseValue(baseValue) / (double)(numberOfEntries - 1) * (double)numberOfEntries) : 0.0;
|
|
}
|
|
|
|
private double GetDifferenceToBaseValue(object baseValue)
|
|
{
|
|
return this.hasDigit ? ((double)this.Value - (double)baseValue) : 0.0;
|
|
}
|
|
|
|
private string textLeftOfDigit = string.Empty;
|
|
|
|
private string textRightOfDigit = string.Empty;
|
|
|
|
private bool hasDigit;
|
|
}
|
|
}
|