/// <summary> /// Initializes a new instance of the <see cref="CSharpAttachmentInstruction"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly instruction from which the C# instruction is created.</param> protected CSharpAttachmentInstruction(ICSharpContext context, ICSharpFeature parentFeature, IAttachmentInstruction source) : base(context, parentFeature, source) { SourceExpression = CSharpExpression.Create(context, (IExpression)source.Source); IResultType ResolvedResult = SourceExpression.Source.ResolvedResult.Item; for (int i = 0; i < source.EntityNameList.Count; i++) { IName EntityName = source.EntityNameList[i]; string ValidName = EntityName.ValidText.Item; EntityNameList.Add(new CSharpVariableContext(ValidName)); } foreach (IAttachment Attachment in source.AttachmentList) { ICSharpAttachment NewAttachment = CSharpAttachment.Create(context, this, Attachment); AttachmentList.Add(NewAttachment); } if (source.ElseInstructions.IsAssigned) { ElseInstructions = CSharpScope.Create(context, parentFeature, (IScope)source.ElseInstructions.Item); } }
private void WriteCSharpSwitch(ICSharpWriter writer) { ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext(EntityNameList); SourceExpression.WriteCSharp(writer, ExpressionContext, -1); Debug.Assert(ExpressionContext.FilledDestinationTable.Count == 1); string EntityName = EntityNameList[0].Name; string LastExpressionText = ExpressionContext.FilledDestinationTable[EntityName]; if (LastExpressionText == null) { LastExpressionText = ExpressionContext.ReturnValue; } writer.WriteIndentedLine($"switch ({LastExpressionText})"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); for (int i = 0; i < AttachmentList.Count; i++) { ICSharpAttachment Attachment = AttachmentList[i]; Attachment.WriteCSharpCase(writer, EntityName); } writer.DecreaseIndent(); writer.WriteIndentedLine("}"); }
private void WriteCSharpIf(ICSharpWriter writer) { ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext(); SourceExpression.WriteCSharp(writer, ExpressionContext, -1); for (int i = 0; i < AttachmentList.Count; i++) { ICSharpAttachment Attachment = AttachmentList[i]; Attachment.WriteCSharpIf(writer, i, EntityNameList, ExpressionContext); } if (ElseInstructions != null) { writer.WriteIndentedLine("else"); ElseInstructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.Mandatory, false); } }