예제 #1
0
        private static void AddResultsToList(
            ISafeVsObjectList2 objectList, ObjectSearchLanguage searchLanguage, List <VsObjectSearchResult> results)
        {
            uint objectCount;

            if (objectList.GetItemCount(out objectCount) == VSConstants.S_OK)
            {
                for (uint j = 0; j < objectCount; j++)
                {
                    var textPointer = IntPtr.Zero;

                    try
                    {
                        if (objectList.GetText(j, VSTREETEXTOPTIONS.TTO_DEFAULT, out textPointer) == VSConstants.S_OK)
                        {
                            var text = Marshal.PtrToStringUni(textPointer);

                            if (text != null)
                            {
                                string fileName;
                                int    lineNumber;
                                int    columnNumber;

                                // FindAllReferencesList.cs (VS) does not implement the GetSourceContext() API of IVsObjectList2, so as a
                                // workaround we will parse the description text to identify the file and line/col number.
                                if (TryParseSourceData(text, searchLanguage, out fileName, out lineNumber, out columnNumber))
                                {
                                    results.Add(new VsObjectSearchResult(fileName, text, lineNumber, columnNumber));
                                }
                            }
                        }
                    }
                    finally
                    {
                        // If this object implements IVsCoTaskMemFreeMyStrings we *must* free the IntPtr since we were passed a copy
                        // of the string the native code is using. If the object does not implement IVsCoTaskMemFreeMyStrings we
                        //  *must not* free the IntPtr since we are referencing the same string the native code is using.
                        if (textPointer != IntPtr.Zero &&
                            objectList is IVsCoTaskMemFreeMyStrings)
                        {
                            Marshal.FreeCoTaskMem(textPointer);
                        }
                    }
                }
            }
        }
        private static void AddResultsToList(
            ISafeVsObjectList2 objectList, ObjectSearchLanguage searchLanguage, List<VsObjectSearchResult> results)
        {
            uint objectCount;
            if (objectList.GetItemCount(out objectCount) == VSConstants.S_OK)
            {
                for (uint j = 0; j < objectCount; j++)
                {
                    var textPointer = IntPtr.Zero;

                    try
                    {
                        if (objectList.GetText(j, VSTREETEXTOPTIONS.TTO_DEFAULT, out textPointer) == VSConstants.S_OK)
                        {
                            var text = Marshal.PtrToStringUni(textPointer);

                            if (text != null)
                            {
                                string fileName;
                                int lineNumber;
                                int columnNumber;

                                // FindAllReferencesList.cs (VS) does not implement the GetSourceContext() API of IVsObjectList2, so as a
                                // workaround we will parse the description text to identify the file and line/col number.
                                if (TryParseSourceData(text, searchLanguage, out fileName, out lineNumber, out columnNumber))
                                {
                                    results.Add(new VsObjectSearchResult(fileName, text, lineNumber, columnNumber));
                                }
                            }
                        }
                    }
                    finally
                    {
                        // If this object implements IVsCoTaskMemFreeMyStrings we *must* free the IntPtr since we were passed a copy
                        // of the string the native code is using. If the object does not implement IVsCoTaskMemFreeMyStrings we
                        //  *must not* free the IntPtr since we are referencing the same string the native code is using.
                        if (textPointer != IntPtr.Zero
                            && objectList is IVsCoTaskMemFreeMyStrings)
                        {
                            Marshal.FreeCoTaskMem(textPointer);
                        }
                    }
                }
            }
        }