public bool MoveNext() { _MoveNextRow: // Is this the start of a new row? if (InitializeRow) { // Are we out of rows? if (!NameEnumerator.MoveNext()) { return(false); } // Get the new row. RowIndex++; ColumnIndex = -1; ObjectEnumerator = CurrentSource.GetEnumerator(); InitializeRow = false; } // Is this the last column? if (!ObjectEnumerator.MoveNext()) { // Attempt to get the next row. InitializeRow = true; goto _MoveNextRow; } Current = ObjectEnumerator.Current; ColumnIndex++; return(true); }
public JSONSchema(JsonElement root, bool isTopLevel) { if (root.ValueKind != JsonValueKind.Object) { throw new ArgumentException("Invalid Json Schema"); } ObjectEnumerator objectEnumerator = root.EnumerateObject(); while (objectEnumerator.MoveNext()) { JsonProperty current = objectEnumerator.Current; if (expectedJsonValueKinds.ContainsKey(current.Name) && expectedJsonValueKinds[current.Name].Contains(current.Value.ValueKind)) { settersDictionary[current.Name].Invoke(this, current.Value); } else { Console.WriteLine($"Invalid JSON Schema. {current.Name} is not a supported JsonSchema property"); } } if (isTopLevel) { ReplaceRefs(this, this); } }
protected sealed override Object EvaluateCore( EvaluationContext context, out ResultMemory resultMemory) { resultMemory = null; var result = new StringBuilder(); var memory = new MemoryCounter(this, context.Options.MaxMemory); var current = Parameters[0].Evaluate(context); var ancestors = new Stack <ICollectionEnumerator>(); do { // Descend as much as possible while (true) { // Collection if (current.TryGetCollectionInterface(out Object collection)) { // Array if (collection is IReadOnlyArray array) { if (array.Count > 0) { // Write array start WriteArrayStart(result, memory, ancestors); // Move to first item var enumerator = new ArrayEnumerator(context, current, array); enumerator.MoveNext(); ancestors.Push(enumerator); current = enumerator.Current; } else { // Write empty array WriteEmptyArray(result, memory, ancestors); break; } } // Mapping else if (collection is IReadOnlyObject obj) { if (obj.Count > 0) { // Write mapping start WriteMappingStart(result, memory, ancestors); // Move to first pair var enumerator = new ObjectEnumerator(context, current, obj); enumerator.MoveNext(); ancestors.Push(enumerator); // Write mapping key WriteMappingKey(context, result, memory, enumerator.Current.Key, ancestors); // Move to mapping value current = enumerator.Current.Value; } else { // Write empty mapping WriteEmptyMapping(result, memory, ancestors); break; } } else { throw new NotSupportedException($"Unexpected type '{collection?.GetType().FullName}'"); } } // Not a collection else { // Write value WriteValue(context, result, memory, current, ancestors); break; } } // Next sibling or ancestor sibling do { if (ancestors.Count > 0) { var parent = ancestors.Peek(); // Parent array if (parent is ArrayEnumerator arrayEnumerator) { // Move to next item if (arrayEnumerator.MoveNext()) { current = arrayEnumerator.Current; break; } // Move to parent else { ancestors.Pop(); current = arrayEnumerator.Array; // Write array end WriteArrayEnd(result, memory, ancestors); } } // Parent mapping else if (parent is ObjectEnumerator objectEnumerator) { // Move to next pair if (objectEnumerator.MoveNext()) { // Write mapping key WriteMappingKey(context, result, memory, objectEnumerator.Current.Key, ancestors); // Move to mapping value current = objectEnumerator.Current.Value; break; } // Move to parent else { ancestors.Pop(); current = objectEnumerator.Object; // Write mapping end WriteMappingEnd(result, memory, ancestors); } } else { throw new NotSupportedException($"Unexpected type '{parent?.GetType().FullName}'"); } } else { current = null; } } while (current != null); } while (current != null); return(result.ToString()); }
static async Task Main(string[] args) { XmlDocument doc = new XmlDocument(); Console.WriteLine(args[0]); FileStream fs = new FileStream(args[0], FileMode.Open, FileAccess.Read); doc.Load(fs); XmlNodeList nodes = doc.GetElementsByTagName("PackageReference"); for (int i = 0; i < nodes.Count; i++) { string packageName = nodes[i].Attributes.GetNamedItem("Include").Value; Console.WriteLine(packageName); Version packageVersion; if (nodes[i].Attributes.GetNamedItem("Version") != null) { Version.TryParse(nodes[i].Attributes.GetNamedItem("Version").Value, out packageVersion); List <Version> allTheVersions = new List <Version>(); HttpClient client = new HttpClient(); HttpResponseMessage message = await client.GetAsync($"https://api-v2v3search-0.nuget.org/search/query?q=packageid:{packageName.ToLowerInvariant()}&ignoreFilter=true"); string json = await message.Content.ReadAsStringAsync(); JsonDocument packageDoc = await System.Text.Json.JsonDocument.ParseAsync(await message.Content.ReadAsStreamAsync()); JsonElement root = packageDoc.RootElement; ObjectEnumerator oe = root.EnumerateObject(); while (oe.MoveNext()) { if (oe.Current.Name == "data") { ArrayEnumerator ae = oe.Current.Value.EnumerateArray(); while (ae.MoveNext()) { ObjectEnumerator re = ae.Current.EnumerateObject(); while (re.MoveNext()) { if (re.Current.Name == "Version") { Version v; if (Version.TryParse(re.Current.Value.GetString(), out v)) { allTheVersions.Add(v); } } } } var newerVersions = allTheVersions.Where(ver => ver.CompareTo(packageVersion) > 0); foreach (Version newerVersion in newerVersions) { Console.WriteLine($"{packageName} - {newerVersion}"); } } } } } }