Example #1
0
        protected MethodSymbol(IMethodSymbol sourceSymbol, AbstractPhaseContext context)
            : base(sourceSymbol, context)
        {
            if (sourceSymbol != null)
            {
                ContainingType = context.GetTypeSymbol(sourceSymbol.ContainingType);
                IsConstructor  = sourceSymbol.MethodKind == MethodKind.Constructor;

                ITypeSymbol returnType = sourceSymbol.ReturnType;

                if (returnType != context.GetTypeSymbol(SpecialType.System_Void).RoslynSymbol)
                {
                    ReturnType = context.GetTypeSymbol(returnType);
                }
                else if (IsConstructor)
                {
                    ReturnType = context.GetTypeSymbol(sourceSymbol.ContainingType);
                }

                if (sourceSymbol.Parameters != null)
                {
                    List <ParameterSymbol> parameterSymbols = new List <ParameterSymbol>();

                    foreach (IParameterSymbol parameterSymbol in sourceSymbol.Parameters)
                    {
                        ParameterSymbol newSymbol = (ParameterSymbol)context.GetSymbol(parameterSymbol);

                        parameterSymbols.Add(newSymbol);
                    }

                    Parameters = ImmutableArray.CreateRange <ParameterSymbol>(parameterSymbols);
                }
                else
                {
                    Parameters = ImmutableArray <ParameterSymbol> .Empty;
                }

                if (!IsGenericMethod && RoslynSymbol != RoslynSymbol.OriginalDefinition)
                {
                    TypeArguments = sourceSymbol.TypeArguments.Length > 0 ? sourceSymbol.TypeArguments.Select(context.GetTypeSymbol).ToImmutableArray() : ImmutableArray <TypeSymbol> .Empty;
                }
                else
                {
                    TypeArguments = sourceSymbol.TypeArguments.Length > 0 ? sourceSymbol.TypeArguments.Select(context.GetTypeSymbolWithoutRedirect).ToImmutableArray() : ImmutableArray <TypeSymbol> .Empty;
                }

                if (RoslynSymbol.IsOverride && RoslynSymbol.OverriddenMethod != null) // abstract methods can be overrides, but not have overriden methods
                {
                    OverridenMethod = (MethodSymbol)context.GetSymbol(RoslynSymbol.OverriddenMethod);
                }

                IsOperator = RoslynSymbol.MethodKind == MethodKind.BuiltinOperator ||
                             RoslynSymbol.MethodKind == MethodKind.UserDefinedOperator;

                if (RoslynSymbol.OriginalDefinition != RoslynSymbol)
                {
                    OriginalSymbol = context.GetSymbolNoRedirect(RoslynSymbol.OriginalDefinition);
                }
            }
        }