How to set the Amazon.S3.Model.Filter.FilterRules List

Asked 2 years ago, Updated 2 years ago, 101 views

Regarding the addition of the List class, what should I do if I use the program below?
Please let me know.

using Amazon.S3.Model;
Filter filter = new Filter();
filter.S3KeyFilter.FilterRules.Add(newFilterRule("hoge", "1"));

Error Contents

NullReferenceException:Object reference not set to an instance of an object

c# aws-sdk

2022-09-30 15:45

1 Answers

You must create an instance of a S3KeyFilter or FilterRules class.

https://dotnetfiddle.net/5qxU0n

using Amazon.S3.Model;
using System.Collections.General;
using System;
usingServiceStack.Text;
          
public class program
{
  public static void Main()
  {
    Filter filter = new Filter {
      S3KeyFilter = new S3KeyFilter {
        FilterRules = new List <FilterRule > {
          new FilterRule("hoge", "1")
        }
      }
    };

    filter.S3KeyFilter.FilterRules.Add(newFilterRule("fuga", "2"));
    Console.WriteLine(filter.S3KeyFilter.FilterRules.Dump());
  }
}


2022-09-30 15:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.