/// <summary> /// Builds a JSON representation of all entry points and components of the <paramref name="catalog"/>. /// </summary> /// <param name="ectx">The exception context to use</param> /// <param name="catalog">The module catalog</param> public static JObject BuildAllManifests(IExceptionContext ectx, ModuleCatalog catalog) { Contracts.CheckValueOrNull(ectx); ectx.CheckValue(catalog, nameof(catalog)); var jEntryPoints = new JArray(); var entryPointInfos = catalog.AllEntryPoints().ToArray(); foreach (var entryPointInfo in entryPointInfos.OrderBy(x => x.Name)) { jEntryPoints.Add(BuildEntryPointManifest(ectx, entryPointInfo, catalog)); } var jKinds = new JArray(); foreach (var kind in catalog.GetAllComponentKinds()) { var jKind = new JObject(); jKind[FieldNames.Kind] = kind; var jComponents = new JArray(); foreach (var component in catalog.GetAllComponents(kind)) { jComponents.Add(BuildComponentManifest(ectx, component, catalog)); } jKind[FieldNames.Components] = jComponents; jKinds.Add(jKind); } var jepKinds = new JArray(); var kinds = new List <Type>(); foreach (var entryPointInfo in entryPointInfos) { if (entryPointInfo.InputKinds != null) { kinds.AddRange(entryPointInfo.InputKinds); } if (entryPointInfo.OutputKinds != null) { kinds.AddRange(entryPointInfo.OutputKinds); } } foreach (var epKind in kinds.Distinct().OrderBy(k => k.Name)) { var jepKind = new JObject(); jepKind[FieldNames.Kind] = epKind.Name; var jepKindFields = new JArray(); var propertyInfos = epKind.GetProperties().AsEnumerable(); propertyInfos = epKind.GetInterfaces().Aggregate(propertyInfos, (current, face) => current.Union(face.GetProperties())); foreach (var fieldInfo in propertyInfos) { var jField = new JObject(); jField[FieldNames.Name] = fieldInfo.Name; var type = CSharpGeneratorUtils.ExtractOptionalOrNullableType(fieldInfo.PropertyType); // Dive inside Var. if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Var <>)) { type = type.GetGenericArguments()[0]; } var typeEnum = TlcModule.GetDataType(type); jField[FieldNames.Type] = typeEnum.ToString(); jepKindFields.Add(jField); } jepKind[FieldNames.Settings] = jepKindFields; jepKinds.Add(jepKind); } var jResult = new JObject(); jResult[FieldNames.TopEntryPoints] = jEntryPoints; jResult[FieldNames.TopComponents] = jKinds; jResult[FieldNames.TopEntryPointKinds] = jepKinds; return(jResult); }