Link to home
Start Free TrialLog in
Avatar of escheider
escheider

asked on

Working with Generics -- IList<T>

Good evening experts:

My team is currently implementing an application that will manage a list of drugs.   To accomplish this task, we have implemented several data transfer objects to maintain these data.  One data transfer object, MyDrugList contains a single attribute of type List<DrugDetailDto> drug.   In this case, drug allows us to manage a list of drug objects .. add, remove, find, etc; however, upon submitting for code review, our enterprise architect pointed out a flaw in the development process and indicated we need not expose our List<T> objects:  ( http://msdn2.microsoft.com/en-us/library/ms182142(VS.80).aspx)

As an alternative, he suggested that we implement the IList interface to transfer objects between our layers.   I somewhat understand his requirement, but now some of our methods are not wanting to cooperate, which I've included below ..  

1) Could someone explain why this is an issue?
2) Could someone assist with how we can implement our search methods using these IList implementations?

We are using 2.0 Framework .. C#

Thanks,
Here is an example of where we search a DrugDetailDTO object for specific product data:
 
 /// <summary>//
        /// Extracts product information attached to a drug for a specified formulary
        /// </summary> 
        private DrugProductDTO GetProductDetail(DrugDetailDTO drug, string formularyID)
        {
            return drug.Products.Find(
                delegate(DrugProductDTO product)
                {
                    return product.ProductID.ToString().Equals(formularyID);
                }
                );
        }
 
AND
 
        /// <summary>
        /// Extracts Drugs information that has generics equivalents available
        /// </summary>
        private List<DrugDetailDTO> ExtractGenericsFromDrugList(List<DrugDetailDTO> myDrugList)
        {
            return myDrugList.FindAll(
                                      (
                                          delegate(DrugDetailDTO drug)
                                          {
                                              return drug.IsConvertibleToGenerics.Equals(true);
 
                                          }
                                      )
                                     );
 
 
        }
 
However, the find, findall, exists methods are not available with the IList interface.

Open in new window

Avatar of William Domenz
William Domenz
Flag of United States of America image

Have you looked at:
http://blogs.msdn.com/fxcop/archive/2006/04/27/585476.aspx
?

Let me know if this helps


BillyDvd
So, why don´t return a Collection<> instead as suggested in the MSDN site?
Collection have the IList interface also.
What the article suggest is not to use List<> generic class.
ASKER CERTIFIED SOLUTION
Avatar of cottsak
cottsak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
EDIT (comment#21861988): there is no LINQ code there... that factory gets users from the Membership provider. other classes in that project used LINQ. sorry to confuse.
Avatar of escheider
escheider

ASKER

I can't pass the List<T> from layer to layer as we are using a controller and facade in the presentation layer that accesses the business and data layer located in web services [via a proxy], so the list of drugs must be serialized and returned to the controller for processing [display, navigation, etc].   Unfortunately, this strategy wouldn't pass our code review standards if I returned the List<T>
escheider,

sorry man. i'm not full-bottle enuf on using all those patterns togetha to suggest a solution that will comply with ur strict coding standards. perhaps your architect should suggest the solution.. thats his job right?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for clearing things up for me ..  we have decided to implement the Collection object, as it will be beneficial for us to determine when an object is added to the collection.   Thanks for all your assistance.
no sweat. it was learning for me too. ;)