Example #1
0
File: View.cs Project: slagusev/api
        /// <summary>
        /// Gets the listener recorded for the given owner with the given (unique) resource id.
        /// A listener is created if not found and create it set to true.
        /// </summary>
        /// <remarks>This method is not thread safe.</remarks>
        internal static T GetOrCreate <T>(this View view, int resourceId, bool create, Action <T> initialize)
            where T : class, new()
        {
            var listener = (T)view.GetTag(resourceId);

            if ((listener == null) && create)
            {
                listener = new T();
                view.SetTag(resourceId, listener);
                if (initialize != null)
                {
                    initialize(listener);
                }
            }
            return(listener);
        }