Private
Public Access
Added new conversions
This commit is contained in:
1 parent
9309b975a6
commit
f57d0cc095
1 file changed
+45
+45
@@ -102,5 +102,50 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
public static Color IntsToColor(int r, int g, int b, int a = 255) {
|
public static Color IntsToColor(int r, int g, int b, int a = 255) {
|
||||||
return Color.FromArgb(a, r, g, b);
|
return Color.FromArgb(a, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool ConvertToBool(string text) {
|
||||||
|
switch (text) {
|
||||||
|
case "true":
|
||||||
|
case "1":
|
||||||
|
case "on":
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case "false":
|
||||||
|
case "0":
|
||||||
|
case "off":
|
||||||
|
return false;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Exception("Invalid input");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IValue ConvertToIValue(string text) {
|
||||||
|
|
||||||
|
//No assignmnet
|
||||||
|
if (!text.Contains("=")) {
|
||||||
|
|
||||||
|
if (!text.Contains("#")) {
|
||||||
|
//Check if string is a number
|
||||||
|
try {
|
||||||
|
return ValueFactory.CreateValue(text, "int");
|
||||||
|
} catch (Exception e) { }
|
||||||
|
|
||||||
|
//Check if string is a double
|
||||||
|
try {
|
||||||
|
return ValueFactory.CreateValue(text, "double");
|
||||||
|
} catch (Exception e) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if color
|
||||||
|
try {
|
||||||
|
return ValueFactory.CreateValue(text, "color");
|
||||||
|
} catch (Exception e) { }
|
||||||
|
} else {
|
||||||
|
//Check if string is an expression
|
||||||
|
return ValueFactory.CreateValue(text, "expression");
|
||||||
|
}
|
||||||
|
throw new Exception("Could not convert " + text + " to any type");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user