Esempio n. 1
0
        public IFileOpenInfo TryGetCecilFileOpenInfo(Type type, MethodInfo methodInfo)
        {
            var assemblyPath = type.Assembly.Location;

            // Get the sequence point directly from the method token (to avoid scanning all types/methods)
            var assemblyDefinition = ReadAssembly(assemblyPath);
            var methodDefinition   = assemblyDefinition.MainModule.LookupToken(methodInfo.MetadataToken) as MethodDefinition;
            var sequencePoint      = GetMethodFirstSequencePoint(methodDefinition);

            var fileOpenInfo = new FileOpenInfo();

            if (sequencePoint != null) // Can be null in case of yield return in target method
            {
                fileOpenInfo.LineNumber = sequencePoint.StartLine;
                fileOpenInfo.FilePath   = sequencePoint.Document.Url;
            }

            return(fileOpenInfo);
        }
Esempio n. 2
0
        public IFileOpenInfo TryGetCecilFileOpenInfo(Type type, MethodInfo methodInfo)
        {
            var assemblyPath = type.Assembly.Location;
            var methodName   = methodInfo.Name;

            // Nested types are appended to the type name in reflection, but not in Cecil
            var typeName = type.FullName ?? string.Empty;

            typeName = typeName.Contains("+") ? typeName.Split('+').First() : typeName;

            var sequencePoint = GetSequencePointForMethod(assemblyPath, typeName, methodName);

            var fileOpenInfo = new FileOpenInfo();

            if (sequencePoint != null) // Can be null in case of yield return in target method
            {
                fileOpenInfo.LineNumber = sequencePoint.StartLine;
                fileOpenInfo.FilePath   = sequencePoint.Document.Url;
            }

            return(fileOpenInfo);
        }