private static bool MatchRecordCheckCondition(Dictionary<int, Conditional> conditions, SubrecordStructure ss)
{
if (ss.Condition == CondType.Exists)
{
if (conditions.ContainsKey(ss.CondID))
{
return true;
}
else
{
return false;
}
}
else if (ss.Condition == CondType.Missing)
{
if (conditions.ContainsKey(ss.CondID))
{
return false;
}
else
{
return true;
}
}
Conditional cond;
if (!conditions.TryGetValue(ss.CondID, out cond))
{
return false;
}
switch (cond.type)
{
case ElementValueType.SByte:
case ElementValueType.Byte:
case ElementValueType.UShort:
case ElementValueType.Short:
case ElementValueType.Int:
case ElementValueType.UInt:
case ElementValueType.FormID:
{
int i = Convert.ToInt32(cond.value), i2;
if (!int.TryParse(ss.CondOperand, out i2))
{
return false;
}
switch (ss.Condition)
{
case CondType.Equal:
return i == i2;
case CondType.Not:
return i != i2;
case CondType.Less:
return i < i2;
case CondType.Greater:
return i > i2;
case CondType.GreaterEqual:
return i >= i2;
case CondType.LessEqual:
return i <= i2;
default:
return false;
}
}
case ElementValueType.Float:
{
float i = (float)cond.value, i2;
if (!float.TryParse(ss.CondOperand, out i2))
{
return false;
}
switch (ss.Condition)
{
case CondType.Equal:
return i == i2;
case CondType.Not:
return i != i2;
case CondType.Less:
return i < i2;
case CondType.Greater:
return i > i2;
case CondType.GreaterEqual:
return i >= i2;
case CondType.LessEqual:
return i <= i2;
default:
return false;
}
}
case ElementValueType.Str4:
case ElementValueType.BString:
case ElementValueType.IString:
case ElementValueType.String:
{
var s = (string)cond.value;
switch (ss.Condition)
{
case CondType.Equal:
return s == ss.CondOperand;
case CondType.Not:
return s != ss.CondOperand;
case CondType.StartsWith:
return s.StartsWith(ss.CondOperand);
case CondType.EndsWith:
return s.EndsWith(ss.CondOperand);
case CondType.Contains:
return s.Contains(ss.CondOperand);
default:
return false;
}
}
case ElementValueType.LString:
{
int i = (int)cond.value, i2;
if (!int.TryParse(ss.CondOperand, out i2))
{
return false;
}
switch (ss.Condition)
{
case CondType.Equal:
return i == i2;
case CondType.Not:
return i != i2;
case CondType.Less:
return i < i2;
case CondType.Greater:
return i > i2;
case CondType.GreaterEqual:
return i >= i2;
case CondType.LessEqual:
return i <= i2;
default:
return false;
}
}
default:
return false;
}
}