Skip to content

Instantly share code, notes, and snippets.

@mehmetalierol
Last active September 8, 2018 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehmetalierol/3d945d6e1487a37555d9f349b9ec6786 to your computer and use it in GitHub Desktop.
Save mehmetalierol/3d945d6e1487a37555d9f349b9ec6786 to your computer and use it in GitHub Desktop.
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