コード例 #1
0
        /// <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)
        {
            var 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
        /// <summary>
        /// Creates a method symbol that can be used to describe a conversion declaration.
        /// </summary>
        public static IMethodSymbol CreateConversionSymbol(IList <AttributeData> attributes, Accessibility accessibility, SymbolModifiers modifiers, ITypeSymbol toType, IParameterSymbol fromType, bool isImplicit = false, IList <SyntaxNode> statements = null, IList <AttributeData> toTypeAttributes = null)
        {
            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: null);
            return(result);
        }
コード例 #3
0
        internal static IMethodSymbol CreateMethodSymbol(INamedTypeSymbol containingType, IList <AttributeData> attributes, Accessibility accessibility, SymbolModifiers modifiers, ITypeSymbol returnType, IMethodSymbol explicitInterfaceSymbol, string name, IList <ITypeParameterSymbol> typeParameters, IList <IParameterSymbol> parameters, IList <SyntaxNode> statements = null, IList <SyntaxNode> handlesExpressions = null, IList <AttributeData> returnTypeAttributes = null)
        {
            var result = new CodeGenerationMethodSymbol(containingType, attributes, accessibility, modifiers, returnType, explicitInterfaceSymbol, name, typeParameters, parameters, returnTypeAttributes);

            CodeGenerationMethodInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, modifiers.IsPartial, modifiers.IsAsync, statements, handlesExpressions);
            return(result);
        }
コード例 #4
0
        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(),
                _documentationCommentXml,
                this.MethodKind,
                this.IsInitOnly
                );

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

            return(result);
        }
コード例 #5
0
 public static void Attach(
     IMethodSymbol method,
     bool isNew,
     bool isUnsafe,
     bool isPartial,
     bool isAsync,
     IList<SyntaxNode> statements,
     IList<SyntaxNode> handlesExpressions)
 {
     var info = new CodeGenerationMethodInfo(isNew, isUnsafe, isPartial, isAsync, statements, handlesExpressions);
     s_methodToInfoMap.Add(method, info);
 }
コード例 #6
0
        public static void Attach(
            IMethodSymbol method,
            bool isNew,
            bool isUnsafe,
            bool isPartial,
            bool isAsync,
            IList <SyntaxNode> statements,
            IList <SyntaxNode> handlesExpressions)
        {
            var info = new CodeGenerationMethodInfo(isNew, isUnsafe, isPartial, isAsync, statements, handlesExpressions);

            methodToInfoMap.Add(method, info);
        }
コード例 #7
0
        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,
            bool isInitOnly       = false
            )
        {
            var result = new CodeGenerationMethodSymbol(
                containingType,
                attributes,
                accessibility,
                modifiers,
                returnType,
                refKind,
                explicitInterfaceImplementations,
                name,
                typeParameters,
                parameters,
                returnTypeAttributes,
                documentationCommentXml: null,
                methodKind,
                isInitOnly
                );

            CodeGenerationMethodInfo.Attach(
                result,
                modifiers.IsNew,
                modifiers.IsUnsafe,
                modifiers.IsPartial,
                modifiers.IsAsync,
                statements,
                handlesExpressions
                );
            return(result);
        }
コード例 #8
0
        /// <summary>
        /// Creates a method symbol that can be used to describe an operator declaration.
        /// </summary>
        public static IMethodSymbol CreateOperatorSymbol(IList <AttributeData> attributes, Accessibility accessibility, SymbolModifiers modifiers, ITypeSymbol returnType, CodeGenerationOperatorKind operatorKind, IList <IParameterSymbol> parameters, IList <SyntaxNode> statements = null, IList <AttributeData> returnTypeAttributes = null)
        {
            int expectedParameterCount = CodeGenerationOperatorSymbol.GetParameterCount(operatorKind);

            if (parameters.Count != expectedParameterCount)
            {
                var message = expectedParameterCount == 1 ?
                              WorkspacesResources.InvalidParameterCountForUnaryOperator :
                              WorkspacesResources.InvalidParameterCountForBinaryOperator;
                throw new ArgumentException(message, "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: null);
            return(result);
        }
コード例 #9
0
        protected override CodeGenerationSymbol Clone()
        {
            var result = new CodeGenerationMethodSymbol(this.ContainingType,
                this.GetAttributes(), this.DeclaredAccessibility, this.Modifiers,
                this.ReturnType, this.ExplicitInterfaceImplementations.FirstOrDefault(),
                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;
        }
コード例 #10
0
        internal static IMethodSymbol CreateMethodSymbol(
            INamedTypeSymbol containingType,
            ImmutableArray <AttributeData> attributes,
            Accessibility accessibility, DeclarationModifiers modifiers,
            ITypeSymbol returnType, bool returnsByRef,
            IMethodSymbol explicitInterfaceSymbol, string name,
            ImmutableArray <ITypeParameterSymbol> typeParameters,
            ImmutableArray <IParameterSymbol> parameters,
            ImmutableArray <SyntaxNode> statements              = default(ImmutableArray <SyntaxNode>),
            ImmutableArray <SyntaxNode> handlesExpressions      = default(ImmutableArray <SyntaxNode>),
            ImmutableArray <AttributeData> returnTypeAttributes = default(ImmutableArray <AttributeData>),
            MethodKind methodKind = MethodKind.Ordinary)
        {
            var result = new CodeGenerationMethodSymbol(containingType, attributes, accessibility, modifiers, returnType, returnsByRef, explicitInterfaceSymbol, name, typeParameters, parameters, returnTypeAttributes, methodKind);

            CodeGenerationMethodInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, modifiers.IsPartial, modifiers.IsAsync, statements, handlesExpressions);
            return(result);
        }
コード例 #11
0
 private static bool GetIsAsync(CodeGenerationMethodInfo info)
 {
     return(info != null && info.isAsync);
 }
コード例 #12
0
 private static ImmutableArray <SyntaxNode> GetStatements(CodeGenerationMethodInfo info)
 => info?._statements ?? ImmutableArray <SyntaxNode> .Empty;
コード例 #13
0
 private static bool GetIsUnsafe(CodeGenerationMethodInfo info)
 {
     return(info != null && info.isUnsafe);
 }
コード例 #14
0
 private static bool GetIsPartial(CodeGenerationMethodInfo info)
 {
     return(info != null && info.isPartial);
 }
コード例 #15
0
 private static ImmutableArray <SyntaxNode> GetHandlesExpressions(CodeGenerationMethodInfo info)
 => info?._handlesExpressions ?? ImmutableArray <SyntaxNode> .Empty;
コード例 #16
0
 private static bool GetIsNew(CodeGenerationMethodInfo info)
 {
     return(info != null && info.isNew);
 }
コード例 #17
0
 private static bool GetIsPartial(CodeGenerationMethodInfo info)
 => info != null && info._isPartial;
コード例 #18
0
 private static bool GetIsUnsafe(CodeGenerationMethodInfo info)
 {
     return info != null && info._isUnsafe;
 }
コード例 #19
0
 private static bool GetIsAsync(CodeGenerationMethodInfo info)
 {
     return info != null && info._isAsync;
 }
コード例 #20
0
 private static bool GetIsAsync(CodeGenerationMethodInfo info)
 => info != null && info._isAsync;
コード例 #21
0
 private static IList<SyntaxNode> GetHandlesExpressions(CodeGenerationMethodInfo info)
 {
     return info == null
         ? SpecializedCollections.EmptyList<SyntaxNode>()
         : info._handlesExpressions;
 }
コード例 #22
0
 private static bool GetIsNew(CodeGenerationMethodInfo info)
 {
     return info != null && info._isNew;
 }
コード例 #23
0
 private static IList<SyntaxNode> GetStatements(CodeGenerationMethodInfo info)
 {
     return info == null
         ? SpecializedCollections.EmptyList<SyntaxNode>()
         : info._statements;
 }
コード例 #24
0
 private static IList <SyntaxNode> GetStatements(CodeGenerationMethodInfo info)
 {
     return(info == null
         ? SpecializedCollections.EmptyList <SyntaxNode>()
         : info.statements);
 }
コード例 #25
0
 private static bool GetIsUnsafe(CodeGenerationMethodInfo info)
 => info != null && info._isUnsafe;
コード例 #26
0
 private static IList <SyntaxNode> GetHandlesExpressions(CodeGenerationMethodInfo info)
 {
     return(info == null
         ? SpecializedCollections.EmptyList <SyntaxNode>()
         : info.handlesExpressions);
 }
コード例 #27
0
 private static bool GetIsPartial(CodeGenerationMethodInfo info)
 {
     return info != null && info._isPartial;
 }