internal IEnumerable <IContainer> ToContainers(ModuleSchema schema, ModuleJson module, ModuleAddress parentAddress, string?parentPath, SchemaVariables variables) { variables = variables.WithVariables(ExtraVariables); ModuleOffset offset = ModuleOffset.FromDisplayValue(Offset.Value); if (Repeat is null) { yield return(resolvedContainer.ToContainer(schema, module, ResolvedName, ResolvedDescription, parentAddress + offset, parentPath, variables)); } else { int gap = ModuleOffset.FromDisplayValue(Repeat.Gap.Value).LogicalValue; foreach (var tuple in module.GetRepeatSequence(Repeat.Items, variables)) { var itemVariables = variables.WithVariable(Repeat.IndexVariable, tuple.index, Repeat.IndexTemplate); var formattedDescription = tuple.variables.Replace(ResolvedDescription); var formattedName = Invariant($"{ResolvedName}[{tuple.index}]"); yield return(resolvedContainer.ToContainer(schema, module, formattedName, formattedDescription, parentAddress + offset, parentPath, itemVariables)); offset += gap; } } }
internal INodeDetail ToNodeDetail(ModuleJson module, IContainer nodeContainer, SchemaVariables nodeVariables) { Validation.Validate(Path is null ^ FormatPaths is null, "Exactly one of Path and FormatPaths must be specified"); if (Path is object) { var container = nodeContainer.ResolveContainer(nodeVariables.Replace(Path)); return(container is FieldContainer fc ? new FieldContainerNodeDetail(Description, fc) : throw new ArgumentException($"'{Path}' does not resolve to a field container")); } else { var formattableFields = module.GetRepeatSequence(Repeat, SchemaVariables.Empty) .Select(tuple => tuple.variables) .Select(variables => FieldFormattableString.Create(nodeContainer, Format, FormatPaths, variables)) .ToList() .AsReadOnly(); return(new ListNodeDetail(Description, formattableFields)); } }
public IContainer ToContainer(ModuleSchema schema, ModuleJson module, string name, string description, ModuleAddress address, string?parentPath, SchemaVariables variables) { string path = PathUtilities.AppendPath(parentPath, name); if (Fields is object) { var fieldList = requiresOverlayResolution ? resolvedFields.Select(FinalizeField) : resolvedFields; var realSize = ModuleOffset.FromDisplayValue(Size.Value).LogicalValue; return(new FieldContainer(schema, name, description, address, path, realSize, fieldList)); FieldBase FinalizeField(FieldBase field) => field is OverlayField overlay?overlay.WithPath(variables.Replace(overlay.SwitchPath)) : field; } else { var containers = new List <IContainer>(); foreach (var container in Containers) { containers.AddRange(container.ToContainers(schema, module, address, path, variables)); } return(new ContainerContainer(schema, name, description, address, path, containers)); } }