Skip to content

Commit

Permalink
v2.2.1 (#28)
Browse files Browse the repository at this point in the history
* add SQLServer provider test

* issue #27 test using sqlserver provider

* Add ReflectionEmit package

* Create parameterized queries Fix #24

* update to v2.2.1
  • Loading branch information
alirezanet authored Sep 30, 2021
1 parent 185bf4c commit 179c5ab
Show file tree
Hide file tree
Showing 18 changed files with 483 additions and 69 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gridify (A Modern Dynamic LINQ library)

<img alt="GitHub" src="https://img.shields.io/github/license/alirezanet/gridify"> ![Nuget](https://img.shields.io/nuget/dt/gridify?color=%239100ff) ![Nuget](https://img.shields.io/nuget/v/gridify?label=stable) ![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/gridify?label=latest) ![GitHub branch checks state](https://img.shields.io/github/checks-status/alirezanet/gridify/master?label=tests) <img alt="Zero-Dependencies" src="https://img.shields.io/badge/Dependencies-0-orange">
<img alt="GitHub" src="https://img.shields.io/github/license/alirezanet/gridify"> ![Nuget](https://img.shields.io/nuget/dt/gridify?color=%239100ff) ![Nuget](https://img.shields.io/nuget/v/gridify?label=stable) ![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/gridify?label=latest) ![GitHub branch checks state](https://img.shields.io/github/checks-status/alirezanet/gridify/master?label=tests)

Easy and optimized way to apply **Filtering**, **Sorting** and **pagination** using text-based data.

Expand Down
47 changes: 31 additions & 16 deletions gridify.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0FCD2937-195
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{1BBCBA37-25E5-4BFF-A8E8-7EE582E0317F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkIntegrationTests.cs", "test\EntityFrameworkIntegrationTests.cs\EntityFrameworkIntegrationTests.cs.csproj", "{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramework6IntegrationTests.cs", "test\EntityFramework6IntegrationTests.cs\EntityFramework6IntegrationTests.cs.csproj", "{CDFDBB16-1D9F-40FD-B693-96D1D4FB79EE}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramework6IntegrationTests", "test\EntityFramework6IntegrationTests\EntityFramework6IntegrationTests.csproj", "{CDFDBB16-1D9F-40FD-B693-96D1D4FB79EE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gridify", "src\Gridify\Gridify.csproj", "{833CCD80-4261-405A-8A4A-BD9B3C375496}"
EndProject
Expand All @@ -21,6 +19,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gridify.Tests", "test\Gridi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "benchmark\Benchmark.csproj", "{02F96021-6989-4F09-919D-999F0BE3DEFB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkIntegrationTests.cs", "test\EntityFrameworkIntegrationTests\EntityFrameworkIntegrationTests.cs.csproj", "{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkSqlProviderIntegrationTests", "test\EntityFrameworkSqlProviderIntegrationTests\EntityFrameworkSqlProviderIntegrationTests.csproj", "{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -34,18 +36,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Debug|x64.ActiveCfg = Debug|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Debug|x64.Build.0 = Debug|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Debug|x86.ActiveCfg = Debug|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Debug|x86.Build.0 = Debug|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Release|Any CPU.Build.0 = Release|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Release|x64.ActiveCfg = Release|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Release|x64.Build.0 = Release|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Release|x86.ActiveCfg = Release|Any CPU
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296}.Release|x86.Build.0 = Release|Any CPU
{CDFDBB16-1D9F-40FD-B693-96D1D4FB79EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDFDBB16-1D9F-40FD-B693-96D1D4FB79EE}.Debug|x64.ActiveCfg = Debug|Any CPU
{CDFDBB16-1D9F-40FD-B693-96D1D4FB79EE}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -101,13 +91,38 @@ Global
{02F96021-6989-4F09-919D-999F0BE3DEFB}.Release|x64.Build.0 = Release|Any CPU
{02F96021-6989-4F09-919D-999F0BE3DEFB}.Release|x86.ActiveCfg = Release|Any CPU
{02F96021-6989-4F09-919D-999F0BE3DEFB}.Release|x86.Build.0 = Release|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Debug|x64.ActiveCfg = Debug|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Debug|x64.Build.0 = Debug|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Debug|x86.ActiveCfg = Debug|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Debug|x86.Build.0 = Debug|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Release|Any CPU.Build.0 = Release|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Release|x64.ActiveCfg = Release|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Release|x64.Build.0 = Release|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Release|x86.ActiveCfg = Release|Any CPU
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4}.Release|x86.Build.0 = Release|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Debug|x64.ActiveCfg = Debug|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Debug|x64.Build.0 = Debug|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Debug|x86.ActiveCfg = Debug|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Debug|x86.Build.0 = Debug|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Release|Any CPU.Build.0 = Release|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Release|x64.ActiveCfg = Release|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Release|x64.Build.0 = Release|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Release|x86.ActiveCfg = Release|Any CPU
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{73CD6D56-C43D-4460-AFFA-FC1AEFB06296} = {1BBCBA37-25E5-4BFF-A8E8-7EE582E0317F}
{CDFDBB16-1D9F-40FD-B693-96D1D4FB79EE} = {1BBCBA37-25E5-4BFF-A8E8-7EE582E0317F}
{833CCD80-4261-405A-8A4A-BD9B3C375496} = {0FCD2937-1953-465E-8608-42B8EB8757C7}
{D1296959-F923-44B6-A8F9-967D5FB7C4C1} = {0FCD2937-1953-465E-8608-42B8EB8757C7}
{6CCEB3F3-2A8A-4790-8DB7-C912509ADFDE} = {1BBCBA37-25E5-4BFF-A8E8-7EE582E0317F}
{02F96021-6989-4F09-919D-999F0BE3DEFB} = {41676937-4F05-4794-A2E5-442127927776}
{9A54A635-2B5B-4EDC-98FE-9BF963903BD4} = {1BBCBA37-25E5-4BFF-A8E8-7EE582E0317F}
{3B9A8E46-1D4D-40EE-89C0-C3C376D9320A} = {1BBCBA37-25E5-4BFF-A8E8-7EE582E0317F}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion src/Gridify.EntityFramework/Gridify.EntityFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Gridify.EntityFramework</PackageId>
<Version>2.2.0</Version>
<Version>2.2.1</Version>
<Authors>Alireza Sabouri</Authors>
<Company>TuxTeam</Company>
<PackageDescription>Gridify (EntityFramework), Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.</PackageDescription>
Expand Down
6 changes: 5 additions & 1 deletion src/Gridify/Gridify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Gridify</PackageId>
<Version>2.2.0</Version>
<Version>2.2.1</Version>
<Authors>Alireza Sabouri</Authors>
<Company>TuxTeam</Company>
<PackageDescription>Gridify, Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.</PackageDescription>
Expand All @@ -16,4 +16,8 @@
<!-- <GeneratePackageOnBuild>true</GeneratePackageOnBuild> -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
</ItemGroup>

</Project>
97 changes: 97 additions & 0 deletions src/Gridify/Syntax/GridifyTypeBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.Reflection;
using System.Reflection.Emit;

namespace Gridify.Syntax
{
internal static class GridifyTypeBuilder
{
private class FieldDescriptor
{
public FieldDescriptor(string fieldName, Type fieldType)
{
FieldName = fieldName;
FieldType = fieldType;
}

public string FieldName { get; }
public Type FieldType { get; }
}

public static (object Instance, Type type) CreateNewObject(Type type, string fieldName, object? value)
{
var myTypeInfo = CompileResultTypeInfo(type, fieldName);
var myType = myTypeInfo!.AsType();
var myObject = Activator.CreateInstance(myType);
myType.GetProperty(fieldName)!.SetValue(myObject, value);
return (myObject, myType);
}

public static TypeInfo? CompileResultTypeInfo(Type type, string name)
{
TypeBuilder tb = GetTypeBuilder();
ConstructorBuilder constructor =
tb.DefineDefaultConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);

var field = new FieldDescriptor(name, type);
CreateProperty(tb, field.FieldName, field.FieldType);
var objectTypeInfo = tb.CreateTypeInfo();

return objectTypeInfo;
}

private static TypeBuilder GetTypeBuilder()
{
const string? typeSignature = "GridifyDisplayClass";
var an = new AssemblyName(typeSignature);
var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(Guid.NewGuid().ToString()), AssemblyBuilderAccess.Run);
ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("RuntimeModule");
TypeBuilder tb = moduleBuilder.DefineType(typeSignature,
TypeAttributes.Public |
TypeAttributes.Class |
TypeAttributes.AutoClass |
TypeAttributes.AnsiClass |
TypeAttributes.BeforeFieldInit |
TypeAttributes.AutoLayout,
null);
return tb;
}

private static void CreateProperty(TypeBuilder tb, string propertyName, Type propertyType)
{
FieldBuilder fieldBuilder = tb.DefineField("_" + propertyName, propertyType, FieldAttributes.Private);

PropertyBuilder propertyBuilder = tb.DefineProperty(propertyName, PropertyAttributes.HasDefault, propertyType, null);
MethodBuilder getPropMthdBldr = tb.DefineMethod("get_" + propertyName,
MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig, propertyType, Type.EmptyTypes);
ILGenerator getIl = getPropMthdBldr.GetILGenerator();

getIl.Emit(OpCodes.Ldarg_0);
getIl.Emit(OpCodes.Ldfld, fieldBuilder);
getIl.Emit(OpCodes.Ret);

MethodBuilder setPropMthdBldr =
tb.DefineMethod("set_" + propertyName,
MethodAttributes.Public |
MethodAttributes.SpecialName |
MethodAttributes.HideBySig,
null, new[] { propertyType });

ILGenerator setIl = setPropMthdBldr.GetILGenerator();
var modifyProperty = setIl.DefineLabel();
var exitSet = setIl.DefineLabel();

setIl.MarkLabel(modifyProperty);
setIl.Emit(OpCodes.Ldarg_0);
setIl.Emit(OpCodes.Ldarg_1);
setIl.Emit(OpCodes.Stfld, fieldBuilder);

setIl.Emit(OpCodes.Nop);
setIl.MarkLabel(exitSet);
setIl.Emit(OpCodes.Ret);

propertyBuilder.SetGetMethod(getPropMthdBldr);
propertyBuilder.SetSetMethod(setPropMthdBldr);
}
}
}
Loading

0 comments on commit 179c5ab

Please sign in to comment.