public static void IfNullOrNotCastable <T>( [CanBeNull][NoEnumeration] object value, Violation message) { Fail.IfNull(value, message); Fail.IfNotCastable(value, typeof(T), message); }
public static void IfNullOrNotCastable <T>( [CanBeNull][NoEnumeration] object value, [NotNull] string message, [NotNull] params object[] args) { Fail.RequiresMessage(message, args); Fail.IfNull(value, message, args); Fail.IfNotCastable(value, typeof(T), message, args); }
public static T CastOrFail <T>([CanBeNull][NoEnumeration] this object value, [CanBeNull] string name = null) { Type castType = typeof(T); Fail.IfNull(value, Violation.WhenCannotCast <T>(name ?? "object", value)); if (castType.IsEnum) { Fail.IfEnumNotDefined <T>(value); return((T)Enum.ToObject(castType, value)); } Fail.IfNotCastable <T>(value, Violation.WhenCannotCast <T>(name ?? "object", value)); return((T)value); }
public static T CastOrFail <T>([CanBeNull][NoEnumeration] this object value, [CanBeNull] string name = null) { Type castedType = typeof(T); Fail.IfNull(value, Fail.notCastableMessageWithName, name ?? "object", castedType, "null"); if (castedType.IsEnum) { Fail.IfEnumNotDefined <T>(value); return((T)Enum.ToObject(castedType, value)); } Fail.IfNotCastable <T>(value, Fail.notCastableMessageWithName, name ?? "object", castedType, value); return((T)value); }
public static void IfNullOrNotCastable <T>([CanBeNull][NoEnumeration] object value) { Fail.IfNull(value, Violation.WhenCannotCast <T>("object", value)); Fail.IfNotCastable <T>(value, Violation.WhenCannotCast <T>("object", value)); }
public static T AsOrFail <T>([CanBeNull][NoEnumeration] this object value, [CanBeNull] string name = null) { Fail.IfNotCastable <T>(value, Violation.WhenCannotCast <T>(name ?? "object", value)); return((T)value); }
public static T AsOrFail <T>([CanBeNull][NoEnumeration] this object value, [CanBeNull] string name = null) { Fail.IfNotCastable <T>(value, Fail.notCastableMessageWithName, name ?? "object", typeof(T), value); return((T)value); }
public static void IfNullOrNotCastable <T>([CanBeNull][NoEnumeration] object value) { Fail.IfNull(value, Fail.notCastableMessage, typeof(T), "<null>"); Fail.IfNotCastable <T>(value, Fail.notCastableMessage, typeof(T), value); }