コード例 #1
0
    public static void Load(this IMethodModel @this, ICodeTextWriter writer, SourceBuilder builder, IMethodSymbol method, ScopeInfo scope, IEnumerable <IMemberInfo> references)
    {
        var methodScope = new ScopeInfo(scope);

        if (method.IsGenericMethod)
        {
            methodScope.CreateAliases(method.TypeArguments);
        }

        (bool isAsync, bool methodReturnsValue) = SemanticFacts.IsAsyncAndGetReturnType(writer.Compilation, method);
        bool canUseAsync = true;

        {
            SourceBuilder builder2 = builder.AppendNewBuilder(false);
            writer.WriteIdentifier(builder2, method);
            if (method.IsGenericMethod)
            {
                builder2.Append('<');
                writer.WriteTypeArgumentsCall(builder2, method.TypeArguments, methodScope);
                builder2.Append('>');
            }
            @this.Name = builder2.ToString();
        }

        {
            SourceBuilder builder2 = builder.AppendNewBuilder(false);
            writer.WriteTypeReference(builder2, method.ReturnType, methodScope);
            @this.ReturnType = builder2.ToString();
        }

        {
            SourceBuilder builder2 = builder.AppendNewBuilder(false);
            writer.WriteParameterDefinition(builder2, methodScope, method.Parameters);
            @this.ArgumentsDefinition = builder2.ToString();
        }

        {
            SourceBuilder builder2 = builder.AppendNewBuilder(false);
            writer.WriteCallParameters(builder2, method.Parameters);
            @this.CallArguments = builder2.ToString();
        }

        @this.IsAsync        = isAsync && canUseAsync;
        @this.ReturnExpected = (isAsync && methodReturnsValue == false) ? canUseAsync == false : methodReturnsValue;

        foreach (IMemberInfo reference in references)
        {
            SourceBuilder builder2 = builder.AppendNewBuilder(false);
            if (isAsync && canUseAsync)
            {
                writer.WriteMethodCall(builder2, reference, method, methodScope, false, false, false);
            }
            else
            {
                writer.WriteMethodCall(builder2, reference, method, methodScope, false, SemanticFacts.IsNullable(writer.Compilation, method.ReturnType), reference.PreferCoalesce);
            }
            @this.Expressions.Add(builder2.ToString());
        }
    }
コード例 #2
0
    public static void Load(this IIndexerModel @this, ICodeTextWriter writer, SourceBuilder builder, IPropertySymbol indexer, ScopeInfo scope, IEnumerable <IMemberInfo> references)
    {
        (@this as IPropertyModel).Load(writer, builder, indexer, scope, references);

        {
            SourceBuilder builder2 = builder.AppendNewBuilder(false);
            writer.WriteParameterDefinition(builder2, scope, indexer.Parameters);
            @this.ParametersDefinition = builder2.ToString();
        }

        {
            SourceBuilder builder2 = builder.AppendNewBuilder(false);
            writer.WriteCallParameters(builder2, indexer.Parameters);
            @this.CallParameters = builder2.ToString();
        }
    }