C# .NET客户端中Google工作表中的条件格式请求

C# .NET客户端中Google工作表中的条件格式请求,c#,google-sheets-api,google-api-dotnet-client,gs-conditional-formatting,C#,Google Sheets Api,Google Api Dotnet Client,Gs Conditional Formatting,我知道如何在GoogleSheetsAPI中对值和其他格式进行批处理电子表格更新请求,但条件格式似乎有所不同。我已正确设置请求: AddConditionalFormatRuleRequest formatRequest = new AddConditionalFormatRuleRequest { Rule = new ConditionalFormatRule { Ranges = new List<GridRange> {

我知道如何在GoogleSheetsAPI中对值和其他格式进行批处理电子表格更新请求,但条件格式似乎有所不同。我已正确设置请求:

AddConditionalFormatRuleRequest formatRequest = new AddConditionalFormatRuleRequest
{
    Rule = new ConditionalFormatRule
    {
        Ranges = new List<GridRange>
        {
            new GridRange
            {
                // omitted
            }
        },
        BooleanRule = new BooleanRule
        {
            Condition = new BooleanCondition
            {
                // omitted
            },
            Format = new CellFormat
            {
                // omitted
            }
        },
    },
};
formatRequests.Add(formatRequest);
此部分不起作用,因为
BatchUpdateSpreadSheetRequest.Requests
的类型为
IList
,但
AddConditionalFormatureRequest
不会从
请求继承。它只实现了
IDirectResponseActionSchema
(参见第2254行),那么实际如何执行这些请求呢

因此,我应该使用其他的对象/方法来实现这一点,但它在哪里


提前感谢。

来自.NET背景,我真的很难理解如何使用Google API。(对我来说)事情组织得很奇怪,.NET组件的文档看起来一点也不像MSDN,所以我觉得很难。不管怎样,我知道了。您不能单独使用
addConditionalFormatureRequest
类。您必须将其包装在常规的
请求
对象中

Request formatRequest = new Request
{
    AddConditionalFormatRule = new AddConditionalFormatRuleRequest
    {
        // etc
    }
};
Request formatRequest = new Request
{
    AddConditionalFormatRule = new AddConditionalFormatRuleRequest
    {
        // etc
    }
};