public static ImplementsInterface ( |
||
targetType | ||
interfaceType | ||
return | bool |
public static bool ImplementsInterface(Type targetType, Type interfaceType)
{
var targetTypeWrapper = TypeFactory.GetTypeInfo(targetType);
var interfaceTypeWrapper = TypeFactory.GetTypeInfo(interfaceType);
if (!interfaceTypeWrapper.IsInterface)
throw new ArgumentOutOfRangeException("interfaceType", "Type is not an interface");
foreach (var inter in targetTypeWrapper.GetInterfaces())
{
var interWrapper = TypeFactory.GetTypeInfo(inter);
if (object.Equals(interWrapper, interfaceTypeWrapper))
return true;
if (interfaceTypeWrapper.IsGenericTypeDefinition && interWrapper.IsGenericType)
{
var generic = interWrapper.GetGenericTypeDefinition();
if (generic == interfaceType)
return true;
}
}
return false;
}
/// <summary> /// Validates configurations and sets required fields /// </summary> public void Validate(DynamoDBContext context) { if (IsVersion) { Utils.ValidateVersionType(MemberType); // no conversion is possible, so type must be a nullable primitive } if (IsHashKey && IsRangeKey) { throw new InvalidOperationException("Property " + PropertyName + " cannot be both hash and range key"); } if (ConverterType != null) { if (!Utils.CanInstantiateConverter(ConverterType) || !Utils.ImplementsInterface(ConverterType, typeof(IPropertyConverter))) { throw new InvalidOperationException("Converter for " + PropertyName + " must be instantiable with no parameters and must implement IPropertyConverter"); } this.Converter = Utils.InstantiateConverter(ConverterType, context) as IPropertyConverter; } IPropertyConverter converter; if (context.ConverterCache.TryGetValue(MemberType, out converter) && converter != null) { this.Converter = converter; } foreach (var index in Indexes) { IndexNames.AddRange(index.IndexNames); } }