Exemple #1
0
        /// <summary>
        /// Gets the <typeparamref name="TModel"/> corresponding to a <paramref name="view"/> using this <paramref name="representer"/>
        /// or the default (<c>null</c>) if the <paramref name="view"/> is <c>null</c>.
        /// </summary>
        /// <param name="representer">The representer which will be used to convert this <paramref name="view"/> into the <typeparamref name="TModel"/>.</param>
        /// <param name="view">The view which should be converted into a <typeparamref name="TModel"/>.</param>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <typeparam name="TView">The type of the view.</typeparam>
        /// <returns>The <typeparamref name="TModel"/> which represents the <paramref name="view"/> or <c>null</c> if the view is <c>null</c>.</returns>
        public static TModel ToModelOrDefault <TModel, TView>(this IRepresenter <TModel, TView> representer, TView view)
            where TView : class, IView <TModel>
            where TModel : class
        {
            if (representer is null)
            {
                throw new System.ArgumentNullException(nameof(representer));
            }

            if (view is null)
            {
                return(default(TModel));
            }

            return(representer.ToModel(view));
        }
Exemple #2
0
        public static TModel?ToModelOrDefault <TView, TModel>(this IRepresenter <TModel, TView> representer, TView?view)
            where TModel : class
            where TView : class, IView <TModel>
        {
            if (representer is null)
            {
                throw new ArgumentNullException(nameof(representer));
            }

            if (view is null)
            {
                return(null);
            }

            return(representer.ToModel(view));
        }