첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ Controllers/TestController.cs

using Microsoft.AspNetCore.Mvc;

namespace TestProject.Controllers
{
    /// <summary>
    /// 테스트 컨트롤러
    /// </summary>
    public class TestController : Controller
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 인덱스 페이지 처리하기 - Index()

        /// <summary>
        /// 인덱스 페이지 처리하기
        /// </summary>
        /// <returns>액션 결과</returns>
        public IActionResult Index()
        {
            return View();
        }

        #endregion
        #region 데이터 변환 페이지 처리하기 - ConvertData()

        /// <summary>
        /// 데이터 변환 페이지 처리하기
        /// </summary>
        /// <returns>액션 결과</returns>
        public IActionResult ConvertData()
        {
            return View();
        }

        #endregion
    }
}

 

728x90

 

▶ Views/Test/ConvertData.cshtml

@{ Layout = null; }
<p>데이터 변환 페이지</p>
<hr />

 

300x250

 

▶ CustomOutboundParameterTransformer.cs

using Microsoft.AspNetCore.Routing;
using System;
using System.Text.RegularExpressions;

namespace TestProject
{
    /// <summary>
    /// 커스텀 아웃 바운드 매개 변수 변환자
    /// </summary>
    public class CustomOutboundParameterTransformer : IOutboundParameterTransformer
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 아웃 바운드 변환하기 - TransformOutbound(value)

        /// <summary>
        /// 아웃 바운드 변환하기
        /// </summary>
        /// <param name="value">값</param>
        /// <returns>변환 아웃 바운드</returns>
        public string TransformOutbound(object value)
        {
            if(value == null)
            {
                return null;
            }

            return Regex.Replace
            (
                value.ToString(), 
                "([a-z])([A-Z])",
                "$1_$2",
                RegexOptions.CultureInvariant,
                TimeSpan.FromMilliseconds(100)
            ).ToLowerInvariant();
        }

        #endregion
    }
}

 

▶ Startup.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace TestProject
{
    /// <summary>
    /// 시작
    /// </summary>
    public class Startup
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 구성 - Configuration

        /// <summary>
        /// 구성
        /// </summary>
        public IConfiguration Configuration { get; }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - Startup(configuration)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="configuration">구성</param>
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 서비스 컬렉션 구성하기 - ConfigureServices(services)

        /// <summary>
        /// 서비스 컬렉션 구성하기
        /// </summary>
        /// <param name="services">서비스 컬렉션</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            services.AddRouting
            (
                options =>
                {
                    options.ConstraintMap["custom"] = typeof(CustomOutboundParameterTransformer);
                }
            );
        }

        #endregion
        #region 구성하기 - Configure(app, environment)

        /// <summary>
        /// 구성하기
        /// </summary>
        /// <param name="app">애플리케이션 빌더</param>
        /// <param name="environment">웹 호스트 환경</param>
        public void Configure(IApplicationBuilder app, IWebHostEnvironment environment)
        {
            if(environment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");

                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints
            (
                endpoints =>
                {
                    endpoints.MapControllerRoute
                    (
                        name    : "default",
                        pattern : "{controller:custom=Home}/{action:custom=Index}/{id?}"
                    );
                }
            );
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요