コード例 #1
0
 private string GetPrefix(MemberReference memberReference)
 {
     switch (memberReference.GetKind())
     {
         case MemberReferenceKind.Field:
             return "F";
         case MemberReferenceKind.Method:
             return "M";
         default:
             return memberReference.GetKind().ToString();
     }
 }
コード例 #2
0
        private MemberDependency GetMemberReferenceMemberDependency(MemberReference memberReference)
        {
            var provider = new MemberMetadataInfoTypeProvider(_reader);
            var memberRefInfo = provider.GetMemberRefInfo(memberReference);

            // Add the parent type to the types list (only needed when we want to report memberrefs defined in the current assembly)
            if (memberRefInfo.ParentType.IsTypeDef || (memberRefInfo.ParentType.IsPrimitiveType && _currentAssemblyName.Equals("mscorlib", StringComparison.OrdinalIgnoreCase)))
            {
                MemberDependency.Add(CreateMemberDependency(memberRefInfo.ParentType));
            }

            var dep = new MemberDependency
            {
                CallingAssembly = CallingAssembly,
                MemberDocId = $"{GetPrefix(memberReference)}:{memberRefInfo}",
                TypeDocId = $"T:{memberRefInfo.ParentType}",
                IsPrimitive = memberRefInfo.ParentType.IsPrimitiveType
            };

            if (memberRefInfo.ParentType.IsAssemblySet)
            {
                dep.DefinedInAssemblyIdentity = _reader.FormatAssemblyInfo(memberRefInfo.ParentType.DefinedInAssembly);
            }
            // If no assembly is set, then the type is either a primitive type or it's in the current assembly.
            // Mscorlib is special-cased for testing purposes.
            else if (!memberRefInfo.ParentType.IsPrimitiveType || string.Equals(_currentAssemblyName, "mscorlib", StringComparison.OrdinalIgnoreCase))
            {
                dep.DefinedInAssemblyIdentity = _currentAssemblyInfo;
            }

            return dep;
        }
コード例 #3
0
        public ParseTarget CreateParseTarget(MemberReference memberRef)
        {

            if (memberRef.GetKind() != MemberReferenceKind.Method)
                throw new ArgumentException("Metadata Token does not refer to a method");

            var methodName = Reader.GetString(memberRef.Name);
            if (memberRef.Parent.Kind != HandleKind.TypeReference)
                throw new ArgumentException("Owner of member is not a reference to a type");

            var sig = ILReader.ParseMethodSignature(this, Reader.GetBlobBytes(memberRef.Signature));

#if DEBUG_SIG
            Console.WriteLine("=== Real Sig ===");
            foreach (var b in sig)
                Console.Write("{0:X2} ", b);
            Console.WriteLine();
#endif

            var parent = Reader.GetTypeReference((TypeReferenceHandle)memberRef.Parent);
            if (parent.ResolutionScope.Kind != HandleKind.AssemblyReference)
                throw new ArgumentException("Owner of members resolution scope is not an assembly");

            var parentFqName = GetFullyQualifiedName(parent);
            var parentScope = Reader.GetAssemblyReference((AssemblyReferenceHandle)parent.ResolutionScope);

            var assemblyName = Reader.GetString(parentScope.Name);

            return new ParseTarget(Context, assemblyName, parentScope.Version, parentFqName)
            {
                MethodName = methodName,
                MethodSignature = sig
            };
        }
コード例 #4
0
 public Class ForceResolveType(MemberReference memberRef)
 {
     var target = CreateParseTarget(memberRef);
     return ForceResolveTypeCore(target);
 }
コード例 #5
0
        private MemberDependency GetMemberReferenceMemberDependency(MemberReference memberReference)
        {
            var provider = new MemberMetadataInfoTypeProvider(_reader);
            var memberRefInfo = provider.GetMemberRefInfo(memberReference);

            AssemblyReferenceInformation definedInAssemblyIdentity = null;
            if (memberRefInfo.ParentType.DefinedInAssembly.HasValue)
            {
                definedInAssemblyIdentity = _reader.FormatAssemblyInfo(memberRefInfo.ParentType.DefinedInAssembly.Value);
            }
            // If no assembly is set, then the type is either a primitive type or it's in the current assembly.
            // Mscorlib is special-cased for testing purposes.
            else if (!memberRefInfo.ParentType.IsPrimitiveType || string.Equals(_currentAssemblyName, "mscorlib", StringComparison.OrdinalIgnoreCase))
            {
                definedInAssemblyIdentity = _currentAssemblyInfo;
            }

            // Apply heuristic to determine if API is most likely defined in a framework assembly
            if (!_assemblyFilter.IsFrameworkAssembly(definedInAssemblyIdentity))
            {
                return null;
            }

            // Add the parent type to the types list (only needed when we want to report memberrefs defined in the current assembly)
            if (memberRefInfo.ParentType.IsTypeDef || (memberRefInfo.ParentType.IsPrimitiveType && _currentAssemblyName.Equals("mscorlib", StringComparison.OrdinalIgnoreCase)))
            {
                var memberDependency = CreateMemberDependency(memberRefInfo.ParentType);

                if (memberDependency != null)
                {
                    MemberDependency.Add(memberDependency);
                }
            }

            return new MemberDependency
            {
                CallingAssembly = CallingAssembly,
                MemberDocId = $"{GetPrefix(memberReference)}:{memberRefInfo}",
                TypeDocId = $"T:{memberRefInfo.ParentType}",
                IsPrimitive = memberRefInfo.ParentType.IsPrimitiveType,
                DefinedInAssemblyIdentity = definedInAssemblyIdentity
            };
        }