Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I've been writing a provider that uses generics to allow for xml serialization of simple classes for storage on low to medium use websites.

The system works great but when I used FXcop on my project I received the warning:"Properties should be used instead of Get/Set methods " on my method GetAllItems()

Now GetAllItems() returns a collection that acts as the only means to search for my generic type with my provider.

as follows.....

C#
XmlProvider<Person> xmlProvider = new XmlProvider<Person>(path);
var q = from item in xmlProvider.GetAllItems() where item.Name.Equals("James South") select item;
Person p = q.FirstOrDefault();


Is that acceptable practice or is there a better method? Am I missing something simple?

Many thanks?
Posted

I don't see anything wrong with this. FxCop does it's best but it isn't always correct based on your usage, it's just trying to get you to evaluate the design. I beleive it is being flagged because the Get in the name.

Of course you could also implement this with a property, which would be a better design for a framework or API

public IEnumerable Items{...}
 
Share this answer
 
If you're relying on FXCop to validate your code, you're in for a big let-down. It's only there to provide guidelines that you can choose to follow or ignore, depending on your own code.

If you wanted to avoid the warning, you could always retrieve the list outside your Linq statement, and use the retrieved list object instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900