Beispiel #1
0
        protected virtual bool isValidType(IGenericParameterProvider gpp, TypeReference type)
        {
            if (type == null)
            {
                return(false);
            }
            if (type.EType == ElementType.Void)
            {
                return(false);
            }

            while (type != null)
            {
                switch (MemberReferenceHelper.getMemberReferenceType(type))
                {
                case CecilType.ArrayType:
                case CecilType.GenericInstanceType:
                case CecilType.PointerType:
                case CecilType.TypeDefinition:
                case CecilType.TypeReference:
                    break;

                case CecilType.GenericParameter:
                    var gp        = (GenericParameter)type;
                    var methodRef = gpp as MethodReference;
                    var typeRef   = gpp as TypeReference;
                    if (methodRef != null)
                    {
                        if (methodRef.DeclaringType != gp.Owner && methodRef != gp.Owner)
                        {
                            return(false);
                        }
                    }
                    else if (typeRef != null)
                    {
                        if (typeRef != gp.Owner)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                case CecilType.ByReferenceType:
                case CecilType.FunctionPointerType:
                case CecilType.OptionalModifierType:
                case CecilType.PinnedType:
                case CecilType.RequiredModifierType:
                case CecilType.SentinelType:
                default:
                    return(false);
                }

                if (!(type is TypeSpecification))
                {
                    break;
                }
                type = ((TypeSpecification)type).ElementType;
            }

            return(type != null);
        }