예제 #1
0
        public IEnumerable <IField> ToFields(ModuleJson module, ModuleOffset offset)
        {
            AssertNotNull(ResolvedName);
            AssertNotNull(ResolvedDescription);

            if (Repeat is null)
            {
                yield return(ToField(module, ResolvedName, ResolvedDescription, offset));
            }
            else
            {
                Preconditions.AssertNotNull(Repeat.Items);
                var variables = SchemaVariables.Empty;
                int?gap       = Repeat.Gap?.Value;
                foreach (var tuple in module.GetRepeatSequence(Repeat.Items, variables))
                {
                    var itemVariables = variables.WithVariable(Repeat.IndexVariable, tuple.index);

                    var formattedDescription = tuple.variables.Replace(ResolvedDescription);
                    var formattedName        = Invariant($"{ResolvedName}[{tuple.index}]");
                    var field = ToField(module, formattedName, formattedDescription, offset);
                    yield return(field);

                    offset += gap ?? field.Size;
                }
            }
        }
예제 #2
0
        internal IEnumerable <TreeNode> ToTreeNodes(ModuleJson json, string?parentNodePath, IContainer parentContainer)
        {
            Preconditions.AssertNotNull(Name);
            Preconditions.AssertNotNull(Path);
            Preconditions.AssertNotNull(Format);
            if (Repeat is null)
            {
                yield return(ToTreeNode(json, Name, parentContainer, SchemaVariables.Empty));
            }
            else
            {
                foreach (var tuple in json.GetRepeatSequence(Repeat, SchemaVariables.Empty))
                {
                    string name = Invariant($"{Name}[{tuple.index}]");
                    yield return(ToTreeNode(json, name, parentContainer, tuple.variables));
                }
            }

            TreeNode ToTreeNode(ModuleJson json, string name, IContainer parentContainer, SchemaVariables variables)
            {
                string nodePath              = PathUtilities.AppendPath(parentNodePath, name);
                string?midiNotePath          = MidiNotePath is null ? null : variables.Replace(MidiNotePath);
                var    resolvedContainerPath = variables.Replace(Path !);
                var    container             = parentContainer.ResolveContainer(resolvedContainerPath);
                var    formattableString     = FieldFormattableString.Create(container, Format !, FormatPaths, variables);

                var childTreeNodes = new List <TreeNode>();

                foreach (var child in Children)
                {
                    childTreeNodes.AddRange(child.ToTreeNodes(json, nodePath, container));
                }
                var treeDetails = Details.Select(detail => detail.ToNodeDetail(json, container, variables)).ToList().AsReadOnly();

                return(new TreeNode(name, nodePath, container, formattableString, midiNotePath, childTreeNodes.AsReadOnly(), treeDetails));
            }
        }
예제 #3
0
 public override HexInt32 ReadJson(JsonReader reader, Type objectType, HexInt32 existingValue, bool hasExistingValue, JsonSerializer serializer) =>
 HexInt32.Parse(Preconditions.AssertNotNull((string?)reader.Value));