开发者

how can I access an attribute by name, rather than by integer?

开发者 https://www.devze.com 2023-04-10 23:51 出处:网络
I must be missing something, but I can\'t seem to figure out how to get an Attribute by Name/String, only by an Integer, which is likely to change(the Attribute Name is not).

I must be missing something, but I can't seem to figure out how to get an Attribute by Name/String, only by an Integer, which is likely to change (the Attribute Name is not).

Could you explain how I get Attributes by name/string? The string "active" attempt produces this error:

Error   82  The best overloaded method match for 'System.Collections.Generic.List<Amazon.SimpleDB.Model.Attribute>.this[int]' has some invalid argumens

Thank you!

Hairgami

using (sdb = AWSClientFactory.CreateAmazonSimpleDBClient(accessKeyID, secretAccessKeyID))
        {
                String selectExpression = string.Format("select * from apps where appid = '{0}'", appID);
                SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression);
                SelectResponse selectResponse = sdb.Select(selectRequestAction)开发者_运维问答;

                if (selectResponse.IsSetSelectResult())
                {
                    SelectResult selectResult = selectResponse.SelectResult;
                    foreach (Item item in selectResult.Item)
                    {
                        //Works fine
                        Amazon.SimpleDB.Model.Attribute id = item.Attribute[1];

                        //How can I do this:
                        Amazon.SimpleDB.Model.Attribute id = item.Attribute["active"];

                    }
                }
                else
                {

                }
            }


You're trying to access a System.Collections.Generic.List<T> like it's an associative array, which it's not. The Enumerable.FirstOrDefault method could be used to achieve something similar:

Amazon.SimpleDB.Model.Attribute id = 
   item.Attribute.FirstOrDefault(attr => attr.Name == "active");
0

精彩评论

暂无评论...
验证码 换一张
取 消