/// <summary> /// Interpolates two values. /// </summary> /// <typeparam name="T">The type of the value to interpolate.</typeparam> /// <param name="from">The from value.</param> /// <param name="to">The to value.</param> /// <param name="amount">The interpolation amount.</param> /// <returns> /// The interpolated value or the default value for T if no value handler is registered /// for the specified type. /// </returns> /// <seealso cref="IValueHandler"/> /// <remarks> /// Internally this method uses |T| to lookup the proper value handler then /// calls the value handlers |Interpolate| method. /// </remarks> public T Interpolate <T>(T from, T to, float amount) { IValueHandler <T> handler = this.GetRegisteredValueHandler <T>(); if (handler == null) { return(default(T)); } return(handler.Interpolate(from, to, amount)); }
internal ReadOnlyRangeList(T start, int count, IValueHandler Handler) { if (count < 0) { throw new ArgumentOutOfRangeException(); } if (count > 0) { try { Handler.AddInt(start, count - 1); } catch (Exception) { throw new ArgumentOutOfRangeException(); } } TheStart = start; TheCount = count; TheHandler = Handler; }
public static string Format(this IValueHandler handler, JsonProperty value, bool safeOutput) => handler.Format(value.GetPropertyValueAsString(), safeOutput);
/// <summary> /// Registers a value handler. /// </summary> /// <typeparam name="T">The type the value handler manages.</typeparam> /// <param name="handler">The value handler.</param> public void RegisterValueHandler <T>(IValueHandler <T> handler) { this.m_valueHandlers[typeof(T)] = handler; }
internal string PropertyBuilder(KeyValuePair <string, JToken> secret, Type type, IValueHandler valueHandler, bool isArray, bool safeOutput) { var output = string.Empty; var typeDeclaration = type.GetStandardTypeName(); var accessModifier = type.FullName == typeDeclaration || isArray ? "static readonly" : "const"; if (isArray) { typeDeclaration += "[]"; var valueArray = GetValueArray(secret.Value).Select(x => valueHandler.Format(x, safeOutput)); output = "new " + typeDeclaration + " { " + string.Join(", ", valueArray) + " }"; } else { output = valueHandler.Format(secret.Value, safeOutput); } if (type == typeof(bool)) { output = output.ToLower(); } return($"{TabSpace}{TabSpace}internal {accessModifier} {typeDeclaration} {secret.Key} = {output};\n\n"); }
public static string Format(this IValueHandler handler, JToken value, bool safeOutput) => handler.Format(value.ToString(), safeOutput);
public void UpdateValueHadler(IValueHandler valueHandler) { ValueHandler = valueHandler; }
public static void RegisterTypeHandler(IValueHandler handler) { ValueHandlers[handler.GetType()] = handler; }