Ejemplo n.º 1
0
 public CastExpression CastTo(AstType type)
 {
     return(new CastExpression {
         Type = type, Expression = this
     });
 }
Ejemplo n.º 2
0
 public CastExpression(AstType castToType, Expression expression)
 {
     AddChild(castToType, Roles.Type);
     AddChild(expression, Roles.Expression);
 }
Ejemplo n.º 3
0
 public UsingAliasDeclaration(string alias, AstType import)
 {
     AddChild(Identifier.Create (alias), AliasRole);
     AddChild(import, ImportRole);
 }
 private TypeExpression(NRefactory.AstType astType, TypeDescription typeDescription, IScope scope, INRefcatoryExpressionVisitor visitor)
     : base(scope, visitor) {
     _astType = astType;
     _typeDescription = typeDescription;
 }
Ejemplo n.º 5
0
 public TypeReferenceExpression(AstType type)
 {
     AddChild(type, Roles.Type);
 }
 public UsingDeclaration(AstType import)
 {
     AddChild(import, ImportRole);
 }
Ejemplo n.º 7
0
 public override AsExpression CastAs(AstType type)
 {
     return(new AsExpression {
         Type = type, Expression = new ParenthesizedExpression(this)
     });
 }
Ejemplo n.º 8
0
 public CastExpression CastTo(Type type)
 {
     return(new CastExpression {
         Type = AstType.Create(type), Expression = this
     });
 }
Ejemplo n.º 9
0
 public AsExpression CastAs(Type type)
 {
     return(new AsExpression {
         Type = AstType.Create(type), Expression = this
     });
 }
Ejemplo n.º 10
0
        internal static ITypeReference ConvertType(AstType type, ITypeDefinition parentTypeDefinition, IMethod parentMethodDefinition, UsingScope parentUsingScope, bool isInUsingDeclaration)
        {
            SimpleType s = type as SimpleType;

            if (s != null)
            {
                List <ITypeReference> typeArguments = new List <ITypeReference>();
                foreach (var ta in s.TypeArguments)
                {
                    typeArguments.Add(ConvertType(ta, parentTypeDefinition, parentMethodDefinition, parentUsingScope, isInUsingDeclaration));
                }
                if (typeArguments.Count == 0 && parentMethodDefinition != null)
                {
                    // SimpleTypeOrNamespaceReference doesn't support method type parameters,
                    // so we directly handle them here.
                    foreach (ITypeParameter tp in parentMethodDefinition.TypeParameters)
                    {
                        if (tp.Name == s.Identifier)
                        {
                            return(tp);
                        }
                    }
                }
                return(new SimpleTypeOrNamespaceReference(s.Identifier, typeArguments, parentTypeDefinition, parentUsingScope, isInUsingDeclaration));
            }

            PrimitiveType p = type as PrimitiveType;

            if (p != null)
            {
                switch (p.Keyword)
                {
                case "string":
                    return(KnownTypeReference.String);

                case "int":
                    return(KnownTypeReference.Int32);

                case "uint":
                    return(KnownTypeReference.UInt32);

                case "object":
                    return(KnownTypeReference.Object);

                case "bool":
                    return(KnownTypeReference.Boolean);

                case "sbyte":
                    return(KnownTypeReference.SByte);

                case "byte":
                    return(KnownTypeReference.Byte);

                case "short":
                    return(KnownTypeReference.Int16);

                case "ushort":
                    return(KnownTypeReference.UInt16);

                case "long":
                    return(KnownTypeReference.Int64);

                case "ulong":
                    return(KnownTypeReference.UInt64);

                case "float":
                    return(KnownTypeReference.Single);

                case "double":
                    return(KnownTypeReference.Double);

                case "decimal":
                    return(ReflectionHelper.ToTypeReference(TypeCode.Decimal));

                case "char":
                    return(KnownTypeReference.Char);

                case "void":
                    return(KnownTypeReference.Void);

                default:
                    return(SharedTypes.UnknownType);
                }
            }
            MemberType m = type as MemberType;

            if (m != null)
            {
                ITypeOrNamespaceReference t;
                if (m.IsDoubleColon)
                {
                    SimpleType st = m.Target as SimpleType;
                    if (st != null)
                    {
                        t = new AliasNamespaceReference(st.Identifier, parentUsingScope);
                    }
                    else
                    {
                        t = null;
                    }
                }
                else
                {
                    t = ConvertType(m.Target, parentTypeDefinition, parentMethodDefinition, parentUsingScope, isInUsingDeclaration) as ITypeOrNamespaceReference;
                }
                if (t == null)
                {
                    return(SharedTypes.UnknownType);
                }
                List <ITypeReference> typeArguments = new List <ITypeReference>();
                foreach (var ta in m.TypeArguments)
                {
                    typeArguments.Add(ConvertType(ta, parentTypeDefinition, parentMethodDefinition, parentUsingScope, isInUsingDeclaration));
                }
                return(new MemberTypeOrNamespaceReference(t, m.MemberName, typeArguments, parentTypeDefinition, parentUsingScope));
            }
            ComposedType c = type as ComposedType;

            if (c != null)
            {
                ITypeReference t = ConvertType(c.BaseType, parentTypeDefinition, parentMethodDefinition, parentUsingScope, isInUsingDeclaration);
                if (c.HasNullableSpecifier)
                {
                    t = NullableType.Create(t);
                }
                for (int i = 0; i < c.PointerRank; i++)
                {
                    t = PointerTypeReference.Create(t);
                }
                foreach (var a in c.ArraySpecifiers.Reverse())
                {
                    t = ArrayTypeReference.Create(t, a.Dimensions);
                }
                return(t);
            }
            Debug.WriteLine("Unknown node used as type: " + type);
            return(SharedTypes.UnknownType);
        }
Ejemplo n.º 11
0
 public UsingDeclaration(string nameSpace)
 {
     AddChild(AstType.Create(nameSpace), ImportRole);
 }
Ejemplo n.º 12
0
 ITypeReference ConvertType(AstType type, bool isInUsingDeclaration = false)
 {
     return(ConvertType(type, currentTypeDefinition, currentMethod, usingScope, isInUsingDeclaration));
 }
Ejemplo n.º 13
0
 DefaultExplicitInterfaceImplementation ConvertInterfaceImplementation(AstType interfaceType, string memberName)
 {
     return(new DefaultExplicitInterfaceImplementation(ConvertType(interfaceType), memberName));
 }
Ejemplo n.º 14
0
 public VariableDeclarationStatement(AstType type, string name, Expression initializer = null)
 {
     this.Type = type;
     this.Variables.Add(new VariableInitializer(name, initializer));
 }
Ejemplo n.º 15
0
 public AsExpression CastAs(AstType type)
 {
     return(new AsExpression {
         Type = type, Expression = this
     });
 }
Ejemplo n.º 16
0
 public IsExpression IsType(Type type)
 {
     return(new IsExpression {
         Type = AstType.Create(type), Expression = this
     });
 }
Ejemplo n.º 17
0
 public IsExpression IsType(AstType type)
 {
     return(new IsExpression {
         Type = type, Expression = this
     });
 }
Ejemplo n.º 18
0
 public ParameterDeclaration(AstType type, string name)
 {
     this.Type = type;
     this.Name = name;
 }
Ejemplo n.º 19
0
 public AsExpression(Expression expression, AstType type)
 {
     AddChild(expression, Roles.Expression);
     AddChild(type, Roles.Type);
 }
Ejemplo n.º 20
0
 public MemberType(AstType target, string memberName)
 {
     this.Target     = target;
     this.MemberName = memberName;
 }
Ejemplo n.º 21
0
 public override IsExpression IsType(AstType type)
 {
     return(new IsExpression {
         Type = type, Expression = new ParenthesizedExpression(this)
     });
 }
Ejemplo n.º 22
0
 public MemberType(AstType target, string memberName, params AstType[] typeArguments) : this(target, memberName, (IEnumerable <AstType>)typeArguments)
 {
 }
 private TypeExpression(NRefactory.AstType astType, TypeDescription typeDescription, IScope scope, INRefcatoryExpressionVisitor visitor)
     : base(scope, visitor)
 {
     _astType         = astType;
     _typeDescription = typeDescription;
 }
Ejemplo n.º 24
0
 public ObjectCreateExpression(AstType type, params Expression[] arguments) : this(type, (IEnumerable <Expression>)arguments)
 {
 }