Пример #1
0
        public override TypeReference Clone()
        {
            InnerClassTypeReference c = new InnerClassTypeReference(baseType.Clone(), Type, new List <TypeReference>());

            CopyFields(this, c);
            return(c);
        }
 /// <summary>
 /// Converts tree into nested TypeReference/InnerClassTypeReference.
 /// Dotted names are split into separate nodes.
 /// It does not normalize generic arguments.
 /// </summary>
 private static TypeReference NormalizeTypeReference(this INode expr)
 {
     if (expr is IdentifierExpression)
     {
         return(new TypeReference(
                    ((IdentifierExpression)expr).Identifier,
                    ((IdentifierExpression)expr).TypeArguments
                    ));
     }
     else if (expr is MemberReferenceExpression)
     {
         TypeReference outter = NormalizeTypeReference(((MemberReferenceExpression)expr).TargetObject);
         return(new InnerClassTypeReference(
                    outter,
                    ((MemberReferenceExpression)expr).MemberName,
                    ((MemberReferenceExpression)expr).TypeArguments
                    ));
     }
     else if (expr is TypeReferenceExpression)
     {
         return(NormalizeTypeReference(((TypeReferenceExpression)expr).TypeReference));
     }
     else if (expr is InnerClassTypeReference)
     { // Frist - it is also TypeReference
         InnerClassTypeReference typeRef = (InnerClassTypeReference)expr;
         string[]      names             = typeRef.Type.Split('.');
         TypeReference newRef            = NormalizeTypeReference(typeRef.BaseType);
         foreach (string name in names)
         {
             newRef = new InnerClassTypeReference(newRef, name, new List <TypeReference>());
         }
         newRef.GenericTypes.AddRange(typeRef.GenericTypes);
         newRef.PointerNestingLevel = typeRef.PointerNestingLevel;
         newRef.RankSpecifier       = typeRef.RankSpecifier;
         return(newRef);
     }
     else if (expr is TypeReference)
     {
         TypeReference typeRef = (TypeReference)expr;
         string[]      names   = typeRef.Type.Split('.');
         if (names.Length == 1)
         {
             return(typeRef);
         }
         TypeReference newRef = null;
         foreach (string name in names)
         {
             if (newRef == null)
             {
                 newRef = new TypeReference(name, new List <TypeReference>());
             }
             else
             {
                 newRef = new InnerClassTypeReference(newRef, name, new List <TypeReference>());
             }
         }
         newRef.GenericTypes.AddRange(typeRef.GenericTypes);
         newRef.PointerNestingLevel = typeRef.PointerNestingLevel;
         newRef.RankSpecifier       = typeRef.RankSpecifier;
         return(newRef);
     }
     else
     {
         throw new EvaluateException(expr, "Type expected. {0} seen.", expr.GetType().FullName);
     }
 }
        public static TypeReference GetTypeReference(this Type type)
        {
            List <int> arrayRanks = new List <int>();

            while (type.IsArray)
            {
                // C# uses reverse array order
                arrayRanks.Add(type.GetArrayRank() - 1);
                type = type.GetElementType();
            }

            int pointerNest = 0;

            while (type.IsPointer)
            {
                pointerNest++;
                type = type.GetElementType();
            }

            if (type.IsArray)
            {
                throw new DebuggerException("C# does not support pointers to arrays");
            }

            string name = type.Name;

            if (name.IndexOf('`') != -1)
            {
                name = name.Substring(0, name.IndexOf('`'));
            }
            if (!string.IsNullOrEmpty(type.Namespace))
            {
                name = type.Namespace + "." + name;
            }

            List <Type> genArgs = new List <Type>();

            // This inludes the generic arguments of the outter types
            genArgs.AddRange(type.GetGenericArguments());
            if (type.DeclaringType != null)
            {
                genArgs.RemoveRange(0, type.DeclaringType.GetGenericArguments().Length);
            }
            List <TypeReference> genTypeRefs = new List <TypeReference>();

            foreach (Type genArg in genArgs)
            {
                genTypeRefs.Add(genArg.GetTypeReference());
            }

            if (type.DeclaringType != null)
            {
                TypeReference           outterRef = type.DeclaringType.GetTypeReference();
                InnerClassTypeReference innerRef  = new InnerClassTypeReference(outterRef, name, genTypeRefs);
                innerRef.PointerNestingLevel = pointerNest;
                innerRef.RankSpecifier       = arrayRanks.ToArray();
                return(innerRef.SetStaticType((DebugType)type));
            }
            else
            {
                return(new TypeReference(name, pointerNest, arrayRanks.ToArray(), genTypeRefs).SetStaticType((DebugType)type));
            }
        }