Exemple #1
0
        /// <summary>
        /// Gets or adds a new <see cref="CogitoControl"/> to the <see cref="ControlCollection"/>.
        /// </summary>
        /// <typeparam name="TControl"></typeparam>
        /// <param name="controls"></param>
        /// <returns></returns>
        public static TControl GetOrAdd <TControl>(this ControlCollection controls)
            where TControl : Control, new()
        {
            if (controls == null)
            {
                throw new ArgumentNullException(nameof(controls));
            }

            return(controls.GetOrAdd(() => new TControl()));
        }
Exemple #2
0
        /// <summary>
        /// Gets or adds a <see cref="Control"/> to the <see cref="ControlCollection"/>.
        /// </summary>
        /// <typeparam name="TControl"></typeparam>
        /// <param name="controls"></param>
        /// <param name="create"></param>
        /// <returns></returns>
        public static TControl GetOrAdd <TControl>(this ControlCollection controls, Func <TControl> create)
            where TControl : Control
        {
            if (controls == null)
            {
                throw new ArgumentNullException(nameof(controls));
            }
            if (create == null)
            {
                throw new ArgumentNullException(nameof(create));
            }

            return(controls.GetOrAdd <TControl>(_ => true, create));
        }