public bool TryParseValue(Type targetType, object value, out object result) { JsonNode node = (value as JsonNode); if (node != null && node.Type == JsonNodeType.Object) { Type[] genericArgs = targetType.GetGenericArguments(); Type functorType = typeof(Func <, ,>).MakeGenericType(genericArgs[0], genericArgs[1], targetType); Delegate creator = functorType.GetCreator(targetType); List <object> items = CollectionPool <List <object>, object> .Get(); try { node = node.Child; while (node != null) { if (node.Type > JsonNodeType.Array) { object k, v; if (node.Name.TryCast(genericArgs[0], out k) && k != null && node.RawValue.TryCast(genericArgs[1], out v) && v != null) { items.Add(creator.DynamicInvoke(k, v)); } } node = node.Next; } result = items.ToArray(); return(true); } finally { CollectionPool <List <object>, object> .Return(items); } } else { result = null; return(false); } }
public void Dispose() { CollectionPool <Dictionary <PackageId, PackageVersion>, PackageId, PackageVersion> .Return(dependencies); dependencies = null; CollectionPool <Dictionary <PackageId, PackageVersion>, PackageId, PackageVersion> .Return(references); references = null; CollectionPool <HashSet <string>, string> .Return(platform); platform = null; CollectionPool <HashSet <PlatformTarget>, PlatformTarget> .Return(architecture); architecture = null; CollectionPool <HashSet <string>, string> .Return(files); files = null; CollectionPool <HashSet <string>, string> .Return(tags); tags = null; CollectionPool <HashSet <Identity>, Identity> .Return(maintainer); maintainer = null; CollectionPool <Dictionary <string, string>, string, string> .Return(events); events = null; CollectionPool <Dictionary <string, string>, string, string> .Return(parameter); parameter = null; }