Beispiel #1
0
 public DomCecilType(TypeReference typeReference)
 {
     this.classType = ClassType.Unknown;
     this.Modifiers = Modifiers.None;
     this.Name      = DomCecilType.RemoveGenericParamSuffix(typeReference.Name);
     this.Namespace = typeReference.Namespace;
 }
Beispiel #2
0
        public DomCecilType(TypeDefinition typeDefinition, bool loadInternal)
        {
            this.typeDefinition = typeDefinition;
            this.loadInternal   = loadInternal;
            this.classType      = GetClassType(typeDefinition);

            this.Name      = DomCecilType.RemoveGenericParamSuffix(typeDefinition.Name);
            this.Namespace = typeDefinition.Namespace;

            this.Modifiers = GetModifiers(typeDefinition.Attributes);

            if (typeDefinition.BaseType != null)
            {
                this.baseType = DomCecilMethod.GetReturnType(typeDefinition.BaseType);
            }
            DomCecilMethod.AddAttributes(this, typeDefinition.CustomAttributes);

            foreach (TypeReference interfaceReference in typeDefinition.Interfaces)
            {
                this.AddInterfaceImplementation(DomCecilMethod.GetReturnType(interfaceReference));
            }
            foreach (GenericParameter parameter in typeDefinition.GenericParameters)
            {
                TypeParameter tp = new TypeParameter(parameter.FullName);
                tp.Variance = (TypeParameterVariance)(((uint)parameter.Attributes) & 3);
                foreach (TypeReference tr in parameter.Constraints)
                {
                    tp.AddConstraint(DomCecilMethod.GetReturnType(tr));
                }
                AddTypeParameter(tp);
            }
        }
Beispiel #3
0
 public static IReturnType GetReturnType(MethodReference methodReference)
 {
     if (methodReference == null)
     {
         return(DomReturnType.Void);
     }
     return(DomReturnType.GetSharedReturnType(DomCecilType.RemoveGenericParamSuffix(methodReference.DeclaringType.FullName)));
 }
Beispiel #4
0
        /*
         *      // Check if 'type' has some decorations applied to it
         *              if (type is Mono.Cecil.TypeSpecification) {
         *                      // Go through all levels of 'indirection', 'array dimensions'
         *                      // and 'generic types' - in the end, we should get the actual
         *                      // type of the ReturnType (but all data about its array
         *                      // dimensions, levels of indirection and even its generic
         *                      // parameters is correctly stored within ArrayCount and
         *                      // ArrayDimensions, PointerNestingLevel and GenericArguments
         *                      // respectively).
         *                      if (type is ArrayType) {
         *                              // This return type is obviously an array - add the rank
         *                              ArrayType at = (ArrayType) type;
         *                              if (arrays == null)
         *                                      arrays = new Stack<int>();
         *                              arrays.Push(at.Rank);
         *                              type = at.ElementType;
         *                      } else else if (type is Mono.Cecil.ReferenceType) {
         *                              Mono.Cecil.ReferenceType rt = (Mono.Cecil.ReferenceType) type;
         *                              byRef = true;
         *                              type = rt.ElementType;
         *                      } else if (type is PointerType) {
         *                              // The type is a pointer
         *                              PointerType pt = (PointerType) type;
         ++pointerNestingLevel;
         *                              type = pt.ElementType;
         *                              // Go down one level
         *                      } else {
         *                              // TODO: Check if we loose some relevant info here
         *                              type = ((TypeSpecification)type).ElementType;
         *                      }*/
        public static DomReturnType GetReturnType(TypeReference typeReference)
        {
            if (typeReference == null)
            {
                return(new DomReturnType(DomReturnType.Void.ToInvariantString()));
            }

            if (typeReference is Mono.Cecil.GenericInstanceType)
            {
                Mono.Cecil.GenericInstanceType genType = (Mono.Cecil.GenericInstanceType)typeReference;
                DomReturnType result = GetReturnType(genType.ElementType);

                foreach (TypeReference typeRef in genType.GenericArguments)
                {
                    DomReturnType param = GetReturnType(typeRef);

                    foreach (IReturnTypePart part in result.Parts)
                    {
                        if (part.Tag is TypeDefinition)
                        {
                            TypeDefinition typeDef = (TypeDefinition)part.Tag;
                            foreach (TypeReference typeParam in typeDef.GenericParameters)
                            {
                                if (typeParam.Name == param.Name)
                                {
                                    part.AddTypeParameter(param);
                                    goto skip;
                                }
                            }
                        }
                    }
                    result.AddTypeParameter(param);
                    skip :;
                }
                return(result);
            }

            if (typeReference is Mono.Cecil.ArrayType)
            {
                Mono.Cecil.ArrayType arrType = (Mono.Cecil.ArrayType)typeReference;
                DomReturnType        result  = GetReturnType(arrType.ElementType);
                result.ArrayDimensions++;
                result.SetDimension(result.ArrayDimensions - 1, arrType.Rank - 1);
                return(result);
            }

            if (typeReference is Mono.Cecil.PointerType)
            {
                Mono.Cecil.PointerType ptrType = (Mono.Cecil.PointerType)typeReference;
                DomReturnType          result  = GetReturnType(ptrType.ElementType);
                if (result.ArrayDimensions > 0)
                {
                    result.ArrayPointerNestingLevel++;
                }
                else
                {
                    result.PointerNestingLevel++;
                }
                return(result);
            }
            if (typeReference is Mono.Cecil.ByReferenceType)
            {
                return(GetReturnType(((Mono.Cecil.ByReferenceType)typeReference).ElementType));
            }

            if (typeReference is Mono.Cecil.TypeDefinition)
            {
                Mono.Cecil.TypeDefinition typeDefinition = (Mono.Cecil.TypeDefinition)typeReference;
                DomReturnType             result;
                if (typeDefinition.DeclaringType != null)
                {
                    result = GetReturnType(typeDefinition.DeclaringType);
                    result.Parts.Add(new ReturnTypePart(typeDefinition.Name));
                    result.Tag = typeDefinition;
                }
                else
                {
                    result           = new DomReturnType(typeDefinition.Name);
                    result.Namespace = typeDefinition.Namespace;
                    result.Tag       = typeDefinition;
                }
                return(result);
            }

            return(new DomReturnType(DomCecilType.RemoveGenericParamSuffix(typeReference.FullName)));
        }