Skip to content

Commit f23d6c5

Browse files
matthew-rollittHovsep
authored andcommitted
Moved a few changes from old repo over. (Azure#2632)
1 parent 77ecca1 commit f23d6c5

File tree

1 file changed

+14
-10
lines changed
  • src/ResourceManager/AzureBatch/BatchModelGenerator

1 file changed

+14
-10
lines changed

src/ResourceManager/AzureBatch/BatchModelGenerator/Program.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,14 @@ private static void GenerateModel(string fileName, Type omType, string modelName
152152
CodeCompileUnit compileUnit = new CodeCompileUnit();
153153
CodeNamespace codeNamespace = new CodeNamespace(ModelNamespace);
154154
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+
158163
codeNamespace.Types.Add(codeType);
159164
compileUnit.Namespaces.Add(codeNamespace);
160165

@@ -262,7 +267,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
262267
CodeExpression[] codeArgumentReferences = new CodeExpression[parameters.Length];
263268
for (int i = 0; i < parameters.Length; i++)
264269
{
265-
bool isOmTypeArg= false;
270+
bool isOmTypeArg = false;
266271

267272
string paramType = parameters[i].ParameterType.FullName;
268273
if (OMtoPSClassMappings.ContainsKey(paramType))
@@ -296,7 +301,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
296301
CodeAssignStatement omObjectAssignStatement = new CodeAssignStatement(new CodeVariableReferenceExpression(string.Format("{0}{1}", parameters[i].Name, "OmObject")), new CodeVariableReferenceExpression(string.Format("{0}.{1}", parameters[i].Name, OmObject)));
297302
CodeBinaryOperatorExpression nullCheck = new CodeBinaryOperatorExpression(omObjectArgumentReference, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
298303

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
300305
constructor.Statements.Add(new CodeConditionStatement(nullCheck, omObjectAssignStatement));
301306

302307
passedInArg = string.Format("{0}{1}", parameters[i].Name, "OmObject");
@@ -311,7 +316,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
311316
}
312317

313318
codeArgumentReferences[i] = new CodeArgumentReferenceExpression(passedInArg);
314-
constructor.Parameters.Add(new CodeParameterDeclarationExpression(paramType, paramName));
319+
constructor.Parameters.Add(new CodeParameterDeclarationExpression(paramType, paramName));
315320
}
316321

317322
CodeObjectCreateExpression createExpression = new CodeObjectCreateExpression(implementationType, codeArgumentReferences);
@@ -338,7 +343,6 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
338343
(property.PropertyType.GetGenericTypeDefinition() == typeof(IList<>) || property.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>) ||
339344
property.PropertyType.GetGenericTypeDefinition() == typeof(IReadOnlyList<>));
340345

341-
342346
CodeFieldReferenceExpression wrappedObject = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), OmObject);
343347
CodePropertyReferenceExpression wrappedObjectProperty = new CodePropertyReferenceExpression(wrappedObject, property.Name);
344348
CodeFieldReferenceExpression fieldReference = null;
@@ -360,8 +364,8 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
360364
codeProperty.Name = property.Name;
361365
codeProperty.Type = new CodeTypeReference(propertyType);
362366

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
365369
// the property.
366370

367371
if (isGenericCollection)
@@ -404,7 +408,7 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
404408
CodeMethodInvokeExpression addToList = new CodeMethodInvokeExpression(listReference, "Add", createListItem);
405409
loopStatement.Statements.Add(addToList);
406410
}
407-
411+
408412
// Initialize the backing field with the built list on first access of the property
409413
CodeAssignStatement assignStatement;
410414
if (property.PropertyType.GetGenericTypeDefinition() == typeof(IReadOnlyList<>))

0 commit comments

Comments
 (0)