1- using Microsoft . EntityFrameworkCore . Metadata ;
2- using System ;
3- using System . Collections . Generic ;
1+ using System ;
42namespace EntityFrameworkCore . Scaffolding . Handlebars
53{
64 /// <summary>
75 /// Default service for transforming entity type definitions.
86 /// </summary>
9- public class HbsEntityTypeTransformationService : IEntityTypeTransformationService
10- {
7+ public class HbsEntityTypeTransformationService : HbsEntityTypeTransformationServiceBase
8+ {
119 /// <summary>
1210 /// Entity name transformer.
1311 /// </summary>
14- public Func < string , string > EntityTypeNameTransformer { get ; }
12+ public new Func < string , string > EntityTypeNameTransformer { get => base . EntityTypeNameTransformer ; }
1513
1614 /// <summary>
1715 /// Entity file name transformer.
1816 /// </summary>
19- public Func < string , string > EntityFileNameTransformer { get ; }
17+ public new Func < string , string > EntityFileNameTransformer { get => base . EntityFileNameTransformer ; }
2018
2119 /// <summary>
2220 /// Constructor transformer.
2321 /// </summary>
24- public Func < IEntityType , EntityPropertyInfo , EntityPropertyInfo > ConstructorTransformer { get ; }
22+ public new Func < EntityPropertyInfo , EntityPropertyInfo > ConstructorTransformer { get => base . ConstructorTransformer ; }
2523
2624 /// <summary>
2725 /// Property name transformer.
2826 /// </summary>
29- public Func < IEntityType , EntityPropertyInfo , EntityPropertyInfo > PropertyTransformer { get ; }
27+ public new Func < EntityPropertyInfo , EntityPropertyInfo > PropertyTransformer { get => base . PropertyTransformer ; }
3028
3129 /// <summary>
3230 /// Navigation property name transformer.
3331 /// </summary>
34- public Func < IEntityType , EntityPropertyInfo , EntityPropertyInfo > NavPropertyTransformer { get ; }
32+ public new Func < EntityPropertyInfo , EntityPropertyInfo > NavPropertyTransformer { get => base . NavPropertyTransformer ; }
3533
3634 /// <summary>
3735 /// HbsEntityTypeTransformationService constructor.
@@ -44,142 +42,14 @@ public class HbsEntityTypeTransformationService : IEntityTypeTransformationServi
4442 public HbsEntityTypeTransformationService (
4543 Func < string , string > entityTypeNameTransformer = null ,
4644 Func < string , string > entityFileNameTransformer = null ,
47- Func < IEntityType , EntityPropertyInfo , EntityPropertyInfo > constructorTransformer = null ,
48- Func < IEntityType , EntityPropertyInfo , EntityPropertyInfo > propertyTransformer = null ,
49- Func < IEntityType , EntityPropertyInfo , EntityPropertyInfo > navPropertyTransformer = null )
45+ Func < EntityPropertyInfo , EntityPropertyInfo > constructorTransformer = null ,
46+ Func < EntityPropertyInfo , EntityPropertyInfo > propertyTransformer = null ,
47+ Func < EntityPropertyInfo , EntityPropertyInfo > navPropertyTransformer = null )
48+ : base ( entityTypeNameTransformer , entityFileNameTransformer )
5049 {
51- EntityTypeNameTransformer = entityTypeNameTransformer ;
52- EntityFileNameTransformer = entityFileNameTransformer ;
53- ConstructorTransformer = constructorTransformer ;
54- PropertyTransformer = propertyTransformer ;
55- NavPropertyTransformer = navPropertyTransformer ;
56- }
57-
58- /// <summary>
59- /// Transform entity type name.
60- /// </summary>
61- /// <param name="entityName">Entity type name.</param>
62- /// <returns>Transformed entity type name.</returns>
63- public string TransformTypeEntityName ( string entityName ) =>
64- EntityTypeNameTransformer ? . Invoke ( entityName ) ?? entityName ;
65-
66- /// <summary>
67- /// Transform entity file name.
68- /// </summary>
69- /// <param name="entityFileName">Entity file name.</param>
70- /// <returns>Transformed entity file name.</returns>
71- public string TransformEntityFileName ( string entityFileName ) =>
72- EntityFileNameTransformer ? . Invoke ( entityFileName ) ?? entityFileName ;
73-
74- /// <summary>
75- /// Transform single property name.
76- /// </summary>
77- /// <param name="entityType">Entity type.</param>
78- /// <param name="propertyName">Property name.</param>
79- /// <param name="propertyType">Property type</param>
80- /// <returns>Transformed property name.</returns>
81- public string TransformPropertyName ( IEntityType entityType , string propertyName , string propertyType )
82- {
83- var propTypeInfo = new EntityPropertyInfo { PropertyName = propertyName , PropertyType = propertyType } ;
84- return PropertyTransformer ? . Invoke ( entityType , propTypeInfo ) ? . PropertyName ?? propertyName ;
85- }
86-
87- /// <summary>
88- /// Transform single navigation property name.
89- /// </summary>
90- /// <param name="entityType">Entity type.</param>
91- /// <param name="propertyName">Property name.</param>
92- /// <param name="propertyType">Property type</param>
93- /// <returns>Transformed property name.</returns>
94- public string TransformNavPropertyName ( IEntityType entityType , string propertyName , string propertyType )
95- {
96- var propTypeInfo = new EntityPropertyInfo { PropertyName = propertyName , PropertyType = propertyType } ;
97- return NavPropertyTransformer ? . Invoke ( entityType , propTypeInfo ) ? . PropertyName ?? propertyName ;
98- }
99-
100- /// <summary>
101- /// Transform entity type constructor.
102- /// </summary>
103- /// <param name="entityType">Entity type.</param>
104- /// <param name="lines">Constructor lines.</param>
105- /// <returns>Transformed constructor lines.</returns>
106- public List < Dictionary < string , object > > TransformConstructor ( IEntityType entityType , List < Dictionary < string , object > > lines )
107- {
108- var transformedLines = new List < Dictionary < string , object > > ( ) ;
109-
110- foreach ( var line in lines )
111- {
112- var propTypeInfo = new EntityPropertyInfo ( line [ "property-type" ] as string ,
113- line [ "property-name" ] as string ) ;
114- var transformedProp = ConstructorTransformer ? . Invoke ( entityType , propTypeInfo ) ?? propTypeInfo ;
115-
116- transformedLines . Add ( new Dictionary < string , object >
117- {
118- { "property-name" , transformedProp . PropertyName } ,
119- { "property-type" , transformedProp . PropertyType }
120- } ) ;
121- }
122-
123- return transformedLines ;
124- }
125-
126- /// <summary>
127- /// Transform entity type properties.
128- /// </summary>
129- /// <param name="entityType">Entity type.</param>
130- /// <param name="properties">Entity type properties.</param>
131- /// <returns>Transformed entity type properties.</returns>
132- public List < Dictionary < string , object > > TransformProperties ( IEntityType entityType , List < Dictionary < string , object > > properties )
133- {
134- var transformedProperties = new List < Dictionary < string , object > > ( ) ;
135-
136- foreach ( var property in properties )
137- {
138- var propTypeInfo = new EntityPropertyInfo ( property [ "property-type" ] as string ,
139- property [ "property-name" ] as string ,
140- ( property [ "property-isnullable" ] as bool ? ) == true ) ;
141- var transformedProp = PropertyTransformer ? . Invoke ( entityType , propTypeInfo ) ?? propTypeInfo ;
142-
143- transformedProperties . Add ( new Dictionary < string , object >
144- {
145- { "property-type" , transformedProp . PropertyType } ,
146- { "property-name" , transformedProp . PropertyName } ,
147- { "property-annotations" , property [ "property-annotations" ] } ,
148- { "property-comment" , property [ "property-comment" ] } ,
149- { "property-isnullable" , transformedProp . PropertyIsNullable } ,
150- { "nullable-reference-types" , property [ "nullable-reference-types" ] }
151- } ) ;
152- }
153-
154- return transformedProperties ;
155- }
156-
157- /// <summary>
158- /// Transform entity type navigation properties.
159- /// </summary>
160- /// <param name="entityType">Entity type.</param>
161- /// <param name="navProperties">Entity type navigation properties.</param>
162- /// <returns>Transformed entity type navigation properties.</returns>
163- public List < Dictionary < string , object > > TransformNavigationProperties ( IEntityType entityType , List < Dictionary < string , object > > navProperties )
164- {
165- var transformedNavProperties = new List < Dictionary < string , object > > ( ) ;
166-
167- foreach ( var navProperty in navProperties )
168- {
169- var propTypeInfo = new EntityPropertyInfo ( navProperty [ "nav-property-type" ] as string ,
170- navProperty [ "nav-property-name" ] as string ) ;
171- var transformedProp = NavPropertyTransformer ? . Invoke ( entityType , propTypeInfo ) ?? propTypeInfo ;
172-
173- var newNavProperty = new Dictionary < string , object > ( navProperty )
174- {
175- [ "nav-property-type" ] = transformedProp . PropertyType ,
176- [ "nav-property-name" ] = transformedProp . PropertyName
177- } ;
178-
179- transformedNavProperties . Add ( newNavProperty ) ;
180- }
181-
182- return transformedNavProperties ;
50+ base . ConstructorTransformer = constructorTransformer ;
51+ base . PropertyTransformer = propertyTransformer ;
52+ base . NavPropertyTransformer = navPropertyTransformer ;
18353 }
18454 }
18555}
0 commit comments