public static void IsOfOneOfTheTypes(string paramName, Type type, Type[] requiredTypes) { Argument.IsNotNull("type", type); Argument.IsNotNullOrEmptyArray("requiredTypes", requiredTypes); if (type.IsCOMObjectEx()) { return; } foreach (var requiredType in requiredTypes) { if (requiredType.IsAssignableFromEx(type)) { return; } } var errorBuilder = new StringBuilder(); errorBuilder.AppendLine("Type '{0}' should implement at least one of the following types, but does not:"); foreach (var requiredType in requiredTypes) { errorBuilder.AppendLine(" * " + requiredType.FullName); } var error = errorBuilder.ToString(); Log.Error(error); throw new ArgumentException(error, paramName); }
public static void ImplementsOneOfTheInterfaces(string paramName, Type type, Type[] interfaceTypes) { Argument.IsNotNull("type", type); Argument.IsNotNullOrEmptyArray("interfaceTypes", interfaceTypes); foreach (var interfaceType in interfaceTypes) { if (type.GetInterfacesEx().Any(iType => iType == interfaceType)) { return; } } var errorBuilder = new StringBuilder(); errorBuilder.AppendLine("Type '{0}' should implement at least one of the following interfaces, but does not:"); foreach (var interfaceType in interfaceTypes) { errorBuilder.AppendLine(" * " + interfaceType.FullName); } var error = errorBuilder.ToString(); Log.Error(error); throw new ArgumentException(error, paramName); }
public static void IsNotOfOneOfTheTypes(string paramName, Type type, Type[] notRequiredTypes) { Argument.IsNotNull("type", type); Argument.IsNotNullOrEmptyArray("notRequiredTypes", notRequiredTypes); if (type.IsCOMObjectEx()) { return; } foreach (var notRequiredType in notRequiredTypes) { if (notRequiredType.IsAssignableFromEx(type)) { var error = string.Format("Type '{0}' should not be of type '{1}', but is", type.Name, notRequiredType.Name); Log.Error(error); throw new ArgumentException(error, paramName); } } }