private PackageReference ParseParametersDependency(IValue dependency) { if (dependency.IsTable()) { var valueTable = dependency.AsTable(); // Get the require fields if (valueTable.TryGetValue("Reference", out var referenceValue)) { if (referenceValue.IsString()) { return(PackageReference.Parse(referenceValue.AsString())); } else { throw new InvalidOperationException("Recipe dependency Reference must be type String."); } } else { throw new InvalidOperationException("Parameter dependency table missing required Reference value."); } } else { throw new InvalidOperationException("Unknown Parameters dependency type."); } }
private static void WriteValue(BinaryWriter writer, IValue value) { // Write the value type writer.Write((uint)value.Type); switch (value.Type) { case ValueType.Table: WriteValue(writer, value.AsTable()); break; case ValueType.List: WriteValue(writer, value.AsList()); break; case ValueType.String: WriteValue(writer, value.AsString()); break; case ValueType.Integer: writer.Write(value.AsInteger()); break; case ValueType.Float: writer.Write(value.AsFloat()); break; case ValueType.Boolean: WriteValue(writer, value.AsBoolean()); break; default: throw new InvalidOperationException("Unknown ValueType"); } }
private (PackageReference Reference, bool ExcludeRuntime) ParseRecipeDependency(IValue dependency) { // A dependency can either be a string or a table with reference key if (dependency.IsString()) { return(PackageReference.Parse(dependency.AsString()), false); } else if (dependency.IsTable()) { var valueTable = dependency.AsTable(); // Check for optional fields bool excludeRuntime = false; if (valueTable.TryGetValue("ExcludeRuntime", out var excludeRuntimeValue)) { excludeRuntime = excludeRuntimeValue.AsBoolean(); } // Get the require fields if (valueTable.TryGetValue("Reference", out var referenceValue)) { if (referenceValue.IsString()) { return(PackageReference.Parse(referenceValue.AsString()), excludeRuntime); } else { throw new InvalidOperationException("Recipe dependency Reference must be type String."); } } else { throw new InvalidOperationException("Recipe dependency table missing required Reference value."); } } else { throw new InvalidOperationException("Unknown Recipe dependency type."); } }