Пример #1
0
        /// <inheritdoc />
        protected override bool HandleDynamic(CodeParameterDeclarationExpression obj, Context ctx)
        {
            if (obj.CustomAttributes.Count > 0)
            {
                GeneralUtils.HandleCollection(obj.CustomAttributes.Cast <CodeAttributeDeclaration>(),
                                              ctx.HandlerProvider.AttributeDeclarationHandler, ctx);
                ctx.Writer.Write(" ");
            }

            CodeExpression defaultValue = (obj as CodeParameterDeclarationExpressionExt)?.DefaultValue;

            if (defaultValue != null)
            {
                ctx.Writer.Write("Optional ");
            }

            ctx.Writer.Write(VisualBasicKeywordsUtils.DirectionKeyword(obj.Direction) + " ");

            if (obj is CodeParameterDeclarationExpressionExt objExt && objExt.IsVarargs)
            {
                ctx.Writer.Write("ParamArray  ");
            }

            ctx.Writer.Write($"{obj.Name.AsVbId()} As ");
            ctx.HandlerProvider.TypeReferenceHandler.Handle(obj.Type, ctx);

            if (defaultValue != null)
            {
                ctx.Writer.Write(" = ");
                ctx.HandlerProvider.ExpressionHandler.Handle(defaultValue, ctx);
            }

            return(true);
        }
Пример #2
0
        /// <inheritdoc />
        protected override bool HandleDynamic(CodeUnaryOperatorExpression obj, Context ctx)
        {
            string operatorSymbol = VisualBasicKeywordsUtils.UnaryOperatorSymbol(obj.Operator);

            if (operatorSymbol != null)
            {
                ctx.Writer.Write(operatorSymbol);
                WrapIfNecessaryAndHandle(obj.Expression, ctx);
                return(true);
            }

            if (obj.Operator == CodeUnaryOperatorType.PostDecrement ||
                obj.Operator == CodeUnaryOperatorType.PostIncrement ||
                obj.Operator == CodeUnaryOperatorType.PreDecrement ||
                obj.Operator == CodeUnaryOperatorType.PreIncrement)
            {
                //TODO this is ok when used as an expression, but not when used as a statement. Should be replaced with a method invocation, and add a library
                bool isIncrement = obj.Operator == CodeUnaryOperatorType.PostIncrement ||
                                   obj.Operator == CodeUnaryOperatorType.PreIncrement;
                bool isPre = obj.Operator == CodeUnaryOperatorType.PreDecrement ||
                             obj.Operator == CodeUnaryOperatorType.PreIncrement;

                CodeExpression toReturn;

                if (isPre)
                {
                    toReturn = obj.Expression;
                }
                else
                {
                    toReturn = new CodeBinaryOperatorExpressionMore(
                        obj.Expression,
                        isIncrement ? CodeBinaryOperatorTypeMore.Subtract : CodeBinaryOperatorTypeMore.Add,
                        Primitives.Int(1));
                }

                var lambda = new CodeLambdaDeclarationExpression(
                    new CodeCommentStatement(obj.Operator.ToString("G")),
                    new CodeOperationAssignmentStatement(
                        obj.Expression,
                        isIncrement ? CodeBinaryOperatorTypeMore.Add : CodeBinaryOperatorTypeMore.Subtract,
                        Primitives.Int(1)),
                    new CodeMethodReturnStatement(toReturn));
                ctx.HandlerProvider.ExpressionHandler.Handle(new CodeMethodInvokeExpression(lambda, "Invoke"), ctx);
                return(true);
            }
            return(false);
        }
Пример #3
0
        /// <inheritdoc />
        protected override bool HandleDynamic(CodeBinaryOperatorExpressionMore obj, Context ctx)
        {
            if (obj.OperatorType == CodeBinaryOperatorTypeMore.NullCoalescing)
            {
                ctx.Writer.Write("If(");
                ctx.HandlerProvider.ExpressionHandler.Handle(obj.LeftExpression, ctx);
                ctx.Writer.Write(", ");
                ctx.HandlerProvider.ExpressionHandler.Handle(obj.RightExpression, ctx);
                ctx.Writer.Write(")");
            }
            else
            {
                WrapIfNecessaryAndHandle(obj.LeftExpression, ctx);
                ctx.Writer.Write($" {VisualBasicKeywordsUtils.OperatorSymbol(obj.OperatorType)} ");
                WrapIfNecessaryAndHandle(obj.RightExpression, ctx);
            }

            return(true);
        }
 /// <inheritdoc />
 protected override string GetAccessibilityLevelKeyword(AccessibilityLevel accessibilityLevel, Context ctx)
 {
     return(VisualBasicKeywordsUtils.AccessibilityLevelKeyword(accessibilityLevel));
 }
Пример #5
0
        /// <inheritdoc />
        protected override void HandleProperty(CodeMemberProperty obj, Context ctx, bool isExt,
                                               CodeMemberPropertyExt objExt, bool doDefaultImplementation)
        {
            if (ctx.Options.DoConsistencyChecks)
            {
                if (!doDefaultImplementation && isExt && objExt.PropertyInitializer != null)
                {
                    throw new ConsistencyException($"Property {obj.Name} can't have initializer if it's not auto-property");
                }
            }

            if (GeneralUtils.IsNullOrVoidType(obj.PrivateImplementationType))
            {
                ctx.HandlerProvider.MemberAttributesHandler.Handle(obj.Attributes, ctx);
            }

            if (obj.HasGet && !obj.HasSet)
            {
                ctx.Writer.Write("ReadOnly ");
            }
            else if (obj.HasSet && !obj.HasGet)
            {
                ctx.Writer.Write("WriteOnly ");
            }

            ctx.Writer.Write($"Property ");
            if (GeneralUtils.IsNullOrVoidType(obj.PrivateImplementationType))
            {
                ctx.Writer.Write(obj.Name.AsVbId());
            }
            else
            {
                HandlePrivateImplementationTypeMemberName(obj.Name, obj.PrivateImplementationType, ctx);
            }
            ctx.Writer.Write(" As ");
            ctx.HandlerProvider.TypeReferenceHandler.Handle(obj.Type, ctx);
            if (doDefaultImplementation)
            {
                if (isExt && objExt.PropertyInitializer != null)
                {
                    ctx.Writer.Write(" = ");
                    ctx.HandlerProvider.ExpressionHandler.Handle(objExt.PropertyInitializer, ctx);
                }
                HandleImplementationTypes(obj.ImplementationTypes, obj.Name, ctx);
                HandlePrivateImplType(obj.PrivateImplementationType, obj.Name, ctx);
                ctx.Writer.NewLine();
            }
            else
            {
                HandleImplementationTypes(obj.ImplementationTypes, obj.Name, ctx);
                HandlePrivateImplType(obj.PrivateImplementationType, obj.Name, ctx);
                VisualBasicUtils.BeginBlock(BlockType.Property, ctx);

                if (obj.HasGet)
                {
                    ctx.Writer.Indent(ctx);
                    if (isExt && objExt.GetAccessibilityLevel != obj.Attributes.GetAccessibilityLevel())
                    {
                        ctx.Writer.Write($"{VisualBasicKeywordsUtils.AccessibilityLevelKeyword(objExt.GetAccessibilityLevel)} ");
                    }
                    ctx.Writer.Write("Get");
                    VisualBasicUtils.HandleStatementCollection(obj.GetStatements, ctx, BlockType.Get);
                }

                if (obj.HasSet)
                {
                    ctx.Writer.Indent(ctx);
                    if (isExt && objExt.SetAccessibilityLevel != obj.Attributes.GetAccessibilityLevel())
                    {
                        ctx.Writer.Write($"{VisualBasicKeywordsUtils.AccessibilityLevelKeyword(objExt.SetAccessibilityLevel)} ");
                    }
                    ctx.Writer.Write("Set");
                    VisualBasicUtils.HandleStatementCollection(obj.SetStatements, ctx, BlockType.Set);
                }

                VisualBasicUtils.EndBlock(ctx);
            }
        }
Пример #6
0
 /// <inheritdoc />
 protected override string GetShorthandOperatorSymbol(CodeBinaryOperatorTypeMore op)
 {
     return(op.CanBeShorthandOperator() ? VisualBasicKeywordsUtils.OperatorSymbol(op) : null);
 }
 /// <inheritdoc />
 protected override string GetTypeKeywordString(Type baseType)
 {
     return(VisualBasicKeywordsUtils.GetKeywordFromType(baseType));
 }