开发者

Is there an equivalent for ActiveRecord#find_by equivalent for C#?

I'm originally a C# developer (as a hobby), but as of late I have been digging into Ruby on Rails and really enjoying it. Right now I am building an application in C#, and I was wondering if there is any collection implementation for C# that could match (or "semi-match") the find_by method of ActiveRecord.

What I am essentially looking for is a list that would hold Rectangles:

class Rectangle
{
    public int Width { get; set; }
    public int Height { get; set; }
    public string Name { get; set; }
}

Where I could query this list and find all entries with Height = 10, Width = 20, or name = "Block". This was done with Act开发者_StackOverflowiveRecord by doing a call similar to Rectangle.find_by_name('Block'). The only way I can think of doing this in C# is to create my own list implementation and iterate through each item manually checking each item against the criteria. I fear I would be reinventing the wheel (and one of poorer quality).

I am not necessarily trying to match the naming convention find_by_..., but rather to have the functionality of the method.

Any input or suggestions is much appreciated.


The "Linq methods", namely Where, that were added in .NET 3.5 are pretty close to what you're looking for.

myCollection.Where(r => r.Name == 'Block')
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜