/// <summary> /// Substitutes the logic to generate a string for <paramref name="name"/> /// with <paramref name="substituteMethod"/>. /// </summary> /// /// <typeparam name="U"> /// The type of the member named <paramref name="name"/> in type <typeparamref name="T"/>. /// </typeparam> /// /// <param name="name">The name of the member in <typeparamref name="T"/>.</param> /// <param name="substituteMethod">The method that will be used for replacement.</param> /// /// <returns>The same instance of <see cref="ToStringMethodBuilder{T}"/>.</returns> /// /// <exception cref="ArgumentNullException"> /// If either <paramref name="name"/> or <paramref name="substituteMethod"/> are null. /// </exception> /// <exception cref="ArgumentException"> /// If <typeparamref name="T"/> doesn't have a member named <paramref name="name"/> /// or if that member is not compatible with <typeparamref name="U"/>. /// </exception> public ToStringMethodBuilder <T> Substitute <U>(string name, ToStringMethod <U> substituteMethod) { Validate.ArgumentNotNull(name, nameof(name)); Validate.ArgumentNotNull(substituteMethod, nameof(substituteMethod)); namedSubstitutes[name] = substituteMethod; return(this); }
public static string[] ConvertListToStringArray <T>(IEnumerable <T> list, ToStringMethod <T> method) { string[] ret = new string[list.Count()]; int i = 0; foreach (T obj in list) { ret[i++] = method.Invoke(obj); } return(ret); }
public override void DrawValue(Rect window, float width) { if (OwnerCacheObject.CanWrite) { if (!IsExpanded) { if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) })) { IsExpanded = true; } } else { if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) })) { IsExpanded = false; } } } GUILayout.Label($"<color=#2df7b2>Vector{VectorSize}</color>: {(string)ToStringMethod.Invoke(Value, new object[0])}", new GUILayoutOption[0]); if (OwnerCacheObject.CanWrite && IsExpanded) { GUILayout.EndHorizontal(); var whitespace = CalcWhitespace(window); // always draw x and y GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUIHelper.Space(whitespace); GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) }); x = GUIHelper.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUIHelper.Space(whitespace); GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) }); y = GUIHelper.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); if (VectorSize > 2) { // draw z GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUIHelper.Space(whitespace); GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) }); z = GUIHelper.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); } if (VectorSize > 3) { // draw w GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUIHelper.Space(whitespace); GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) }); w = GUIHelper.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); } // draw set value button GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUIHelper.Space(whitespace); if (GUILayout.Button("<color=lime>Apply</color>", new GUILayoutOption[] { GUILayout.Width(155) })) { SetValueFromInput(); } GUILayout.EndHorizontal(); GUIHelper.BeginHorizontal(new GUILayoutOption[0]); } }
public static string ConvertListToString <T>(IEnumerable <T> list, ToStringMethod <T> method, string seperator) { string[] ret = ConvertListToStringArray(list, method); return(ConvertListToString(ret, seperator)); }