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

            if (model is null)
            {
                return(default(TView));
            }

            return(representer.ToView(model));
        }
示例#2
0
        public static TView?ToViewOrDefault <TView, TModel>(this IRepresenter <TModel, TView> representer, TModel?model)
            where TModel : class
            where TView : class, IView <TModel>
        {
            if (representer is null)
            {
                throw new ArgumentNullException(nameof(representer));
            }

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

            return(representer.ToView(model));
        }