public void RunTest(Delegate f, ToStr toString) { foreach (List <object> test in tests) { string inputs = ""; foreach (object item in test) { inputs = inputs + item.ToString() + " "; } Console.WriteLine("Testing " + inputs); T result = (T)f.DynamicInvoke(test.ToArray()); Console.WriteLine(toString(result)); Console.WriteLine("---"); } }
public void TestToStr() { ToStr toStr = new ToStr(); toStr.Parameters = new List <Token>() { "val".toToken(CefType.StringLiteral) }; var res = toStr.Exec(null); res.Wait(); Assert.AreEqual((string)res.Result.Value, "val"); }
public void Method() { ToStr str = new ToStr(field.ToString); Console.WriteLine(str("x", null)); }
/// <summary> /// Initializes a new instance of the <see cref="ToStringRow"/> class. /// </summary> /// <param name="toStr">use ScenePathToString when null</param> /// <param name="toObj">use default casting when null</param> public ObjToString(ToStr toStr, ToObject toObj, bool showAsTooltip) { this.toString = toStr != null ? toStr : ScenePathToString; this.toObject = toObj != null ? toObj : DefaultToObject; this.showAsTooltip = showAsTooltip; }
public static bool PopupNullable <T>(string label, ref T selection, IList <T> items, ToStr toString, params GUILayoutOption[] options) { if (items.Count == 0) { bool changed = false; Color old = GUI.backgroundColor; GUI.backgroundColor = Color.red; if (label == null) { int i = EditorGUILayout.Popup(1, new string[] { "-", selection.ToString() }, options); if (i == 0) { selection = default(T); changed = true; } } else { int i = EditorGUILayout.Popup(label, 1, new string[] { "-", selection.ToString() }, options); if (i == 0) { selection = default(T); changed = true; } } GUI.backgroundColor = old; return(changed); } int index = 0; string[] str = new string[items.Count + 1]; str[0] = "-"; for (int i = 1; i <= items.Count; i++) { str[i] = toString(items[i - 1]); if (object.Equals(items[i - 1], selection)) { index = i; } } int newIndex = 0; if (label == null) { newIndex = EditorGUILayout.Popup(index, str, options); } else { newIndex = EditorGUILayout.Popup(label, index, str, options); } if (newIndex == 0) { selection = default(T); } else { selection = items[newIndex - 1]; } return(newIndex != index); }