Last active
December 26, 2019 05:46
-
-
Save bessgeor/9e2bb46d078d38895038a3a402805235 to your computer and use it in GitHub Desktop.
C# HList example
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
using System; | |
using System.Linq.Expressions; | |
using ZeroORM.SqlBuilder.Vendor; | |
namespace ZeroORM.SqlBuilder | |
{ | |
public static class NpgsqlExtension | |
{ | |
/// <summary> | |
/// Single vendor in list overload | |
/// </summary> | |
public static TResult Npgsql<TExprBuilder, TResult> | |
( | |
this IVendorBuilder<TExprBuilder, Npgsql, UnknownReturnType> builder, | |
Expression<Func<INpgsqlExpressionBuilder<TExprBuilder>, TResult>> vendorExpression | |
) | |
where TExprBuilder : ISqlExpressionBuilder | |
=> builder.Move( vendorExpression ); | |
/// <summary> | |
/// Multiple vendors in list overload, case when current is the first | |
/// </summary> | |
public static IVendorBuilder<TExprBuilder, TNextVendor, TResult> Npgsql<TExprBuilder, TNextVendor, TResult> | |
( | |
this IVendorBuilder<TExprBuilder, HLI<Npgsql, TNextVendor>, UnknownReturnType> builder, | |
Expression<Func<INpgsqlExpressionBuilder<TExprBuilder>, TResult>> vendorExpression | |
) | |
where TExprBuilder : ISqlExpressionBuilder | |
where TNextVendor : IZeroORMVendor | |
=> builder.Move( vendorExpression ); | |
/// <summary> | |
/// Multiple vendors in list overload, case when current is neither first nor last | |
/// </summary> | |
public static IVendorBuilder<TExprBuilder, TNextVendor, TResult> Npgsql<TExprBuilder, TNextVendor, TResult> | |
( | |
this IVendorBuilder<TExprBuilder, HLI<Npgsql, TNextVendor>, TResult> builder, | |
Expression<Func<INpgsqlExpressionBuilder<TExprBuilder>, TResult>> vendorExpression | |
) | |
where TExprBuilder : ISqlExpressionBuilder | |
where TNextVendor : IZeroORMVendor | |
=> builder.Move( vendorExpression ); | |
/// <summary> | |
/// Multiple vendors in list overload, case when current is the last | |
/// </summary> | |
public static TResult Npgsql<TExprBuilder, TResult> | |
( | |
this IVendorBuilder<TExprBuilder, HLI<Npgsql, VendorsHListEnd>, TResult> builder, | |
Expression<Func<INpgsqlExpressionBuilder<TExprBuilder>, TResult>> vendorExpression | |
) | |
where TExprBuilder : ISqlExpressionBuilder | |
=> builder.Move( vendorExpression ); | |
} | |
} |
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
using System; | |
using System.Linq.Expressions; | |
using ZeroORM.SqlBuilder.Vendor; | |
namespace ZeroORM.SqlBuilder | |
{ | |
public static class TSqlExtension | |
{ | |
/// <summary> | |
/// Single vendor in list overload | |
/// </summary> | |
public static TResult TSql<TExprBuilder, TResult> | |
( | |
this IVendorBuilder<TExprBuilder, SqlServer, UnknownReturnType> builder, | |
Expression<Func<ISqlServerExpressionBuilder<TExprBuilder>, TResult>> vendorExpression | |
) | |
where TExprBuilder : ISqlExpressionBuilder | |
=> builder.Move( vendorExpression ); | |
/// <summary> | |
/// Multiple vendors in list overload, case when current is the first | |
/// </summary> | |
public static IVendorBuilder<TExprBuilder, TNextVendor, TResult> TSql<TExprBuilder, TNextVendor, TResult> | |
( | |
this IVendorBuilder<TExprBuilder, HLI<SqlServer, TNextVendor>, UnknownReturnType> builder, | |
Expression<Func<ISqlServerExpressionBuilder<TExprBuilder>, TResult>> vendorExpression | |
) | |
where TExprBuilder : ISqlExpressionBuilder | |
where TNextVendor : IZeroORMVendor | |
=> builder.Move( vendorExpression ); | |
/// <summary> | |
/// Multiple vendors in list overload, case when current is neither first nor last | |
/// </summary> | |
public static IVendorBuilder<TExprBuilder, TNextVendor, TResult> TSql<TExprBuilder, TNextVendor, TResult> | |
( | |
this IVendorBuilder<TExprBuilder, HLI<SqlServer, TNextVendor>, TResult> builder, | |
Expression<Func<ISqlServerExpressionBuilder<TExprBuilder>, TResult>> vendorExpression | |
) | |
where TExprBuilder : ISqlExpressionBuilder | |
where TNextVendor : IZeroORMVendor | |
=> builder.Move( vendorExpression ); | |
/// <summary> | |
/// Multiple vendors in list overload, case when current is the last | |
/// </summary> | |
public static TResult TSql<TExprBuilder, TResult> | |
( | |
this IVendorBuilder<TExprBuilder, HLI<SqlServer, VendorsHListEnd>, TResult> builder, | |
Expression<Func<ISqlServerExpressionBuilder<TExprBuilder>, TResult>> vendorExpression | |
) | |
where TExprBuilder : ISqlExpressionBuilder | |
=> builder.Move( vendorExpression ); | |
} | |
} |
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 ZeroORM.SqlBuilder.Vendor | |
{ | |
public interface IVendorBuilder<TBuilder, TCurrent, TResult> | |
where TCurrent : IZeroORMVendor | |
{ | |
} | |
} |
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
using System; | |
using System.Linq.Expressions; | |
namespace ZeroORM.SqlBuilder.Vendor | |
{ | |
public static class IVendorBuilderExtensions | |
{ | |
/// <summary> | |
/// Single vendor in list overload | |
/// </summary> | |
public static TResult Move | |
< | |
TBuilder, | |
TSingleVendor, | |
TFirstVendorBuilder, | |
TResult | |
> | |
( | |
this IVendorBuilder<TBuilder, TSingleVendor, UnknownReturnType> _, | |
Expression<Func<TFirstVendorBuilder, TResult>> vendorExpression | |
) | |
where TSingleVendor : IZeroORMVendor | |
where TFirstVendorBuilder : IConcreteVendorBuilder<TBuilder, TSingleVendor> | |
=> default; | |
/// <summary> | |
/// Multiple vendors in list overload, case when current is the first | |
/// </summary> | |
public static IVendorBuilder<TBuilder, TNextVendor, TResult> Move | |
< | |
TBuilder, | |
TCurrentVendor, | |
TNextVendor, | |
TCurrentVendorBuilder, | |
TResult | |
> | |
( | |
this IVendorBuilder<TBuilder, HLI<TCurrentVendor, TNextVendor>, UnknownReturnType> _, | |
Expression<Func<TCurrentVendorBuilder, TResult>> vendorExpression | |
) | |
where TCurrentVendor : IZeroORMVendor | |
where TNextVendor : IZeroORMVendor | |
where TCurrentVendorBuilder : IConcreteVendorBuilder<TBuilder, TCurrentVendor> | |
=> default; | |
/// <summary> | |
/// Multiple vendors in list overload, case when current is neither first nor last | |
/// </summary> | |
public static IVendorBuilder<TBuilder, TNextVendor, TResult> Move | |
< | |
TBuilder, | |
TCurrentVendor, | |
TNextVendor, | |
TCurrentVendorBuilder, | |
TResult | |
> | |
( | |
this IVendorBuilder<TBuilder, HLI<TCurrentVendor, TNextVendor>, TResult> _, | |
Expression<Func<TCurrentVendorBuilder, TResult>> vendorExpression | |
) | |
where TCurrentVendor : IZeroORMVendor | |
where TNextVendor : IZeroORMVendor | |
where TCurrentVendorBuilder : IConcreteVendorBuilder<TBuilder, TCurrentVendor> | |
=> default; | |
/// <summary> | |
/// Multiple vendors in list overload, case when current is the last | |
/// </summary> | |
public static TResult Move | |
< | |
TBuilder, | |
TCurrentVendor, | |
TCurrentVendorBuilder, | |
TResult | |
> | |
( | |
this IVendorBuilder<TBuilder, HLI<TCurrentVendor, VendorsHListEnd>, TResult> _, | |
Expression<Func<TCurrentVendorBuilder, TResult>> vendorExpression | |
) | |
where TCurrentVendor : IZeroORMVendor | |
where TCurrentVendorBuilder : IConcreteVendorBuilder<TBuilder, TCurrentVendor> | |
=> default; | |
} | |
} |
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 ZeroORM.SqlBuilder | |
{ | |
public interface IZeroORMVendorList | |
{ | |
} | |
public interface IZeroORMVendorList<TProvider1> : IZeroORMVendorList | |
where TProvider1 : IZeroORMVendor | |
{ | |
} | |
public class VendorsHListEnd : IZeroORMVendor | |
{ | |
} | |
/// <summary> | |
/// Stands for Heterogeneous List Item. Long name for such a thing reduces readability significially, so it is abbreviated. | |
/// </summary> | |
public class HLI<T1, T2> : IZeroORMVendor | |
where T1 : IZeroORMVendor | |
where T2 : IZeroORMVendor | |
{ | |
} | |
} |
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
using System; | |
using ZeroORM.SqlBuilder.Vendor; | |
namespace ZeroORM.SqlBuilder | |
{ | |
public class Npgsql : IZeroORMVendor { } | |
public interface INpgsqlExpressionBuilder<TExprBuilder> : IConcreteVendorBuilder<TExprBuilder, Npgsql> | |
where TExprBuilder : ISqlExpressionBuilder | |
{ | |
DateTime CurrentTimestamp { get; } | |
} | |
} |
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
using System; | |
using ZeroORM.SqlBuilder.Vendor; | |
namespace ZeroORM.SqlBuilder | |
{ | |
public class SqlServer : IZeroORMVendor | |
{ | |
} | |
public interface ISqlServerExpressionBuilder<TExprBuilder> : IConcreteVendorBuilder<TExprBuilder, SqlServer> | |
where TExprBuilder : ISqlExpressionBuilder | |
{ | |
DateTime GetDate(); | |
} | |
} |
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
DateTime x = db | |
.Vendor() | |
.Npgsql( npg => npg.CurrentTimestamp ) | |
.TSql( tsql => tsql.GetDate() ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment