Skip to content

Commit 0402607

Browse files
committed
New LIQN
1 parent 3082e96 commit 0402607

File tree

217 files changed

+237
-36750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+237
-36750
lines changed

src/StronglyTypedIds.Attributes/StronglyTypedIdConverter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,10 @@ public enum StronglyTypedIdConverter
5757
/// </summary>
5858
AutoMapper = 128,
5959

60+
/// <summary>
61+
/// Creates a LinqToDb bidirectional converters
62+
/// </summary>
63+
LinqToDb = 256,
64+
6065
}
6166
}

src/StronglyTypedIds/EmbeddedSources.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal static class EmbeddedSources
3030
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_StronglyTypedId.cs"),
3131
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_SwaggerSchemaFilter.cs"),
3232
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_AutoMapperTypeConverter.cs"),
33+
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_LinqToDbTypeConverter.cs"),
3334
false
3435
);
3536

@@ -47,6 +48,7 @@ internal static class EmbeddedSources
4748
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_StronglyTypedId.cs"),
4849
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_SwaggerSchemaFilter.cs"),
4950
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_AutoMapperTypeConverter.cs"),
51+
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_LinqToDbTypeConverter.cs"),
5052
false
5153
);
5254

@@ -64,6 +66,7 @@ internal static class EmbeddedSources
6466
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_StronglyTypedId.cs"),
6567
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_SwaggerSchemaFilter.cs"),
6668
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_AutoMapperTypeConverter.cs"),
69+
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_LinqToDbTypeConverter.cs"),
6770
false
6871
);
6972

@@ -81,6 +84,7 @@ internal static class EmbeddedSources
8184
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_StronglyTypedId.cs"),
8285
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_SwaggerSchemaFilter.cs"),
8386
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_AutoMapperTypeConverter.cs"),
87+
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_LinqToDbTypeConverter.cs"),
8488
false
8589
);
8690

@@ -98,6 +102,7 @@ internal static class EmbeddedSources
98102
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_StronglyTypedId.cs"),
99103
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_SwaggerSchemaFilter.cs"),
100104
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_AutoMapperTypeConverter.cs"),
105+
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_LinqToDbTypeConverter.cs"),
101106
true
102107
);
103108

@@ -115,6 +120,7 @@ internal static class EmbeddedSources
115120
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_StronglyTypedId.cs"),
116121
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_SwaggerSchemaFilter.cs"),
117122
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_AutoMapperTypeConverter.cs"),
123+
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_LinqToDbTypeConverter.cs"),
118124
false
119125
);
120126

@@ -149,6 +155,7 @@ public readonly struct ResourceCollection
149155
public string EfCoreValueConverter { get; }
150156
public string DapperTypeHandler { get; }
151157
public string AutoMapperTypeHandler { get; }
158+
public string LinqToDbTypeHandler { get; }
152159
public string Comparable { get; }
153160
public string Parsable { get; }
154161
public string Convertible { get; }
@@ -169,6 +176,7 @@ public ResourceCollection(
169176
string stronglyTypedId,
170177
string swaggerSchemaFilter,
171178
string autoMapperTypeHandler,
179+
string linqToDbTypeHandler,
172180
bool nullableEnable)
173181
{
174182
SwaggerSchemaFilter = swaggerSchemaFilter;
@@ -179,6 +187,7 @@ public ResourceCollection(
179187
EfCoreValueConverter = efCoreValueConverter;
180188
DapperTypeHandler = dapperTypeHandler;
181189
AutoMapperTypeHandler = autoMapperTypeHandler;
190+
LinqToDbTypeHandler = linqToDbTypeHandler;
182191
Comparable = comparable;
183192
Parsable = parsable;
184193
Convertible = convertible;

src/StronglyTypedIds/SourceGenerationHelper.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static string CreateId(
7272
var useEfCoreValueConverter = converters.IsSet(StronglyTypedIdConverter.EfCoreValueConverter);
7373
var useDapperTypeHandler = converters.IsSet(StronglyTypedIdConverter.DapperTypeHandler);
7474
var useAutoMapperTypeHandler = converters.IsSet(StronglyTypedIdConverter.AutoMapper);
75+
var useLinqToDbTypeHandler = converters.IsSet(StronglyTypedIdConverter.LinqToDb);
7576

7677
var useIEquatable = implementations.IsSet(StronglyTypedIdImplementations.IEquatable);
7778
var useIComparable = implementations.IsSet(StronglyTypedIdImplementations.IComparable);
@@ -174,6 +175,11 @@ static string CreateId(
174175
sb.AppendLine(resources.AutoMapperTypeHandler);
175176
}
176177

178+
if (useLinqToDbTypeHandler)
179+
{
180+
sb.AppendLine(resources.LinqToDbTypeHandler);
181+
}
182+
177183
if (useTypeConverter)
178184
{
179185
sb.AppendLine(resources.TypeConverter);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
#if !FAKE_CODE
3+
4+
#endif
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
#if !FAKE_CODE
3+
4+
#endif

src/StronglyTypedIds/Templates/Long/Long_Convertible.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public System.DateTime ToDateTime(System.IFormatProvider? provider)
2929

3030
public decimal ToDecimal(System.IFormatProvider? provider)
3131
{
32-
throw new System.NotImplementedException();
32+
return (decimal)Value;
3333
}
3434

3535
public double ToDouble(System.IFormatProvider? provider)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+

2+
#if !FAKE_CODE
3+
public static void UseLinqToDbConverter(LinqToDB.DataOptions opts)
4+
{
5+
var mappingSchema = new LinqToDB.Mapping.MappingSchema();
6+
7+
mappingSchema.SetDataType(typeof(TESTID), LinqToDB.DataType.Decimal);
8+
mappingSchema
9+
.SetConvertExpression<TESTID, LinqToDB.Data.DataParameter>(a => new LinqToDB.Data.DataParameter() { DataType = LinqToDB.DataType.Decimal, Value = a.Value});
10+
11+
LinqToDB.DataOptionsExtensions.UseMappingSchema(opts, mappingSchema);
12+
}
13+
14+
public static TESTID op_Implicit(decimal value)
15+
{
16+
return new TESTID((long)value);
17+
}
18+
#endif
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
#if !FAKE_CODE
3+
4+
#endif
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
#if !FAKE_CODE
3+
4+
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+

2+
#if !FAKE_CODE
3+
public static void UseLinqToDbConverter(LinqToDB.DataOptions opts)
4+
{
5+
var mappingSchema = new LinqToDB.Mapping.MappingSchema();
6+
7+
mappingSchema.SetDataType(typeof(TESTID), LinqToDB.DataType.VarChar);
8+
mappingSchema
9+
.SetConvertExpression<TESTID, LinqToDB.Data.DataParameter>(a => new LinqToDB.Data.DataParameter() { DataType = LinqToDB.DataType.VarChar, Value = a.Value});
10+
11+
LinqToDB.DataOptionsExtensions.UseMappingSchema(opts, mappingSchema);
12+
}
13+
14+
public static TESTID op_Implicit(string value)
15+
{
16+
return new TESTID(value);
17+
}
18+
19+
#endif

0 commit comments

Comments
 (0)