forked from FortuneN/FineCodeCoverage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectFilePropertyWriter.cs
More file actions
40 lines (34 loc) · 1.66 KB
/
ProjectFilePropertyWriter.cs
File metadata and controls
40 lines (34 loc) · 1.66 KB
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
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio;
using System.ComponentModel.Composition;
namespace FineCodeCoverage.Core.Utilities
{
[Export(typeof(IProjectFilePropertyWriter))]
public class ProjectFilePropertyWriter : IProjectFilePropertyWriter
{
public async System.Threading.Tasks.Task<bool> WritePropertyAsync(IVsHierarchy projectHierarchy, string propertyName, string value)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (projectHierarchy is IVsBuildPropertyStorage vsBuildPropertyStorage)
{
var result = vsBuildPropertyStorage.GetPropertyValue(propertyName, string.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE, out var v);
if (result == VSConstants.S_OK && v == value)
{
return true;
}
return vsBuildPropertyStorage.SetPropertyValue(propertyName, string.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE, value) == VSConstants.S_OK;
}
return false;
}
public async System.Threading.Tasks.Task<bool> RemovePropertyAsync(IVsHierarchy pHierProj, string propertyName)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (pHierProj is IVsBuildPropertyStorage vsBuildPropertyStorage)
{
return vsBuildPropertyStorage.RemoveProperty(propertyName, string.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE) == VSConstants.S_OK;
}
return false;
}
}
}