-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReferencesExtender.cs
79 lines (62 loc) · 1.92 KB
/
ReferencesExtender.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using EnvDTE;
using Microsoft.VisualStudio.Shell.Interop;
using Skyline.VSX.ProtocolEditor.Tools.Extensions;
namespace Skyline.VSX.ProtocolEditor.PropertyExtenders
{
[ComVisible(true)] // Important!
public class ReferencesExtender
{
public const string ExtenderName = "Example_ReferencesExtender";
private readonly VSLangProj.Reference _reference;
private readonly IExtenderSite _extenderSite;
private readonly int _cookie;
private readonly IVsBuildPropertyStorage _propertyStorage;
private readonly uint _itemId;
private bool _disposed;
public ReferencesExtender(VSLangProj.Reference reference, IExtenderSite extenderSite, int cookie)
{
_reference = reference;
_extenderSite = extenderSite;
_cookie = cookie;
//Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
IVsBrowseObject browseObject = reference as IVsBrowseObject;
if (browseObject != null)
{
browseObject.GetProjectItem(out IVsHierarchy hierarchyItem, out uint itemId);
_propertyStorage = (IVsBuildPropertyStorage)hierarchyItem;
_itemId = itemId;
}
}
// These attributes supply the property with some information
[DisplayName("CustomDLLPath")]
[Category("Custom")]
[Description(@"Allows to specify a custom value.")]
[Editor(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string CustomDllPath
{
get { return _propertyStorage.GetItemAttribute<string>(_itemId, nameof(CustomDllPath), null); }
set { _propertyStorage.SetItemAttribute<string>(_itemId, nameof(CustomDllPath), value, null); }
}
~ReferencesExtender()
{
Dispose();
}
public void Dispose()
{
if (_disposed) return;
try
{
_extenderSite.NotifyDelete(_cookie);
}
catch (Exception)
{
// ignore
}
GC.SuppressFinalize(this);
_disposed = true;
}
}
}