Skip to content

Instantly share code, notes, and snippets.

@farukterzioglu
Last active July 3, 2017 11:12
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 farukterzioglu/3a4b6e5e4b0103f15af72a004c9bebcb to your computer and use it in GitHub Desktop.
Save farukterzioglu/3a4b6e5e4b0103f15af72a004c9bebcb to your computer and use it in GitHub Desktop.
using System;
using System.Runtime.CompilerServices;
using Xunit;
namespace Tests
{
public class Dto1{}
public class Dto2{}
public interface IDbModel
{
Dto1 Dto1 { get; }
Dto2 Dto2 { get; }
object Dto99 { get; }
}
public class DbModel : IDbModel
{
public Dto1 Dto1 => this.GetData<Dto1>();
public Dto2 Dto2 => this.GetData<Dto2>();
public object Dto99 => this.GetData();
}
public static class Extensions
{
public static T GetData<T>(this object type, [CallerMemberName] string callerMember = "") where T : class
{
return new Repo().Get<T>(callerMember);
}
public static object GetData(this object type, [CallerMemberName] string callerMember = "")
{
return new Repo().Get(callerMember);
}
}
public class Repo
{
public T Get<T>(string tableName) where T : class{
//TODO : Db codes
#region Db Simulation
if (tableName == "Dto1") return new Dto1() as T;
if (tableName == "Dto2") return new Dto2() as T;
#endregion
throw new NotSupportedException();
}
public object Get(string tableName){
//TODO : Db codes
#region DB simulation
if (tableName == "Dto1") return new Dto1();
if (tableName == "Dto2") return new Dto2();
if (tableName == "Dto99") return "testing value";
#endregion
throw new NotSupportedException();
}
}
public class Tests
{
[Fact]
public void Testing()
{
var dbModel = new DbModel();
Dto2 data1 = dbModel.Dto2;
Dto1 data2 = dbModel.Dto1;
object data3 = dbModel.Dto99;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment