コード例 #1
0
        public static SourceParameterSymbol Create(
            Binder context,
            Symbol owner,
            TypeWithAnnotations parameterType,
            ParameterSyntax syntax,
            RefKind refKind,
            SyntaxToken identifier,
            int ordinal,
            bool isParams,
            bool isExtensionMethodThis,
            bool addRefReadOnlyModifier,
            DiagnosticBag declarationDiagnostics)
        {
            Debug.Assert(!(owner is LambdaSymbol)); // therefore we don't need to deal with discard parameters

            var name      = identifier.ValueText;
            var locations = ImmutableArray.Create <Location>(new SourceLocation(identifier));

            if (isParams)
            {
                // touch the constructor in order to generate proper use-site diagnostics
                Binder.ReportUseSiteDiagnosticForSynthesizedAttribute(context.Compilation,
                                                                      WellKnownMember.System_ParamArrayAttribute__ctor,
                                                                      declarationDiagnostics,
                                                                      identifier.Parent.GetLocation());
            }

            ImmutableArray <CustomModifier> inModifiers = ParameterHelpers.ConditionallyCreateInModifiers(refKind, addRefReadOnlyModifier, context, declarationDiagnostics, syntax);

            if (!inModifiers.IsDefaultOrEmpty)
            {
                return(new SourceComplexParameterSymbolWithCustomModifiersPrecedingByRef(
                           owner,
                           ordinal,
                           parameterType,
                           refKind,
                           inModifiers,
                           name,
                           locations,
                           syntax.GetReference(),
                           isParams,
                           isExtensionMethodThis));
            }

            if (!isParams &&
                !isExtensionMethodThis &&
                (syntax.Default == null) &&
                (syntax.AttributeLists.Count == 0) &&
                !owner.IsPartialMethod())
            {
                return(new SourceSimpleParameterSymbol(owner, parameterType, ordinal, refKind, name, isDiscard: false, locations));
            }

            return(new SourceComplexParameterSymbol(
                       owner,
                       ordinal,
                       parameterType,
                       refKind,
                       name,
                       locations,
                       syntax.GetReference(),
                       isParams,
                       isExtensionMethodThis));
        }