Last active
September 8, 2018 20:04
-
-
Save mehmetalierol/3d945d6e1487a37555d9f349b9ec6786 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Company.Application.Common.Api | |
{ | |
#region ObjectResult | |
/// <summary> | |
/// Tipi çalışma anında belli olacak ya da kontrol etmek istemediğimiz standart tipler olacak ise bu nesne ile dönüşümüzü yapacağız. | |
/// Her bir standart ValueType için nesne oluşturmak yerine, object tipinde bir nesne oluşturup kutulama(boxing) yaparak dönüş yapacağız. | |
/// Kutulama valueType'ların referenceType lara dönüştürülmesidir. Sistem bunu otomatik olarak yapar. Bu nesne oluşturulduğun data propertisine atanacak tip sistem tarafından otomatik olarak explicit boxing işlemine tabi tutulacaktır. | |
/// </summary> | |
public class ApiResult | |
{ | |
public string Message { get; set; } | |
public int StatusCode { get; set; } | |
public object Data { get; set; } | |
} | |
#endregion | |
#region GenericResult | |
/// <summary> | |
/// Web Api projemizden geriye dönüşleri(response to requester) generic olarak handle edecek kodumuz. | |
/// Api result türünde geri döndürmek istediğimiz generic tipi message ve statusCode alanları ile birlikte istemciye dönüyoruz | |
/// Yukarıdaki object alanını bizim için serbest dönüşler yapacak ancak biz bu generic class'ı tanımlayarak method dönüşünde ne tip dönmesi gerektiğiniz bildirmiş olacağız. | |
/// Bu sayede hem kodumuza bir zorunluluk getirmiş hem de tasarım sırasında ortaya çıkacak yanlış tip dönme gibi sorunların önüne geçmiş olacağız. | |
/// </summary> | |
/// <typeparam name="T">Geri dönemesini istediğimiz tip</typeparam> | |
public class ApiResult<T> | |
{ | |
public string Message { get; set; } | |
public int StatusCode { get; set; } | |
public T Data { get; set; } | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment