Generic version for ObjectContainer.NamedList(String listName)

1 posts, 0 answers
  1. gmendez
    gmendez avatar
    82 posts
    Member since:
    Jun 2012

    Posted 08 Aug 2009 Link to this post

    Requirements

    .NET version

    3.0

    programming language

    C#

    PROJECT DESCRIPTION

    This is a very simple alternative implemented as a c# extension method.
    Note that the namespace is Telerik.OpenAccess so every place you use this namespace you'll see the extension method.
    Really simple. You just need to reference this class. Enjoy!

    using System;
    using System.Collections.Generic;
    using System.Collections;


    namespace Telerik.OpenAccess
    {
        public static class OpenAccessExtensions
        {

            #region ObjectContainer

            /// <summary>
            /// Generic version for ObjectContainer.NamedList(String listName)
            /// </summary>
            public static IList<T> NamedList<T>(this ObjectContainer container, String listName)
            {
                IList<T> result = null;

                IList originalList = container.NamedList(listName);
                if (originalList != null)
                {
                    result = new List<T>();
                    foreach (T value in originalList)
                        result.Add(value);
                }
                return result;
            }

            #endregion
        }
    }














Back to Top