Ejemplo n.º 1
0
        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()
            {
                Monikers         = impl.Monikers,
                Value            = DocIdToTypeMDString(impl.Value, _store),
                valuePerLanguage = TypeStringToMDWithTypeMapping(impl.Value, m.Signatures?.DevLangs, nullIfTheSame: true)
            });

            sdpMember.ImplementsMonikers = ConverterHelper.ConsolidateVersionedValues(sdpMember.ImplementsWithMoniker, m.Monikers);

            var knowTypeParams = m.Parent.TypeParameters.ConcatList(m.TypeParameters);

            if (m.ReturnValueType != null)
            {
                sdpMember.ReturnsWithMoniker = ConvertReturnValue(m.ReturnValueType, knowTypeParams, m.Signatures.DevLangs);
            }

            sdpMember.Parameters = m.Parameters?.Select(p => ConvertNamedParameter(p, knowTypeParams, m.Signatures.DevLangs))
                                   .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;
            sdpMember.Type         = m.ItemType.ToString().ToLower();

            return(sdpMember);
        }
Ejemplo n.º 2
0
        public EnumSDPModel FormatEnum(Type enumTypeItem, HashSet <string> memberTouchCache)
        {
            var sdpEnum = InitWithBasicProperties <EnumSDPModel>(enumTypeItem);

            if (_withVersioning)
            {
                sdpEnum.InheritancesWithMoniker = ConverterHelper.TrimMonikers(
                    enumTypeItem.InheritanceChains?.Select(
                        chain => new VersionedCollection <string>(
                            chain.Monikers,
                            chain.Values.Select(uid => UidToTypeMDString(uid, _store)).ToList()
                            )).ToList(),
                    enumTypeItem.Monikers);
            }
            else
            {
                sdpEnum.Inheritances = enumTypeItem.InheritanceChains?.LastOrDefault().Values.Select(uid => UidToTypeMDString(uid, _store)).ToList();
            }

            sdpEnum.IsFlags = enumTypeItem.Attributes != null &&
                              enumTypeItem.Attributes.Any(attr => attr.Declaration == "System.Flags");

            sdpEnum.Fields = enumTypeItem.Members.Select(fItem =>
            {
                var f = new EnumField()
                {
                    Uid          = fItem.Uid,
                    CommentId    = fItem.CommentId,
                    Name         = fItem.DisplayName,
                    NameWithType = enumTypeItem.Name + '.' + fItem.Name,
                    FullName     = fItem.FullDisplayName,
                    Summary      = fItem.Docs.Summary,
                    Monikers     = fItem.Monikers
                };
                if (fItem.Metadata.TryGetValue(OPSMetadata.LiteralValue, out object val))
                {
                    f.LiteralValue = val?.ToString();
                }
                f.LiteralValue = f.LiteralValue ?? "";
                memberTouchCache.Add(f.Uid);

                return(f);
            }).ToList().NullIfEmpty();

            return(sdpEnum);
        }
Ejemplo n.º 3
0
        public TypeSDPModel FormatType(Type t)
        {
            var sdpType = InitWithBasicProperties <TypeSDPModel>(t);

            sdpType.Type           = t.ItemType.ToString().ToLower();
            sdpType.TypeParameters = ConvertTypeParameters(t);
            sdpType.ThreadSafety   = ConvertThreadSafety(t);

            Type child = t;

            sdpType.InheritancesWithMoniker = ConverterHelper.TrimMonikers(
                t.InheritanceChains?.Select(
                    chain => GetInheritChainMDStringList(chain, t)).ToList(),
                t.Monikers);
            sdpType.DerivedClassesWithMoniker = MonikerizeDerivedClasses(t);
            sdpType.ImplementsWithMoniker     = t.Interfaces?.Where(i => i != null && i.Value != null)
                                                .Select(i => new VersionedString()
            {
                Monikers         = i.Monikers,
                Value            = TypeStringToTypeMDString(i.Value, _store),
                valuePerLanguage = TypeStringToMDWithTypeMapping(i.Value, t.Signatures?.DevLangs, nullIfTheSame: true)
            })
                                                .ToList()
                                                .NullIfEmpty();
            sdpType.ImplementsMonikers = ConverterHelper.ConsolidateVersionedValues(sdpType.ImplementsWithMoniker, t.Monikers);

            sdpType.Permissions = t.Docs.Permissions?.Select(
                p => new TypeReference()
            {
                Description = p.Description,
                Type        = DocIdToTypeMDString(p.CommentId, _store)
            })
                                  .ToList()
                                  .NullIfEmpty();

            if (t.Attributes != null &&
                t.Attributes.Any(attr => attr.Declaration == "System.CLSCompliant(false)"))
            {
                sdpType.IsNotClsCompliant = true;
            }
            sdpType.AltCompliant = t.Docs.AltCompliant.ResolveCommentId(_store)?.Uid;

            PopulateTypeChildren(t, sdpType);

            return(sdpType);
        }
Ejemplo n.º 4
0
        private T InitWithBasicProperties <T>(ReflectionItem item) where T : ItemSDPModelBase, new()
        {
            T rval = new T
            {
                Uid       = item.Uid,
                CommentId = item.CommentId,
                Name      = item.Name,
                DevLangs  = item.Signatures?.DevLangs ?? defaultLangList,

                SeeAlso  = BuildSeeAlsoList(item.Docs, _store),
                Summary  = item.Docs.Summary,
                Remarks  = item.Docs.Remarks,
                Examples = item.Docs.Examples,
                Monikers = item.Monikers,
                Source   = (_store.UWPMode || _store.DemoMode) ?item.SourceDetail.ToSDPSourceDetail() : null
            };

            if (_withVersioning)
            {
                rval.AssembliesWithMoniker = _store.UWPMode ? null : MonikerizeAssemblyStrings(item);
                rval.PackagesWithMoniker   = _store.UWPMode ? null : MonikerizePackageStrings(item, _store.PkgInfoMapping);
                rval.AttributesWithMoniker = item.Attributes?.Where(att => att.Visible)
                                             .Select(att => new VersionedString()
                {
                    Value = att.TypeFullName, Monikers = att.Monikers?.ToHashSet()
                })
                                             .DistinctVersionedString()
                                             .ToList().NullIfEmpty();
                rval.AttributeMonikers = ConverterHelper.ConsolidateVersionedValues(rval.AttributesWithMoniker, item.Monikers);
                rval.SyntaxWithMoniker = ConverterHelper.BuildVersionedSignatures(item, uwpMode: _store.UWPMode)?.NullIfEmpty();
            }
            else
            {
                rval.Assemblies = _store.UWPMode ? null : item.AssemblyInfo?.Select(asm => asm.Name).Distinct().ToList();
                rval.Attributes = item.Attributes?.Where(att => att.Visible).Select(att => att.TypeFullName)
                                  .ToList().NullIfEmpty();
                var rawSignatures = ConverterHelper.BuildSignatures(item, uwpMode: _store.UWPMode);
                rval.Syntax = rawSignatures?.Select(sig => new SignatureModel()
                {
                    Lang = sig.Key, Value = sig.Value
                }).ToList();
            }

            switch (item)
            {
            case Member m:
                rval.Namespace    = string.IsNullOrEmpty(m.Parent.Parent.Name) ? null : m.Parent.Parent.Name;
                rval.FullName     = m.FullDisplayName;
                rval.Name         = m.DisplayName;
                rval.NameWithType = m.Parent.Name + '.' + m.DisplayName;
                break;

            case ECMA2Yaml.Models.Type t:
                rval.Namespace    = string.IsNullOrEmpty(t.Parent.Name) ? null : t.Parent.Name;
                rval.FullName     = t.FullName;
                rval.NameWithType = t.FullName;
                var children = t.ItemType == ItemType.Enum
                        ? t.Members.Cast <ReflectionItem>().ToList()
                        : null;
                GenerateRequiredMetadata(rval, item, children);
                break;

            case Namespace n:
                rval.Namespace = n.Name;
                rval.FullName  = n.Name;
                GenerateRequiredMetadata(rval, item);
                break;
            }

            if (item.Metadata.TryGetValue(OPSMetadata.InternalOnly, out object val))
            {
                rval.IsInternalOnly = (bool)val;
            }

            if (item.Metadata.TryGetValue(OPSMetadata.AdditionalNotes, out object notes))
            {
                rval.AdditionalNotes = (AdditionalNotes)notes;
            }

            if (item.Attributes != null)
            {
                rval.ObsoleteMessagesWithMoniker = item.Attributes
                                                   .Where(attr => attr.TypeFullName == "System.ObsoleteAttribute")
                                                   .Select(attr => new VersionedString()
                {
                    Value    = GenerateObsoleteNotification(attr.Declaration),
                    Monikers = attr.Monikers
                })
                                                   .ToList().NullIfEmpty();
            }

            if (_store.UWPMode || _store.DemoMode)
            {
                GenerateUWPRequirements(rval, item);
            }

            return(rval);
        }
Ejemplo n.º 5
0
        public TypeSDPModel FormatType(Type t)
        {
            var sdpType = InitWithBasicProperties <TypeSDPModel>(t);

            sdpType.Type           = t.ItemType.ToString().ToLower();
            sdpType.TypeParameters = ConvertTypeParameters(t);
            sdpType.ThreadSafety   = ConvertThreadSafety(t);

            if (_withVersioning)
            {
                Type child = t;
                sdpType.InheritancesWithMoniker = ConverterHelper.TrimMonikers(
                    t.InheritanceChains?.Select(
                        chain => new VersionedCollection <string>(
                            chain.Monikers?.NullIfEmpty(),
                            GetInheritChainMDStringList(chain.Values, t)
                            )).ToList(),
                    t.Monikers);
                sdpType.DerivedClassesWithMoniker = MonikerizeDerivedClasses(t);
                sdpType.ImplementsWithMoniker     = t.Interfaces?.Where(i => i != null && i.Value != null)
                                                    .Select(i => new VersionedString(i.Monikers, TypeStringToTypeMDString(i.Value, _store)))
                                                    .ToList()
                                                    .NullIfEmpty();
                sdpType.ImplementsMonikers = ConverterHelper.ConsolidateVersionedValues(sdpType.ImplementsWithMoniker, t.Monikers);
            }
            else
            {
                sdpType.Inheritances = t.InheritanceChains?.LastOrDefault()?.Values.Select(uid => UidToTypeMDString(uid, _store))
                                       .ToList()
                                       .NullIfEmpty();

                //not top level class like System.Object, has children
                if (t.ItemType == ItemType.Interface &&
                    _store.ImplementationChildrenByUid.ContainsKey(t.Uid))
                {
                    sdpType.DerivedClasses = _store.ImplementationChildrenByUid[t.Uid].Select(v => v.Value).ToList();
                }
                else if (_store.InheritanceParentsByUid.ContainsKey(t.Uid) &&
                         _store.InheritanceParentsByUid[t.Uid]?.Count > 0 &&
                         _store.InheritanceChildrenByUid.ContainsKey(t.Uid))
                {
                    sdpType.DerivedClasses = _store.InheritanceChildrenByUid[t.Uid].Select(v => v.Value).ToList();
                }
                sdpType.Implements = t.Interfaces?.Where(i => i != null && i.Value != null)
                                     .Select(i => TypeStringToTypeMDString(i.Value, _store))
                                     .ToList()
                                     .NullIfEmpty();
            }

            sdpType.Permissions = t.Docs.Permissions?.Select(
                p => new TypeReference()
            {
                Description = p.Description,
                Type        = DocIdToTypeMDString(p.CommentId, _store)
            })
                                  .ToList()
                                  .NullIfEmpty();

            if (t.Attributes != null &&
                t.Attributes.Any(attr => attr.Declaration == "System.CLSCompliant(false)"))
            {
                sdpType.IsNotClsCompliant = true;
            }
            sdpType.AltCompliant = t.Docs.AltCompliant.ResolveCommentId(_store)?.Uid;

            PopulateTypeChildren(t, sdpType);

            return(sdpType);
        }