本文整理汇总了C#中Function.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Function.ToString方法的具体用法?C# Function.ToString怎么用?C# Function.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Function
的用法示例。
在下文中一共展示了Function.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeNextFrame
public void InvokeNextFrame(Function function)
{
try{
StartCoroutine(_InvokeNextFrame(function));
}catch{
Debug.Log ("Trying to invoke " + function.ToString() + " but it doesnt seem to exist");
}
}
示例2: NuthonMethod
public static Tuple<Matrix, string> NuthonMethod(Function f, Matrix x0, double e1, double e2, int M)
{
string matrixStartLine = "[", matrixElementsSeparator = ", ", matrixEndLine = "]";
StringBuilder sb = new StringBuilder("Метод Ньютона\n");
int k = 0;
double t = 0;
string[] vars = f.Variables;
Matrix varsNames = new Matrix(vars.Length);
int n = vars.Length;
for (int i = 0; i < vars.Length; i++)
{
varsNames[i] = new FunctionMatrixElement(1, vars[i]);
}
Matrix gradF = f.Gradient();
Matrix H = f.GesseMatrix();
sb.AppendFormat("Шаг 1. Задаём: x0 = {0}, e1 = {1}, e2 = {2}, M = {3}\n", x0.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine), e1, e2, M);
sb.AppendFormat(" Градиент функции: ▼f = {0}\n", gradF.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
sb.AppendFormat(" Матрица Гессе: H = {0}\n", H.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
sb.AppendFormat("Шаг 2. Положим: k = {0}\n", k);
List<Matrix> gradFs = new List<Matrix>();
List<Matrix> x = new List<Matrix>();
List<Matrix> d = new List<Matrix>();
x.Add(x0);
Matrix answer = x0;
while (true)
{
sb.AppendFormat("---------------------------{0} иттерация-------------------\n", k);
gradFs.Add(gradF.SetVariablesValuesWithFixedOrder(x[k], varsNames));
sb.AppendFormat("Шаг 3. Градиент: ▼f(x[{0}]) = {1}\n", k, gradFs[k].Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
double normF = gradFs[k].Norm();
sb.AppendFormat("Шаг 4. 1-ый критерий окончания: || ▼f(x[{0}]) || = {1} {2} e1 = {3}\n", k, normF, normF <= e1 ? " <= " : " > ", e1);
if (normF <= e1)
{
answer = x[k];
sb.AppendFormat("1-ый критерий выполнен, следовательно x* = {0}", answer.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
break;
}
sb.AppendFormat("Шаг 5. Проверяем k >= M: {0} {1} {2}\n", k, k < M ? "<" : ">=", M);
if (k >= M)
{
answer = x[k];
sb.AppendFormat("Следовательно x* = {0}", answer.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
break;
}
Matrix Hk = H.SetVariablesValuesWithFixedOrder(x[k], varsNames);
sb.AppendFormat("Шаг 6. H(x[{0}]):\n{1}\n", k, Hk.ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
sb.AppendFormat("Шаг 7. Обратная матрица матрицы H(x[{0}]):\n{1}\n", k, Hk.Reverse().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
bool flag = Hk.Reverse().Silvestr();
sb.AppendFormat("Шаг 8. Проверяем условие H^-1[{0}] > 0: {1}", k, flag);
if (flag)
{
sb.AppendFormat(" => переходим к 9 шагу.\n");
d.Add(new FunctionMatrixElement(-1) * Hk.Reverse() * gradFs[k]);
sb.AppendFormat("Шаг 9. Находим d[{0}]:\n{1}\n", k, d[k].ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
t = 1;
}
else
{
d.Add(new FunctionMatrixElement(-1) * gradFs[k]);
sb.AppendFormat(" => переходим к 10 шагу, положим d[{0}] = -▼f(x[{0}]):{1}\n", k, d[k].ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
Matrix tf = x[k] - new FunctionMatrixElement(1, "t#") * gradFs[k];
Function fi = new Function(f.SetVariablesValues(tf));
sb.AppendFormat("x{0} - t{0}*▼f(x{0}) = {1}\n", k, tf.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
sb.AppendFormat("f(x{0} - t{0}*▼f(x{0})) = {1}\n", k, fi);
Equation et = new Function(fi.Derivative("t#")).EquationSolutionByVariable("t#", new Function(0));
sb.AppendLine(et.ToString());
t = et.RightPart.ToDouble();
}
x.Add(x[k] + new FunctionMatrixElement(t) * d[k]);
sb.AppendFormat("Шаг 10. x{0} = {1}\n", k + 1, x[k + 1].Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
if (k == 0)
{
k++;
sb.AppendFormat("Шаг 11. Т.к. это первая иттерация, то увеличиваем k и возвращаемся к 3 шагу.\n\tk = {0}\n", k);
continue;
}
double normX1 = (x[k + 1] - x[k]).Norm(), normX2 = (x[k] - x[k - 1]).Norm();
double normF1 = Math.Abs((new Function(f.SetVariablesValuesWithFixedOrder(x[k + 1], varsNames)) - f.SetVariablesValuesWithFixedOrder(x[k], varsNames)).ToDouble()),
normF2 = Math.Abs((new Function(f.SetVariablesValuesWithFixedOrder(x[k], varsNames)) - f.SetVariablesValuesWithFixedOrder(x[k - 1], varsNames)).ToDouble());
sb.AppendFormat("Шаг 11. ||x{0} - x{1}|| = {2} {3} {4}\n ||f(x{0}) - f(x{1})|| = {5} {6} {4}\n",
k, k + 1, normX1, normX1 < e2 ? "<" : ">", e2, normF1, normF1 < e2 ? "<" : ">");
sb.AppendFormat(" ||x{0} - x{1}|| = {2} {3} {4}\n ||f(x{0}) - f(x{1})|| = {5} {6} {4}\n",
k - 1, k, normX2, normX2 < e2 ? "<" : ">", e2, normF2, normF2 < e2 ? "<" : ">");
//.........这里部分代码省略.........
示例3: SteepesGradientDescent
public static Tuple<Matrix, string> SteepesGradientDescent(Function f, Matrix x0, double e1, double e2, int M)
{
string matrixStartLine = "[", matrixElementsSeparator = ", ", matrixEndLine = "]";
StringBuilder sb = new StringBuilder("Метод наискорейшего градиентного спуска\n");
sb.AppendFormat("Функция f = {0}\n", f);
int k = 0;
string[] vars = f.Variables;
Matrix varsNames = new Matrix(vars.Length);
for (int i = 0; i < vars.Length; i++)
{
varsNames[i] = new FunctionMatrixElement(1, vars[i]);
}
Matrix gradF = f.Gradient();
sb.AppendFormat("Шаг 1. Задаём: x0 = {0}, e1 = {1}, e2 = {2}, M = {3}\n", x0.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine), e1, e2, M);
sb.AppendFormat(" Градиент функции: ▼f = {0}\n", gradF.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
sb.AppendFormat("Шаг 2. Положим: k = {0}\n", k);
List<Matrix> gradFs = new List<Matrix>();
List<Matrix> x = new List<Matrix>();
x.Add(x0);
Matrix answer = x0;
while (true)
{
sb.AppendFormat("---------------------------{0} иттерация-------------------\n", k);
gradFs.Add(gradF.SetVariablesValuesWithFixedOrder(x[k], varsNames));
sb.AppendFormat("Шаг 3. Градиент: ▼f(x{0}) = {1}\n", k, gradFs[k].Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
double normF = gradFs[k].Norm();
sb.AppendFormat("Шаг 4. 1-ый критерий окончания: || ▼f(x{0}) || = {1} {2} e1 = {3}\n", k, normF, normF < e1 ? " < " : " >= ", e1);
if (normF < e1)
{
answer = x[k];
sb.AppendFormat("1-ый критерий выполнен, следовательно x* = {0}", answer.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
break;
}
sb.AppendFormat("Шаг 5. Проверяем k >= M: {0} {1} {2}\n", k, k < M ? "<" : ">=", M);
if (k >= M)
{
answer = x[k];
sb.AppendFormat("Следовательно x* = {0}", answer.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
break;
}
Matrix tf = x[k] - new FunctionMatrixElement(1, "t#") * gradFs[k];
Function fi = new Function(f.SetVariablesValuesWithFixedOrder(tf, varsNames));
sb.AppendFormat("x{0} - t{0}*▼f(x{0}) = {1}\n", k, tf.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
sb.AppendFormat("f(x{0} - t{0}*▼f(x{0})) = {1}\n", k, fi);
Equation et = new Function(fi.Derivative("t#")).EquationSolutionByVariable("t#", new Function(0));
sb.AppendLine(et.ToString());
double t = et.RightPart.ToDouble();
sb.AppendFormat("Шаг 6. Задаем шаг t{0} = {1}\n", k, t);
x.Add(x[k] - new FunctionMatrixElement(t) * gradFs[k]);
sb.AppendFormat("Шаг 7. x{0} = {1}\n", k + 1, x[k + 1].Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
if (k == 0)
{
k++;
sb.AppendFormat("Шаг 8. Т.к. это первая иттерация, то увеличиваем k и возвращаемся к 3 шагу.\n\tk = {0}\n", k);
continue;
}
double normX1 = (x[k + 1] - x[k]).Norm(), normX2 = (x[k] - x[k - 1]).Norm();
double normF1 = Math.Abs((new Function(f.SetVariablesValuesWithFixedOrder(x[k + 1], varsNames)) - f.SetVariablesValuesWithFixedOrder(x[k], varsNames)).ToDouble()),
normF2 = Math.Abs((new Function(f.SetVariablesValuesWithFixedOrder(x[k], varsNames)) - f.SetVariablesValuesWithFixedOrder(x[k - 1], varsNames)).ToDouble());
sb.AppendFormat("Шаг 8. ||x{0} - x{1}|| = {2} {3} {4}\n ||f(x{0}) - f(x{1})|| = {5} {6} {4}\n",
k, k + 1, normX1, normX1 < e2 ? "<" : ">", e2, normF1, normF1 < e2 ? "<" : ">");
sb.AppendFormat(" ||x{0} - x{1}|| = {2} {3} {4}\n ||f(x{0}) - f(x{1})|| = {5} {6} {4}\n",
k - 1, k, normX2, normX2 < e2 ? "<" : ">", e2, normF2, normF2 < e2 ? "<" : ">");
if (normX1 < e2 && normX2 < e2 && normF1 < e2 && normF2 < e2)
{
answer = x[k + 1];
sb.AppendFormat("Следовательно x* = {0}", answer.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
break;
}
else
{
k++;
sb.AppendFormat("Т.к. хотя бы одно условие не выполнено (не <), то увеличиваем k и возвращаемся к 3 шагу.\n\tk = {0}\n", k);
continue;
}
}
return new Tuple<Matrix, string>(answer, sb.ToString());
}
示例4: FletcherReevesMethod
public static Tuple<Matrix, string> FletcherReevesMethod(Function f, Matrix x0, double e1, double e2, int M)
{
string matrixStartLine = "[", matrixElementsSeparator = ", ", matrixEndLine = "]";
StringBuilder sb = new StringBuilder("Метод Флетчера-Ривза\n");
int k = 0;
string[] vars = f.Variables;
Matrix varsNames = new Matrix(vars.Length);
int n = vars.Length;
for (int i = 0; i < vars.Length; i++)
{
varsNames[i] = new FunctionMatrixElement(1, vars[i]);
}
Matrix gradF = f.Gradient();
sb.AppendFormat("Шаг 1. Задаём: x0 = {0}, e1 = {1}, e2 = {2}, M = {3}\n", x0.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine), e1, e2, M);
sb.AppendFormat(" Градиент функции: ▼f = {0}\n", gradF.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
sb.AppendFormat("Шаг 2. Положим: k = {0}\n", k);
List<Matrix> gradFs = new List<Matrix>();
List<Matrix> x = new List<Matrix>();
List<Matrix> d = new List<Matrix>();
double beta = 0;
x.Add(x0);
Matrix answer = x0;
while (true)
{
sb.AppendFormat("---------------------------{0} иттерация-------------------\n", k);
gradFs.Add(gradF.SetVariablesValuesWithFixedOrder(x[k], varsNames));
sb.AppendFormat("Шаг 3. Градиент: ▼f(x{0}) = {1}\n", k, gradFs[k].Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
double normF = gradFs[k].Norm();
sb.AppendFormat("Шаг 4. 1-ый критерий окончания: || ▼f(x{0}) || = {1} {2} e1 = {3}\n", k, normF, normF < e1 ? " < " : " >= ", e1);
if (normF < e1)
{
answer = x[k];
sb.AppendFormat("1-ый критерий выполнен, следовательно x* = {0}", answer.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
break;
}
sb.AppendFormat("Шаг 5. Проверяем k >= M: {0} {1} {2}\n", k, k < M ? "<" : ">=", M);
if (k >= M)
{
answer = x[k];
sb.AppendFormat("Следовательно x* = {0}", answer.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
break;
}
else
{
if (k == 0)
{
d.Add(new FunctionMatrixElement(-1) * gradFs[0]);
sb.AppendFormat("Т.к. k = 0, переходим к 6 шагу, а потом сразу к 9.\nШаг 6. d[0] = -▼f(x[0]) = {0}\n", d[0].Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
}
else
{
//beta = Math.Pow(gradFs[k].Norm(), 2) / Math.Pow(gradFs[k - 1].Norm(), 2);
//beta = k % n == 0 ? 0 : Matrix.CosBetweenVectors(gradFs[k], gradFs[k] - gradFs[k - 1]).ToDouble()
// / Math.Pow(gradFs[k - 1].Norm(), 2);
beta = k % n == 0 ? 0 : Matrix.VectorsMultiplication(gradFs[k], gradFs[k] - gradFs[k - 1]).ToDouble()
/ Math.Pow(gradFs[k - 1].Norm(), 2);
sb.AppendFormat("Т.к. k >= 1, переходим на 7 шаг.\nШаг 7. Beta[{0}] = {1}\n", k - 1, beta);
d.Add(new FunctionMatrixElement(-1) * gradFs[k] + new FunctionMatrixElement(beta) * d[k - 1]);
sb.AppendFormat("Шаг 8. d[{0}] = {1}\n", k, d[k].Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
}
}
sb.AppendFormat("Шаг 9. Находим t[{0}]:\n", k);
Matrix tf = x[k] + new FunctionMatrixElement(1, "t#") * d[k];
Function fi = new Function(f.SetVariablesValuesWithFixedOrder(tf, varsNames));
sb.AppendFormat(" x[{0}] + t[{0}]*d[{0}] = {1}\n", k, tf.Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
sb.AppendFormat(" f(x[{0}] + t[{0}]*d[{0}] = {1}\n", k, fi);
Equation et = new Function(fi.Derivative("t#")).EquationSolutionByVariable("t#", new Function(0));
sb.AppendLine(et.ToString());
double t = et.RightPart.ToDouble();
sb.AppendFormat(" t[{0}] = {1}\n", k, t);
x.Add(x[k] + new FunctionMatrixElement(t) * d[k]);
sb.AppendFormat("Шаг 10. x{0} = {1}\n", k + 1, x[k + 1].Transposition().ToString(matrixStartLine, matrixElementsSeparator, matrixEndLine));
if (k == 0)
{
k++;
sb.AppendFormat("Шаг 11. Т.к. это первая иттерация, то увеличиваем k и возвращаемся к 3 шагу.\n\tk = {0}\n", k);
continue;
}
double normX1 = (x[k + 1] - x[k]).Norm(), normX2 = (x[k] - x[k - 1]).Norm();
double normF1 = Math.Abs((f.SetVariablesValuesWithFixedOrder(x[k + 1], varsNames) - f.SetVariablesValuesWithFixedOrder(x[k], varsNames)).ToDouble()),
normF2 = Math.Abs((f.SetVariablesValuesWithFixedOrder(x[k], varsNames) - f.SetVariablesValuesWithFixedOrder(x[k - 1], varsNames)).ToDouble());
sb.AppendFormat("Шаг 11. ||x{0} - x{1}|| = {2} {3} {4}\n ||f(x{0}) - f(x{1})|| = {5} {6} {4}\n",
//.........这里部分代码省略.........
示例5: dumpAllExecFromFile
/// <summary>
/// Dumps functions labeled as Exec into a file
/// </summary>
/// <param name="pccfile">File to dump functions from</param>
/// <param name="outputfile">File to save dump to</param>
public static void dumpAllExecFromFile(string pccfile, string outputfile = null)
{
Console.WriteLine("Scanning " + Path.GetFileName(pccfile) + " for Exec Functions");
SortedSet<String> uniqueExecFunctions = new SortedSet<String>();
SortedDictionary<String, List<String>> functionFileMap = new SortedDictionary<String, List<String>>();
SortedDictionary<String, String> functionTextMap = new SortedDictionary<String, String>(); //Function > Function Text
PCCObject pcc = new PCCObject(pccfile);
foreach (PCCObject.ExportEntry exp in pcc.Exports)
{
if (exp.ClassName == "Function")
{
Function func = new Function(exp.Data, pcc);
//exec = 9
int execbit = 9;
int flagint = func.GetFlagInt();
int flag = 1 << execbit;
if ((flagint & flag) != 0)
{
//EXEC FUNCTION!
List<String> list;
string key = exp.PackageName + "." + exp.ObjectName;
if (functionFileMap.TryGetValue(key, out list))
{
list.Add(Path.GetFileName(pccfile));
}
else
{
list = new List<String>();
list.Add(Path.GetFileName(pccfile));
functionFileMap.Add(key, list);
//add new
}
//Check function text
string functext;
if (functionTextMap.TryGetValue(key, out functext))
{
// add to list
if (functext != func.ToString())
{
functionTextMap[key] = func.ToRawText();
}
}
else
{
//set first time text
functionTextMap[key] = func.ToRawText();
}
}
}
}
if (outputfile == null)
{
outputfile = Directory.GetParent(pccfile).ToString();
}
if (!outputfile.EndsWith(@"\")) outputfile += @"\";
outputfile = outputfile + "ExecFunctions.txt";
Console.WriteLine("Saving to " + outputfile);
Directory.CreateDirectory(Path.GetDirectoryName(outputfile));
using (System.IO.StreamWriter file = new System.IO.StreamWriter(outputfile, false))
{
foreach (String key in functionFileMap.Keys)
{
List<String> fileList = functionFileMap[key];
file.WriteLine(key);
file.Write("Appears in:");
foreach (String filename in fileList)
{
file.Write(filename + " ");
}
file.WriteLine();
file.WriteLine("============Function============");
file.WriteLine(functionTextMap[key]);
file.WriteLine();
}
}
}
示例6: dumpAllExecFromFolder
/// <summary>
/// Dumps all exec functions from all pcc's in the specified folder into a file
/// </summary>
/// <param name="folder">Folder to search for pcc's for.</param>
/// <param name="outputfolder">Folder to place a file named ExecFunctions.txt into. If null it will be placed in folder.</param>
public static void dumpAllExecFromFolder(string folder, string outputfolder = null)
{
SortedSet<String> uniqueExecFunctions = new SortedSet<String>(); //unique set of function names
SortedDictionary<String, List<String>> functionFileMap = new SortedDictionary<String, List<String>>(); //what functions appear in what file(s)
SortedDictionary<String, String> functionTextMap = new SortedDictionary<String, String>(); //Function > Function Text
string[] files = Directory.GetFiles(folder, "*.pcc", SearchOption.AllDirectories);
int filesDone = 1;
foreach (String pccfile in files)
{
Console.WriteLine("[" + (filesDone) + "/" + files.Length + "] Scanning for Exec: " + Path.GetFileName(pccfile));
PCCObject pcc = new PCCObject(pccfile);
foreach (PCCObject.ExportEntry exp in pcc.Exports)
{
if (exp.ClassName == "Function")
{
Function func = new Function(exp.Data, pcc);
//exec = 9
int execbit = 9;
int flagint = func.GetFlagInt();
int flag = 1 << execbit;
if ((flagint & flag) != 0)
{
//EXEC FUNCTION!
List<String> list;
string key = exp.PackageName + "." + exp.ObjectName;
if (functionFileMap.TryGetValue(key, out list))
{
// add to list
list.Add(Path.GetFileName(pccfile));
}
else
{
//make new list, add to it
list = new List<String>();
list.Add(Path.GetFileName(pccfile));
functionFileMap.Add(exp.PackageName + "." + exp.ObjectName, list);
}
//Check function text
string functext;
if (functionTextMap.TryGetValue(key, out functext))
{
// add to list
if (functext != func.ToString())
{
functionTextMap[key] = func.ToRawText();
}
}
else
{
//set first time text
functionTextMap[key] = func.ToRawText();
}
}
}
}
filesDone++;
}
if (outputfolder == null)
{
outputfolder = folder;
}
if (!outputfolder.EndsWith(@"\")) outputfolder += @"\";
string outputfile = outputfolder + "ExecFunctions.txt";
Console.WriteLine("Saving to " + outputfile);
Directory.CreateDirectory(Path.GetDirectoryName(outputfile));
using (System.IO.StreamWriter file = new System.IO.StreamWriter(outputfile, false))
{
foreach (String key in functionFileMap.Keys)
{
List<String> fileList = functionFileMap[key];
file.WriteLine(key);
file.Write("Appears in:");
foreach (String filename in fileList)
{
file.Write(filename + " ");
}
file.WriteLine();
file.WriteLine("============Function============");
file.WriteLine(functionTextMap[key]);
file.WriteLine();
}
}
}
示例7: IsLegal
/// <summary>
/// Валидация значения фишки по отношению к правилам текущего цвета.
/// </summary>
/// <param name="tokenF">функция - представление 1 фишки</param>
/// <returns></returns>
public bool IsLegal(Function tokenF)
{
var v = tokenF.ToLeaf();
if (v is Variable && (v as Variable).Name != "")
{
if (!this.Collection.HasVariable(v.Name))
{
return false;
}
var var = this.Collection.GetVariable(v.Name);
if (var.ColorSet.Type == ColorSetType.Record)
{
var curC = var.ColorSet;
for (int i = 0; i < tokenF.MathFunctions.Count; i++)
{
if (!(tokenF.MathFunctions[i].Item1 == RecordVariable.RecordField))
{
break;
}
var s = tokenF.MathFunctions[i].Item2[0].ToLeaf() as StringVariable;
if (!curC.ParsedAttributes.ContainsKey(s.Value))
{
return false;
}
curC = this.Collection.GetColorSet(curC.ParsedAttributes[s.Value]);
}
return curC == this;
}
if (var.ColorSet.Type == ColorSetType.List &&
v.MathFunctions.Count > 0 &&
v.MathFunctions[0].Item1 == Function.GetMathFunction("index"))
{
if (var.ColorSet == this && this.Type == ColorSetType.Index)
{
return true;
}
return this.Collection.GetColorSet(var.ColorSet.ParsedAttributes[ColorSet.ElementsColor]) == this;
}
return this.Collection.GetVariable(v.Name).ColorSet == this;
}
switch (this.Type)
{
case ColorSetType.Unit:
var s = v as StringVariable;
if (s == null)
{
return false;
}
return s.ToString().Equals(ColorSet.UnitDefault) || s.ToString().Equals(this.ParsedAttributes[ColorSet.NameAttribute]);
case ColorSetType.Int:
if (!tokenF.IsDouble())
{
var vars = tokenF.Variables;
foreach (var var in vars)
{
if (!this.Collection.HasVariable(var) || !(this.Collection.GetVariable(var).ColorSet == this))
{
return false;
}
}
try
{
// Можно ли будет посчитать?
tokenF.ToDouble();
}
catch (NotImplementedException)
{
return false;
}
catch
{
return true;
}
}
int val = (int)tokenF.ToDouble();
string min = this.ParsedAttributes[ColorSet.MinValueAttribute];
string max = this.ParsedAttributes[ColorSet.MaxValueAttribute];
return (min.Equals(ColorSet.EmptyAttribute) || Convert.ToInt32(min) <= val) &&
(max.Equals(ColorSet.EmptyAttribute) || Convert.ToInt32(max) >= val);
case ColorSetType.Bool:
// оно сюда никогда не должно попасть, потому что true и false должны быть как переменные в ColorSetCollection и их значения для текущего цвета!
// разве что если будет выражение с логическими операциями
//.........这里部分代码省略.........