.NET
-
[.NET 8.0] C# 12 새로운 기능 정리.NET 2023. 11. 16. 01:45
2023년 11월 15일 .NET 8.0 이 정식 릴리즈 되었다. 그와 함께 C# 언어 버전도 12로 올라오게 되었는데, 어떤 점이 생겼는지 정리해보았다. 1.기본생성자(Primary Constructors) 지금까진 class 에서 생성자 함수를 선언할 때 아래와 같이 생성한다. public class AsIs { private string name; public AsIs(string name) { // 생성자 함수 this.name = name; } public void PrintName() { Console.WriteLine(name); } } C# 12부터는 record 형식과 마찬가지로 별도 생성자함수 없이 클래스 옆에 바로 선언이 가능하다. public class Tobe(string name..
-
[ADO.NET] 프로시저 호출 시 the Size property has an invalid size of 0 오류 일어날 때 확인 사항.NET/개념 및 유용한 팁 2023. 4. 20. 22:42
1. 오류원인 SqlCommand 사용시 SqlParameter 가 Varchar와 같이 사이즈가 지정된 유형을 OUTPUT으로 받는 파라메터라면 Size를 필수적으로 설정해야한다. 그러지 않을 경우 the Size property has an invalid size of 0 오류가 발생할 수 있다. 2. 재현 아래와 같은 테이블과 프로시저 있다고 가정하자. -- 테이블 CREATE TABLE ApplicationDB.dbo.Student ( StudentId INT NOT NULL PRIMARY KEY, -- primary key column "Name" [NVARCHAR](50) NOT NULL, "Id" [NVARCHAR](50) NOT NULL -- specify more columns here ..
-
[ASP.NET Core] AddSingleton(), AddScoped(), AddTransient() 차이점 - 2.NET/ASP.NET Core 2023. 3. 15. 21:47
해당 포스트 작성하기 약 2년 전, ASP.NET Core 에서 3가지 생명주기에 대해 정리한 적이 있었다. [ASP.NET Core] AddSingleton(), AddScoped(), AddTransient() 차이점 - 1 :: 또치의 삽질 보관함 (tistory.com) [ASP.NET Core] AddSingleton(), AddScoped(), AddTransient() 차이점 - 1 ASP.NET Core에서 의존성 주입에 의해 추가되는 Service는 크게 3가지 생명주기를 지닌다. AddSingleton AddScoped AddTransient AddSingleton의 경우는 클라이언트(보통 웹브라우저)의 접속상태에 관계없이, 웹 서 ddochea.tistory.com 지난시간에 Scop..
-
[.NET] The last access/last write time on file 빌드오류.NET/개념 및 유용한 팁 2023. 3. 12. 17:17
아래와 같은 오류가 발생했다. The last access/last write time on file "obj/Debug/net6.0/example-producer.MvcApplicationPartsAssemblyInfo.cache" cannot be set. Access to the path '/workspaces/example-producer/obj/Debug/net6.0/example-producer.MvcApplicationPartsAssemblyInfo.cache' is denied. [/workspaces/example-producer/example-producer.csproj] 해결은 obj 폴더를 제거하고 다시 빌드하면 된다.
-
[ASP.NET Core] WebApi with Swagger - 5. enum.NET/ASP.NET Core 2023. 2. 18. 13:26
아래와 같은 Controller 소스가 있다. using Microsoft.AspNetCore.Mvc; namespace swagger_5_enum.Controllers; [ApiController] [Route("[controller]")] public class WeatherForecastController : ControllerBase { private static readonly string[] Summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; private readonly ILogger _logger; public WeatherF..
-
[ASP.NET Core] WebApi with Swagger - 4. DataAnnotations을 통한 유효성 검사(Vaildation) 응답.NET/ASP.NET Core 2023. 2. 16. 23:13
System.ComponentModel.DataAnnotations 네임스페이스에 속한 특성(Attribute)를 통해 요청값에 대한 유효성 처리를 적용할 수 있다. /// /// 입력된 일수만큼 날씨 데이터를 제공합니다. /// /// 입력일수 /// [HttpGet("{cnt}", Name = "GetWeatherForecastByCount")] public IEnumerable Get( [Required][Range(1, 10)] int cnt) { // 이제 cnt 값은 1~10 사이의 값이 필수적으로 들어와야 한다. return Enumerable.Range(1, cnt).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(ind..
-
[ASP.NET Core] WebApi with Swagger - 3. 응답 명세(ProducesResponseType).NET/ASP.NET Core 2023. 2. 15. 23:27
항상 올바른 요청(Request)에 올바른 응답(Response)값만 줄 수 있는 상황이라면 좋겠지만, 요청이 거지같거나(?) 올바른 요청이지만 이를 제대로 제공할 데이터가 없는 경우가 종종 있다. ProducesResponseType는 이와 같이 응답상태에 따라 타입을 지정하여 안내할 수 있는 방법을 제공한다. 아래 소스코드는 데이터가 없을 땐 string 형식으로, 데이터가 있을땐 WeatherForecast 배열형식으로 이원화하여 응답할 수 있음을 안내하는 예제이다. /// /// 오늘 ~ 입력한 날짜 하루전에 해당하는 날씨 데이터를 제공합니다. /// /// 입력날짜 /// [HttpGet("datetime", Name = "GetWeatherForecastByDateTime")] [Produce..
-
[ASP.NET Core] WebApi with Swagger - 2. 예제(example) 적용.NET/ASP.NET Core 2023. 2. 14. 22:40
Swagger 문서내 요청에서 파라메터에 어떤 값이 들어가야하는지, 또는 어떤 값이 나올지 주석을 이용해 제한적으로나마 예제(example)을 적용할 수 있다. 1. 숫자 /// /// 입력된 일수만큼 날씨 데이터를 제공합니다. /// /// 입력일수 // 숫자형 예제 /// [HttpGet("{cnt}", Name = "GetWeatherForecastByCount")] public IEnumerable Get(int cnt) { return Enumerable.Range(1, cnt).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), TemperatureC = Random.Shared.Next(-20, 55), Summ..