Creating a search and callback system in Unity — part 2, Use Linq to search through cases.
What’s nice about C# is that it has a built in set of search tools called Linq we can take advantage of to help us search for a specific case in our bucket. We’ll add the namespace to our AWSManager.
We’ll then use a built in function of link to see if a match has been found:
responseObject.Response.S3Objects will return a list of objects, we want to know if any object has what we’re looking for so we include .Any(), which will iterate through the objects and return any of the type, but we’ll pass in a fun or function that returns a boolean (true or false), so we’ll use a variable of obj and pass it through a lambda that compares obj.Key to target, basically comparing all values in the s3Objects bucket to what we’re searching for, if something is found, it will be stored in the caseFound boolean.
So given that, we’ll just give a message whether the case was found or not for now.
So testing it out, we know that our current case numbers are: 221, 515, 699, and 873. Let’s search for one of them.
Looks like it found 221
And it found 699 too!
Looks like any random number won’t be found!
We’re ready to download to download an object and reconstruct it!