Beispiel #1
0
        private string ResolvePredefinedAndArrayTypes(TypeSyntax type)
        {
            switch (type.Kind())
            {
            case SyntaxKind.PredefinedType: return(Context.TypeResolver.ResolvePredefinedType(Context.GetTypeInfo(type).Type.Name));

            case SyntaxKind.ArrayType: return(ResolveType(type.DescendantNodes().OfType <TypeSyntax>().Single()) + ".MakeArrayType()");

            case SyntaxKind.PointerType: return(ResolveType(type.DescendantNodes().OfType <TypeSyntax>().Single()) + ".MakePointerType()");
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a closed generic type from the a generic type definition (like <see cref="IEnumerable{T}"/>) and type arguments (like <see cref="string"/>).
        /// </summary>
        /// <param name="genericTypeDefinition">The generic type definition</param>
        /// <param name="typeArguments">Type arguments</param>
        /// <returns>The generic type.</returns>
        public static TypeSyntax CreateGenericTypeFromGenericTypeDefinition(TypeSyntax genericTypeDefinition, params TypeSyntax[] typeArguments)
        {
            GenericNameSyntax openType   = genericTypeDefinition.DescendantNodes().OfType <GenericNameSyntax>().Single();
            GenericNameSyntax closedType = openType.AddTypeArgumentListArguments(typeArguments);

            return(genericTypeDefinition.ReplaceNode(openType, closedType));
        }
Beispiel #3
0
        public void Init(TypeSyntax typeSyntax, string name, string className, int index,
                         Dictionary <string, MethodDeclarationSyntax> methods, SourceBuilder sb)
        {
            Type           = typeSyntax.ToString();
            this.Name      = name;
            this.className = className;
            this.index     = index;
            this.methods   = methods;
            this.sb        = sb;

            foreach (var innerType in typeSyntax.DescendantNodes().OfType <TypeSyntax>())
            {
                var s = innerType.ToString();
                typeArgs.Add(s);
                capitalizedTypeArgs.Add(s.First().ToString().ToUpper() + s.Substring(1));
            }
        }
Beispiel #4
0
 public static bool ContainsGenericTypeParameterOf(this TypeSyntax type, MethodDeclarationSyntax method)
 {
     return(type.DescendantNodes <TypeSyntax>().Any(t => t.IsGenericTypeParameterOf(method)));
 }