public static ArmNestedTemplate CreateFromTemplates(IEnumerable <ArmTemplate> templates) { var resourceArray = new ArmArray <ArmResource>(); var templateNames = new Dictionary <string, int>(); foreach (ArmTemplate template in templates) { string templateName = template.TemplateName; if (templateNames.TryGetValue(templateName, out int count)) { count++; templateName = $"{templateName}_{count}"; templateNames[templateName] = count; } else { templateNames[templateName] = 0; } resourceArray.Add(new ArmTemplateResource(new ArmStringLiteral(templateName)) { Template = template, }); } return(new ArmNestedTemplate { Resources = resourceArray, }); }
protected override void EndProcessing() { if (Body != null) { WriteArmArrayElement(Body); return; } var armArray = new ArmArray(); for (int i = 0; i < Values.Length; i++) { object currVal = Values[i]; if (!ArmElementConversion.TryConvertToArmElement(currVal, out ArmElement element)) { this.ThrowTerminatingError( new InvalidCastException($"Unable to convert value '{currVal}' of type '{currVal.GetType()}' to type '{typeof(ArmElement)}'"), "InvalidArmTypeCase", ErrorCategory.InvalidArgument, currVal); return; } armArray.Add(element); } WriteObject(armArray); }
private bool TryGetAllowedValues(ParameterAst parameter, out ArmArray allowedValues) { if (parameter.Attributes is null) { allowedValues = null; return(false); } foreach (AttributeBaseAst attributeBase in parameter.Attributes) { if (attributeBase is not AttributeAst attribute || attribute.TypeName.GetReflectionType() != typeof(ValidateSetAttribute) || attribute.PositionalArguments is null || attribute.PositionalArguments.Count == 0) { continue; } allowedValues = new ArmArray(); foreach (ExpressionAst allowedExpression in attribute.PositionalArguments) { if (!ArmElementConversion.TryConvertToArmElement(allowedExpression.SafeGetValue(), out ArmElement allowedArmElement)) { throw new ArgumentException($"ValidateSet value '{allowedExpression}' on parameter '{parameter.Name}' is not a value ARM value"); } allowedValues.Add(allowedArmElement); } return(true); } allowedValues = null; return(false); }
private ArmArray ReadArmArray(JArray jArray) { var armArray = new ArmArray(); foreach (JToken item in jArray) { armArray.Add(ReadValue(item)); } return(armArray); }
protected ArmArray <TArmElement> AggregateArmArray <TArmElement>( ScriptBlock body) where TArmElement : ArmElement { var array = new ArmArray <TArmElement>(); foreach (PSObject output in InvokeBody(body)) { if (output.BaseObject is TArmElement element) { array.Add(element); } } return(array); }
protected override void EndProcessing() { var array = new ArmArray(); if (Value != null) { foreach (IArmString value in Value) { array.Add((ArmElement)value); } WriteArmValueEntry(ArmTemplateKeys.DependsOn, array); return; } foreach (PSObject output in InvokeBody(Body)) { if (LanguagePrimitives.TryConvertTo(output, typeof(IArmString), out object result)) { array.Add((ArmElement)result); } } WriteArmValueEntry(ArmTemplateKeys.DependsOn, array); }
private static bool TryConvertEnumerableToArmArray(IEnumerable enumerable, out ArmElement armArray) { var array = new ArmArray(); foreach (object element in enumerable) { if (!TryConvertToArmElement(element, out ArmElement armElement)) { armArray = null; return(false); } array.Add(armElement); } armArray = array; return(true); }
public ArmNestedTemplateBuilder AddTemplate(ArmTemplate template) { string templateName = template.TemplateName; if (_templateNameCounts.TryGetValue(templateName, out int count)) { count++; templateName = $"{templateName}_{count}"; _templateNameCounts[templateName] = count; } else { _templateNameCounts[templateName] = 0; } _templateResources.Add(new ArmTemplateResource(new ArmStringLiteral(templateName)) { Template = template, }); return(this); }