protected override void Completed() { if (_isStruct) { // Use the first value as the template. var template = (IStructValue)_virtualValues[0]; Value = template.Bridge(bridgeArgs => { // Get the workshop values. var steppedValues = _virtualValues // Do not need to calculate GetValueWithPath, already known via bridgeArgs.Value .Skip(1) // Step into the overrider values with the path provided by bridgeArgs. .Select(value => IStructValue.GetValueWithPath((IStructValue)value, bridgeArgs.Path)) // Prepend the template value. .Prepend(bridgeArgs.Value); return(CreateVirtualMap(steppedValues)); }); } else { Value = CreateVirtualMap(_virtualValues); } }
static StructArray MakeEmptyArray(IWorkshopTree value) { if (value is Element element) { if (element.Function.Name == "Empty Array" || element.Function.Name == "Null") { return(new StructArray(new IStructValue[0])); } else if (element.Function.Name == "Array") { var arr = new IStructValue[element.ParameterValues.Length]; for (int i = 0; i < element.ParameterValues.Length; i++) { arr[i] = MakeEmptyArray(element.ParameterValues[i]); if (arr[i] == null) { return(null); } } return(new StructArray(arr)); } } return(null); }
public void Write(XmlWriter writer, List <V> value) { IStructValue structValue = this.ValueMetadata as IStructValue; string itemTag = structValue?.StructType.Name ?? "Item"; for (int i = 0; i < value.Count; i++) { writer.WriteStartElement(itemTag); this.ValueMetadata.Write(writer, value[i]); writer.WriteEndElement(); } }
public void Write(XElement xe, List <V> value) { IStructValue structValue = this.ValueMetadata as IStructValue; string itemTag = structValue?.StructType.Name ?? "Item"; for (int i = 0; i < value.Count; i++) { XElement ce = new XElement(itemTag); this.ValueMetadata.Write(ce, value[i]); xe.Add(ce); } }
public void Write(XmlWriter writer, HashSet <V> value) { IStructValue structValue = this.ValueMetadata as IStructValue; string itemTag = structValue?.StructType.Name ?? "Item"; foreach (V item in value) { writer.WriteStartElement(itemTag); this.ValueMetadata.Write(writer, item); writer.WriteEndElement(); } }
public void Write(XElement xe, HashSet <V> value) { IStructValue structValue = this.ValueMetadata as IStructValue; string itemTag = structValue?.StructType.Name ?? "Item"; foreach (V item in value) { XElement ce = new XElement(itemTag); this.ValueMetadata.Write(ce, item); xe.Add(ce); } }
public Struct ReadBinary(StructDescription desc, StructDescription[] structs, string binary, ref int position) { IStructValue[] values = new IStructValue[desc.types.Length]; for (int i = 0; i < values.Length; i++) { string type = desc.types[i]; if (binaryTypes.ContainsKey(type)) { values[i] = new CustomStructValue(binaryTypes[type].ReadType(binary, ref position), type); } else { var st = structs.First(s => s.name.Equals(type)); values[i] = ReadBinary(st, structs, binary, ref position); } } return(new Struct(desc.name, desc.types, values)); }
public GettableAssignerResult GetResult(GettableAssignerValueInfo info) { IStructValue initialValue = null; // Set the initial value. // If an initial value is provided, use that. if (info.InitialValueOverride != null) { initialValue = ValueInArrayToWorkshop.ExtractStructValue(info.InitialValueOverride); } // Otherwise, use the default initial value if it exists. else if (_attributes.DefaultValue != null) { initialValue = ValueInArrayToWorkshop.ExtractStructValue(_attributes.DefaultValue.Parse(info.ActionSet)); } // 'initialValue' may still be null. bool inline = info.Inline || _attributes.StoreType == StoreType.None; var values = new Dictionary <string, IGettable>(); foreach (var var in _variables) { // Get the child gettable. values.Add( var.Name, var.GetAssigner(new(info.ActionSet, _attributes.Name + "_")) .GetValue(new GettableAssignerValueInfo( actionSet: info.ActionSet, setInitialValue: info.SetInitialValue, initialValue: initialValue?.GetValue(var.Name), inline: inline, indexReferenceCreator: info.IndexReferenceCreator, isGlobal: info.IsGlobal, isRecursive: info.IsRecursive))); } return(new GettableAssignerResult(new StructAssignerValue(values), null)); }
public IWorkshopTree[] GetAllValues() => IStructValue.ExtractAllValues(_children.Select(child => child.Value.GetVariable()));