public MemberSDPModel FormatSingleMember(Member m) { var sdpMember = InitWithBasicProperties <MemberSDPModel>(m); sdpMember.TypeParameters = ConvertTypeParameters(m); sdpMember.ThreadSafety = ConvertThreadSafety(m); sdpMember.ImplementsWithMoniker = m.Implements?.Select(impl => new VersionedString(impl.Monikers, DocIdToTypeMDString(impl.Value, _store))) .Where(impl => impl.Value != null) .ToList().NullIfEmpty(); sdpMember.ImplementsMonikers = ConverterHelper.ConsolidateVersionedValues(sdpMember.ImplementsWithMoniker, m.Monikers); var knowTypeParams = m.Parent.TypeParameters.ConcatList(m.TypeParameters); if (m.ReturnValueType != null) { var returns = m.ReturnValueType; var r = returns.VersionedTypes .Where(v => !string.IsNullOrWhiteSpace(v.Value) && v.Value != "System.Void").ToArray(); if (r.Any()) { foreach (var t in returns.VersionedTypes) { t.Value = SDPYamlConverter.TypeStringToTypeMDString(t.Value, _store); } var returnType = new ReturnValue { VersionedTypes = r, Description = returns.Description }; sdpMember.ReturnsWithMoniker = returnType; } } sdpMember.Parameters = m.Parameters?.Select(p => ConvertNamedParameter(p, knowTypeParams)) .ToList().NullIfEmpty(); sdpMember.Exceptions = m.Docs.Exceptions?.Select( p => new TypeReference() { Description = p.Description, Type = UidToTypeMDString(p.Uid, _store) }).ToList().NullIfEmpty(); sdpMember.Permissions = m.Docs.Permissions?.Select( p => new TypeReference() { Description = p.Description, Type = DocIdToTypeMDString(p.CommentId, _store) }).ToList().NullIfEmpty(); if (m.Attributes != null && m.Attributes.Any(attr => attr.Declaration == "System.CLSCompliant(false)")) { sdpMember.IsNotClsCompliant = true; } sdpMember.AltCompliant = m.Docs.AltCompliant.ResolveCommentId(_store)?.Uid; return(sdpMember); }
public DelegateSDPModel FormatDelegate(Type t) { var sdpDelegate = InitWithBasicProperties <DelegateSDPModel>(t); sdpDelegate.TypeParameters = ConvertTypeParameters(t); sdpDelegate.Inheritances = t.InheritanceChains?.LastOrDefault().Values.Select(uid => UidToTypeMDString(uid, _store)).ToList(); if (t.ReturnValueType != null) { var returns = t.ReturnValueType; var r = returns.VersionedTypes .Where(v => !string.IsNullOrWhiteSpace(v.Value) && v.Value != "System.Void"); if (r.Any()) { foreach (var vt in returns.VersionedTypes) { vt.Value = SDPYamlConverter.TypeStringToTypeMDString(vt.Value, _store); } sdpDelegate.ReturnsWithMoniker = returns; } } sdpDelegate.Parameters = t.Parameters?.Select(p => ConvertNamedParameter(p, t.TypeParameters)) .ToList().NullIfEmpty(); if (t.Attributes != null && t.Attributes.Any(attr => attr.Declaration == "System.CLSCompliant(false)")) { sdpDelegate.IsNotClsCompliant = true; } sdpDelegate.AltCompliant = t.Docs.AltCompliant.ResolveCommentId(_store)?.Uid; if (t.ExtensionMethods?.Count > 0) { sdpDelegate.ExtensionMethods = t.ExtensionMethods.Select(im => ExtensionMethodToTypeMemberLink(t, im)) .Where(ext => ext != null).ToList(); } return(sdpDelegate); }
public static IDictionary <string, List <string> > Generate( ECMAStore store, string outputFolder, bool flatten) { WriteLine("Generating SDP Yaml models..."); if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } var sdpConverter = new SDPYamlConverter(store); sdpConverter.Convert(); WriteLine("Writing SDP Yaml files..."); ConcurrentDictionary <string, List <string> > fileMapping = new ConcurrentDictionary <string, List <string> >(); ParallelOptions po = new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }; Parallel.ForEach(store.Namespaces, po, ns => { Dictionary <string, int> existingFileNames = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); var nsFolder = Path.Combine(outputFolder, ns.Key); if (!string.IsNullOrEmpty(ns.Key) && sdpConverter.NamespacePages.TryGetValue(ns.Key, out var nsPage)) { var nsFileName = Path.Combine(outputFolder, ns.Key + ".yml"); if (!string.IsNullOrEmpty(ns.Value.SourceFileLocalPath)) { fileMapping.TryAdd(ns.Value.SourceFileLocalPath, new List <string> { nsFileName }); } YamlUtility.Serialize(nsFileName, nsPage, nsPage.YamlMime); } if (!flatten && !Directory.Exists(nsFolder)) { Directory.CreateDirectory(nsFolder); } foreach (var t in ns.Value.Types) { if (!string.IsNullOrEmpty(t.Uid) && sdpConverter.TypePages.TryGetValue(t.Uid, out var typePage)) { var tFileName = Path.Combine(flatten ? outputFolder : nsFolder, t.Uid.Replace('`', '-') + ".yml"); var ymlFiles = new List <string>() { tFileName }; YamlUtility.Serialize(tFileName, typePage, typePage.YamlMime); if (t.Members != null) { foreach (var m in t.Members) { if (!string.IsNullOrEmpty(m.Uid) && sdpConverter.OverloadPages.TryGetValue(m.Uid, out var mPage)) { var fileName = PathUtility.ToCleanUrlFileName(m.Uid); fileName = GetUniqueFileNameWithSuffix(fileName, existingFileNames) + ".yml"; var path = Path.Combine(flatten ? outputFolder : nsFolder, fileName); ymlFiles.Add(path); YamlUtility.Serialize(path, mPage, mPage.YamlMime); } } if (t.Overloads != null) { foreach (var ol in t.Overloads) { if (!string.IsNullOrEmpty(ol.Uid) && sdpConverter.OverloadPages.TryGetValue(ol.Uid, out var mPage)) { var fileName = PathUtility.ToCleanUrlFileName(GetNewFileName(t.Uid, ol)); fileName = GetUniqueFileNameWithSuffix(fileName, existingFileNames) + ".yml"; var path = Path.Combine(flatten ? outputFolder : nsFolder, fileName); ymlFiles.Add(path); YamlUtility.Serialize(path, mPage, mPage.YamlMime); } } } } if (!string.IsNullOrEmpty(t.SourceFileLocalPath)) { fileMapping.TryAdd(t.SourceFileLocalPath, ymlFiles); } } } }); WriteLine("Done writing SDP Yaml files."); return(fileMapping); }