Amazon.DynamoDBv2.DataModel.Utils.ImplementsInterface C# (CSharp) Method

ImplementsInterface() public static method

public static ImplementsInterface ( Type targetType, Type interfaceType ) : bool
targetType System.Type
interfaceType System.Type
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;
        }

Usage Example

Ejemplo n.º 1
0
        /// <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);
            }
        }
All Usage Examples Of Amazon.DynamoDBv2.DataModel.Utils::ImplementsInterface