/// <summary>
        /// Creates a method symbol that can be used to describe an operator declaration.
        /// </summary>
        public static IMethodSymbol CreateOperatorSymbol(
            ImmutableArray <AttributeData> attributes,
            Accessibility accessibility,
            DeclarationModifiers modifiers,
            ITypeSymbol returnType,
            CodeGenerationOperatorKind operatorKind,
            ImmutableArray <IParameterSymbol> parameters,
            ImmutableArray <SyntaxNode> statements = default,
            ImmutableArray <AttributeData> returnTypeAttributes = default)
        {
            int expectedParameterCount = CodeGenerationOperatorSymbol.GetParameterCount(operatorKind);

            if (parameters.Length != expectedParameterCount)
            {
                var message = expectedParameterCount == 1 ?
                              WorkspacesResources.Invalid_number_of_parameters_for_unary_operator :
                              WorkspacesResources.Invalid_number_of_parameters_for_binary_operator;
                throw new ArgumentException(message, nameof(parameters));
            }

            var result = new CodeGenerationOperatorSymbol(null, attributes, accessibility, modifiers, returnType, operatorKind, parameters, returnTypeAttributes);

            CodeGenerationMethodInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, modifiers.IsPartial, modifiers.IsAsync, statements, handlesExpressions: default);
            return(result);
        }
示例#2
0
        public static void Attach(
            IMethodSymbol method,
            bool isNew,
            bool isUnsafe,
            bool isPartial,
            bool isAsync,
            ImmutableArray <SyntaxNode> statements,
            ImmutableArray <SyntaxNode> handlesExpressions)
        {
            var info = new CodeGenerationMethodInfo(isNew, isUnsafe, isPartial, isAsync, statements, handlesExpressions);

            s_methodToInfoMap.Add(method, info);
        }
        /// <summary>
        /// Creates a method symbol that can be used to describe a conversion declaration.
        /// </summary>
        public static IMethodSymbol CreateConversionSymbol(
            ImmutableArray <AttributeData> attributes,
            Accessibility accessibility,
            DeclarationModifiers modifiers,
            ITypeSymbol toType,
            IParameterSymbol fromType,
            bool isImplicit = false,
            ImmutableArray <SyntaxNode> statements          = default,
            ImmutableArray <AttributeData> toTypeAttributes = default)
        {
            var result = new CodeGenerationConversionSymbol(null, attributes, accessibility, modifiers, toType, fromType, isImplicit, toTypeAttributes);

            CodeGenerationMethodInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, modifiers.IsPartial, modifiers.IsAsync, statements, handlesExpressions: default);
            return(result);
        }
        protected override CodeGenerationSymbol Clone()
        {
            var result = new CodeGenerationMethodSymbol(this.ContainingType,
                                                        this.GetAttributes(), this.DeclaredAccessibility, this.Modifiers,
                                                        this.ReturnType, this.RefKind, this.ExplicitInterfaceImplementations,
                                                        this.Name, this.TypeParameters, this.Parameters, this.GetReturnTypeAttributes());

            CodeGenerationMethodInfo.Attach(result,
                                            CodeGenerationMethodInfo.GetIsNew(this),
                                            CodeGenerationMethodInfo.GetIsUnsafe(this),
                                            CodeGenerationMethodInfo.GetIsPartial(this),
                                            CodeGenerationMethodInfo.GetIsAsync(this),
                                            CodeGenerationMethodInfo.GetStatements(this),
                                            CodeGenerationMethodInfo.GetHandlesExpressions(this));

            return(result);
        }
        internal static IMethodSymbol CreateMethodSymbol(
            INamedTypeSymbol containingType,
            ImmutableArray <AttributeData> attributes,
            Accessibility accessibility, DeclarationModifiers modifiers,
            ITypeSymbol returnType,
            RefKind refKind,
            ImmutableArray <IMethodSymbol> explicitInterfaceImplementations, string name,
            ImmutableArray <ITypeParameterSymbol> typeParameters,
            ImmutableArray <IParameterSymbol> parameters,
            ImmutableArray <SyntaxNode> statements              = default,
            ImmutableArray <SyntaxNode> handlesExpressions      = default,
            ImmutableArray <AttributeData> returnTypeAttributes = default,
            MethodKind methodKind = MethodKind.Ordinary)
        {
            var result = new CodeGenerationMethodSymbol(containingType, attributes, accessibility, modifiers, returnType, refKind, explicitInterfaceImplementations, name, typeParameters, parameters, returnTypeAttributes, methodKind);

            CodeGenerationMethodInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, modifiers.IsPartial, modifiers.IsAsync, statements, handlesExpressions);
            return(result);
        }
示例#6
0
 private static bool GetIsAsync(CodeGenerationMethodInfo info)
 => info != null && info._isAsync;
示例#7
0
 private static bool GetIsPartial(CodeGenerationMethodInfo info)
 => info != null && info._isPartial;
示例#8
0
 private static bool GetIsUnsafe(CodeGenerationMethodInfo info)
 => info != null && info._isUnsafe;
示例#9
0
 private static ImmutableArray <SyntaxNode> GetHandlesExpressions(CodeGenerationMethodInfo info)
 => info?._handlesExpressions ?? ImmutableArray <SyntaxNode> .Empty;
示例#10
0
 private static ImmutableArray <SyntaxNode> GetStatements(CodeGenerationMethodInfo info)
 => info?._statements ?? ImmutableArray <SyntaxNode> .Empty;