@@ -152,9 +152,14 @@ private static void GenerateModel(string fileName, Type omType, string modelName
152
152
CodeCompileUnit compileUnit = new CodeCompileUnit ( ) ;
153
153
CodeNamespace codeNamespace = new CodeNamespace ( ModelNamespace ) ;
154
154
GenerateUsingDirectives ( codeNamespace ) ;
155
- CodeTypeDeclaration codeType = new CodeTypeDeclaration ( modelName ) ;
156
- codeType . IsClass = true ;
157
- codeType . TypeAttributes = TypeAttributes . Public ;
155
+
156
+ var codeType = new CodeTypeDeclaration ( modelName )
157
+ {
158
+ IsClass = true ,
159
+ TypeAttributes = TypeAttributes . Public ,
160
+ IsPartial = true , // allows us to provide some custom behaviours
161
+ } ;
162
+
158
163
codeNamespace . Types . Add ( codeType ) ;
159
164
compileUnit . Namespaces . Add ( codeNamespace ) ;
160
165
@@ -262,7 +267,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
262
267
CodeExpression [ ] codeArgumentReferences = new CodeExpression [ parameters . Length ] ;
263
268
for ( int i = 0 ; i < parameters . Length ; i ++ )
264
269
{
265
- bool isOmTypeArg = false ;
270
+ bool isOmTypeArg = false ;
266
271
267
272
string paramType = parameters [ i ] . ParameterType . FullName ;
268
273
if ( OMtoPSClassMappings . ContainsKey ( paramType ) )
@@ -296,7 +301,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
296
301
CodeAssignStatement omObjectAssignStatement = new CodeAssignStatement ( new CodeVariableReferenceExpression ( string . Format ( "{0}{1}" , parameters [ i ] . Name , "OmObject" ) ) , new CodeVariableReferenceExpression ( string . Format ( "{0}.{1}" , parameters [ i ] . Name , OmObject ) ) ) ;
297
302
CodeBinaryOperatorExpression nullCheck = new CodeBinaryOperatorExpression ( omObjectArgumentReference , CodeBinaryOperatorType . IdentityInequality , new CodePrimitiveExpression ( null ) ) ;
298
303
299
- // if the parameter is not null, use the omObject of the PS Wrapper class
304
+ // if the parameter is not null, use the omObject of the PS Wrapper class
300
305
constructor . Statements . Add ( new CodeConditionStatement ( nullCheck , omObjectAssignStatement ) ) ;
301
306
302
307
passedInArg = string . Format ( "{0}{1}" , parameters [ i ] . Name , "OmObject" ) ;
@@ -311,7 +316,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
311
316
}
312
317
313
318
codeArgumentReferences [ i ] = new CodeArgumentReferenceExpression ( passedInArg ) ;
314
- constructor . Parameters . Add ( new CodeParameterDeclarationExpression ( paramType , paramName ) ) ;
319
+ constructor . Parameters . Add ( new CodeParameterDeclarationExpression ( paramType , paramName ) ) ;
315
320
}
316
321
317
322
CodeObjectCreateExpression createExpression = new CodeObjectCreateExpression ( implementationType , codeArgumentReferences ) ;
@@ -338,7 +343,6 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
338
343
( property . PropertyType . GetGenericTypeDefinition ( ) == typeof ( IList < > ) || property . PropertyType . GetGenericTypeDefinition ( ) == typeof ( IEnumerable < > ) ||
339
344
property . PropertyType . GetGenericTypeDefinition ( ) == typeof ( IReadOnlyList < > ) ) ;
340
345
341
-
342
346
CodeFieldReferenceExpression wrappedObject = new CodeFieldReferenceExpression ( new CodeThisReferenceExpression ( ) , OmObject ) ;
343
347
CodePropertyReferenceExpression wrappedObjectProperty = new CodePropertyReferenceExpression ( wrappedObject , property . Name ) ;
344
348
CodeFieldReferenceExpression fieldReference = null ;
@@ -360,8 +364,8 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
360
364
codeProperty . Name = property . Name ;
361
365
codeProperty . Type = new CodeTypeReference ( propertyType ) ;
362
366
363
- // For properties with a backing field, the field will not be initialized in the constructor in order to avoid
364
- // hitting a run time access constraint from the OM. Instead, the field is initialized on the first access of
367
+ // For properties with a backing field, the field will not be initialized in the constructor in order to avoid
368
+ // hitting a run time access constraint from the OM. Instead, the field is initialized on the first access of
365
369
// the property.
366
370
367
371
if ( isGenericCollection )
@@ -404,7 +408,7 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
404
408
CodeMethodInvokeExpression addToList = new CodeMethodInvokeExpression ( listReference , "Add" , createListItem ) ;
405
409
loopStatement . Statements . Add ( addToList ) ;
406
410
}
407
-
411
+
408
412
// Initialize the backing field with the built list on first access of the property
409
413
CodeAssignStatement assignStatement ;
410
414
if ( property . PropertyType . GetGenericTypeDefinition ( ) == typeof ( IReadOnlyList < > ) )
0 commit comments