當前位置: 首頁>>代碼示例>>C#>>正文


C# BoundObjectCreationExpression類代碼示例

本文整理匯總了C#中BoundObjectCreationExpression的典型用法代碼示例。如果您正苦於以下問題:C# BoundObjectCreationExpression類的具體用法?C# BoundObjectCreationExpression怎麽用?C# BoundObjectCreationExpression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BoundObjectCreationExpression類屬於命名空間,在下文中一共展示了BoundObjectCreationExpression類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EmitObjectCreationExpression

        private void EmitObjectCreationExpression(BoundObjectCreationExpression expression, bool used)
        {
            MethodSymbol constructor = expression.Constructor;
            if (constructor.IsDefaultValueTypeConstructor())
            {
                EmitInitObj(expression.Type, used, expression.Syntax);
            }
            else
            {
                if (!used &&
                    expression.Constructor.OriginalDefinition == _module.Compilation.GetSpecialTypeMember(SpecialMember.System_Nullable_T__ctor))
                {
                    // creating nullable has no side-effects, so we will just evaluate the arg
                    EmitExpression(expression.Arguments[0], used: false);
                }
                else
                {
                    EmitArguments(expression.Arguments, constructor.Parameters);

                    var stackAdjustment = GetObjCreationStackBehavior(expression);
                    _builder.EmitOpCode(ILOpCode.Newobj, stackAdjustment);

                    // for variadic ctors emit expanded ctor token
                    EmitSymbolToken(constructor, expression.Syntax,
                                    constructor.IsVararg ? (BoundArgListOperator)expression.Arguments[expression.Arguments.Length - 1] : null);

                    EmitPopIfUnused(used);
                }
            }
        }
開發者ID:tvsonar,項目名稱:roslyn,代碼行數:30,代碼來源:EmitExpression.cs

示例2: InPlaceCtorCall

        private void InPlaceCtorCall(BoundExpression target, BoundObjectCreationExpression objCreation, bool used)
        {
            var temp = EmitAddress(target, AddressKind.Writeable);
            Debug.Assert(temp == null, "in-place ctor target should not create temps");

            var constructor = objCreation.Constructor;
            EmitArguments(objCreation.Arguments, constructor.Parameters);
            // -2 to adjust for consumed target address and not produced value.
            var stackAdjustment = GetObjCreationStackBehavior(objCreation) - 2;
            _builder.EmitOpCode(ILOpCode.Call, stackAdjustment);
            // for variadic ctors emit expanded ctor token
            EmitSymbolToken(constructor, objCreation.Syntax,
                            constructor.IsVararg ? (BoundArgListOperator)objCreation.Arguments[objCreation.Arguments.Length - 1] : null);

            if (used)
            {
                Debug.Assert(TargetIsNotOnHeap(target), "cannot read-back the target since it could have been modified");
                EmitExpression(target, used: true);
            }
        }
開發者ID:tvsonar,項目名稱:roslyn,代碼行數:20,代碼來源:EmitExpression.cs

示例3: VisitObjectCreationExpression

        public override BoundNode VisitObjectCreationExpression(BoundObjectCreationExpression node)
        {
            var constructor = node.Constructor;
            var rewrittenArguments = VisitArguments(node.Arguments, constructor.Parameters);
            Debug.Assert(node.InitializerExpressionOpt == null);

            return node.Update(constructor, rewrittenArguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt,
                node.Expanded, node.ArgsToParamsOpt, node.ConstantValue, null, node.Type);
        }
開發者ID:rosslyn-cuongle,項目名稱:roslyn,代碼行數:9,代碼來源:Optimizer.cs

示例4: GetObjCreationStackBehavior

        private static int GetObjCreationStackBehavior(BoundObjectCreationExpression objCreation)
        {
            int stack = 0;

            // Constructor puts the return value on the stack.
            stack += 1;

            if (objCreation.Constructor.IsVararg)
            {
                // Constructor pops all the arguments, fixed and variadic.
                int fixedArgCount = objCreation.Arguments.Length - 1;
                int varArgCount = ((BoundArgListOperator)objCreation.Arguments[fixedArgCount]).Arguments.Length;
                stack -= fixedArgCount;
                stack -= varArgCount;
            }
            else
            {
                // Constructor pops all the arguments.
                stack -= objCreation.Arguments.Length;
            }

            return stack;
        }
開發者ID:tvsonar,項目名稱:roslyn,代碼行數:23,代碼來源:EmitExpression.cs

示例5: VisitObjectCreationExpression

        public override BoundNode VisitObjectCreationExpression(BoundObjectCreationExpression node)
        {
            var rewritten = (BoundObjectCreationExpression)base.VisitObjectCreationExpression(node);
            if (rewritten.Type != node.Type && (object)node.Constructor != null)
            {
                MethodSymbol ctor = VisitMethodSymbol(node.Constructor);
                rewritten = rewritten.Update(
                    ctor,
                    rewritten.Arguments,
                    rewritten.ArgumentNamesOpt,
                    rewritten.ArgumentRefKindsOpt,
                    rewritten.Expanded,
                    rewritten.ArgsToParamsOpt,
                    rewritten.ConstantValueOpt,
                    rewritten.InitializerExpressionOpt,
                    rewritten.Type);
            }

            return rewritten;
        }
開發者ID:XieShuquan,項目名稱:roslyn,代碼行數:20,代碼來源:MethodToClassRewriter.cs

示例6: GetTypeVariablesMethod

 private EEMethodSymbol GetTypeVariablesMethod(EENamedTypeSymbol container, string methodName, NamedTypeSymbol typeVariablesType)
 {
     var syntax = SyntaxFactory.IdentifierName(SyntaxFactory.MissingToken(SyntaxKind.IdentifierToken));
     return this.CreateMethod(container, methodName, syntax, (method, diagnostics) =>
     {
         var type = method.TypeMap.SubstituteNamedType(typeVariablesType);
         var expression = new BoundObjectCreationExpression(syntax, type.InstanceConstructors[0]);
         var statement = new BoundReturnStatement(syntax, expression) { WasCompilerGenerated = true };
         return statement;
     });
 }
開發者ID:rgani,項目名稱:roslyn,代碼行數:11,代碼來源:CompilationContext.cs

示例7: EmitObjectCreationExpression

        private void EmitObjectCreationExpression(BoundObjectCreationExpression expression, bool used)
        {
            MethodSymbol constructor = expression.Constructor;
            if (constructor.IsDefaultValueTypeConstructor())
            {
                EmitInitObj(expression.Type, used, expression.Syntax);
            }
            else
            {
                if (!used && ConstructorNotSideEffecting(constructor))
                {
                    // creating nullable has no side-effects, so we will just evaluate the arguments
                    foreach (var arg in expression.Arguments)
                    {
                        EmitExpression(arg, used: false);
                    }
                }
                else
                {
                    EmitArguments(expression.Arguments, constructor.Parameters);

                    var stackAdjustment = GetObjCreationStackBehavior(expression);
                    _builder.EmitOpCode(ILOpCode.Newobj, stackAdjustment);

                    // for variadic ctors emit expanded ctor token
                    EmitSymbolToken(constructor, expression.Syntax,
                                    constructor.IsVararg ? (BoundArgListOperator)expression.Arguments[expression.Arguments.Length - 1] : null);

                    EmitPopIfUnused(used);
                }
            }
        }
開發者ID:jkotas,項目名稱:roslyn,代碼行數:32,代碼來源:EmitExpression.cs

示例8: EmitObjectCreationExpression

        private void EmitObjectCreationExpression(BoundObjectCreationExpression expression, bool used)
        {
            MethodSymbol constructor = expression.Constructor;
            if (constructor.IsParameterlessValueTypeConstructor(requireSynthesized: true))
            {
                EmitInitObj(expression.Type, used, expression.Syntax);
            }
            else
            {
                EmitArguments(expression.Arguments, constructor.Parameters);

                var stackAdjustment = GetObjCreationStackBehavior(expression);
                builder.EmitOpCode(ILOpCode.Newobj, stackAdjustment);

                // for variadic ctors emit expanded ctor token
                EmitSymbolToken(constructor, expression.Syntax,
                                constructor.IsVararg ? (BoundArgListOperator)expression.Arguments[expression.Arguments.Length - 1] : null);

                EmitPopIfUnused(used);
            }
        }
開發者ID:riversky,項目名稱:roslyn,代碼行數:21,代碼來源:EmitExpression.cs

示例9: VisitObjectCreationExpression

        public override BoundNode VisitObjectCreationExpression(BoundObjectCreationExpression node)
        {
            Debug.Assert(node != null);

            // Start by rewriting the arguments:
            var rewrittenArguments = VisitList(node.Arguments);

            // If the mapping from arguments to parameters is perfectly in order, no complex rewriting is needed.
            if (node.ArgsToParamsOpt.IsNull && !node.Expanded)
            {
                return node.Update(node.ConstructorOpt, rewrittenArguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt, node.Expanded, node.ArgsToParamsOpt, node.ConstantValueOpt, node.Type);
            }

            var argumentRefKinds = node.ArgumentRefKindsOpt;
            ReadOnlyArray<LocalSymbol> temps;

            Debug.Assert(node.ConstructorOpt != null, "rewriting arguments when there is no constructor");

            RewriteArguments(node.ConstructorOpt,
                        node.Expanded,
                        node.ArgsToParamsOpt,
                        ref argumentRefKinds,
                        ref rewrittenArguments,
                        out temps);

            if (temps.IsNullOrEmpty)
            {
                return node.Update(
                    node.ConstructorOpt,
                    rewrittenArguments,
                    ReadOnlyArray<string>.Null,
                    argumentRefKinds,
                    false,
                    ReadOnlyArray<int>.Null,
                    node.ConstantValueOpt,
                    node.Type);
            }
            else
            {
                return new BoundSequence(
                    null,
                    null,
                    temps,
                    ReadOnlyArray<BoundExpression>.Empty,
                    new BoundObjectCreationExpression(
                        node.Syntax,
                        node.SyntaxTree,
                        node.ConstructorOpt,
                        rewrittenArguments,
                        ReadOnlyArray<string>.Null,
                        argumentRefKinds,
                        false,
                        ReadOnlyArray<int>.Null,
                        node.ConstantValueOpt,
                        node.Type),
                    node.Type
                );
            }
        }
開發者ID:modulexcite,項目名稱:pattern-matching-csharp,代碼行數:59,代碼來源:CallRewriter.cs

示例10: IsValidDefaultValue

 private static bool IsValidDefaultValue(BoundObjectCreationExpression expression)
 {
     return expression.Constructor.IsDefaultValueTypeConstructor() && expression.InitializerExpressionOpt == null;
 }
開發者ID:Rickinio,項目名稱:roslyn,代碼行數:4,代碼來源:ParameterHelpers.cs


注:本文中的BoundObjectCreationExpression類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。