// ReSharper disable once UnusedParameter.Global public virtual T GetDefault(DefaultUsage usage) { var t = typeof(T); if (t.IsPrimitive || t.IsEnum) { return(default);
/// <summary> /// Returns a default value for the Key or Value properties for new dictionary entries /// </summary> /// <param name="usage">Specifies if the desired default value is to be used as Key or Value</param> /// <returns>Returns a value of type T to be used as the default</returns> /// <remarks>If the default value is to be used as Key it may NOT be null (because the Dictionary doesn't allow null as Key)</remarks> public virtual T GetDefault(DefaultUsage usage) { Type t = typeof(T); if (t.IsPrimitive || t.IsEnum) { return(default(T)); } else if (t == typeof(string)) { return((T)(object)String.Empty); } else { return(Activator.CreateInstance <T>()); } }
public override int GetDefault(DefaultUsage usage) { // The mother of all numbers return(42); }
public override Color GetDefault(DefaultUsage usage) { // we want red as default color! return(Color.Red); }
public override string GetDefault(DefaultUsage usage) { return("0"); }