Skip to content

Hotfix/psmodelgenerator #2632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/ResourceManager/AzureBatch/BatchModelGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,14 @@ private static void GenerateModel(string fileName, Type omType, string modelName
CodeCompileUnit compileUnit = new CodeCompileUnit();
CodeNamespace codeNamespace = new CodeNamespace(ModelNamespace);
GenerateUsingDirectives(codeNamespace);
CodeTypeDeclaration codeType = new CodeTypeDeclaration(modelName);
codeType.IsClass = true;
codeType.TypeAttributes = TypeAttributes.Public;

var codeType = new CodeTypeDeclaration(modelName)
{
IsClass = true,
TypeAttributes = TypeAttributes.Public,
IsPartial = true, // allows us to provide some custom behaviours
};

codeNamespace.Types.Add(codeType);
compileUnit.Namespaces.Add(codeNamespace);

Expand Down Expand Up @@ -262,7 +267,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
CodeExpression[] codeArgumentReferences = new CodeExpression[parameters.Length];
for (int i = 0; i < parameters.Length; i++)
{
bool isOmTypeArg= false;
bool isOmTypeArg = false;

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

// if the parameter is not null, use the omObject of the PS Wrapper class
// if the parameter is not null, use the omObject of the PS Wrapper class
constructor.Statements.Add(new CodeConditionStatement(nullCheck, omObjectAssignStatement));

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

codeArgumentReferences[i] = new CodeArgumentReferenceExpression(passedInArg);
constructor.Parameters.Add(new CodeParameterDeclarationExpression(paramType, paramName));
constructor.Parameters.Add(new CodeParameterDeclarationExpression(paramType, paramName));
}

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


CodeFieldReferenceExpression wrappedObject = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), OmObject);
CodePropertyReferenceExpression wrappedObjectProperty = new CodePropertyReferenceExpression(wrappedObject, property.Name);
CodeFieldReferenceExpression fieldReference = null;
Expand All @@ -360,8 +364,8 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
codeProperty.Name = property.Name;
codeProperty.Type = new CodeTypeReference(propertyType);

// For properties with a backing field, the field will not be initialized in the constructor in order to avoid
// hitting a run time access constraint from the OM. Instead, the field is initialized on the first access of
// For properties with a backing field, the field will not be initialized in the constructor in order to avoid
// hitting a run time access constraint from the OM. Instead, the field is initialized on the first access of
// the property.

if (isGenericCollection)
Expand Down Expand Up @@ -404,7 +408,7 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
CodeMethodInvokeExpression addToList = new CodeMethodInvokeExpression(listReference, "Add", createListItem);
loopStatement.Statements.Add(addToList);
}

// Initialize the backing field with the built list on first access of the property
CodeAssignStatement assignStatement;
if (property.PropertyType.GetGenericTypeDefinition() == typeof(IReadOnlyList<>))
Expand Down