Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 67fcf8d

Browse files
committed
Add custom export attribute that only exports for a named process
This lets us define exports that are available inside Visual Studio but not Blend.
1 parent bf27bc6 commit 67fcf8d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.ComponentModel.Composition;
4+
5+
namespace GitHub.Exports
6+
{
7+
/// <summary>
8+
/// Only expose export when executing in specific named process.
9+
/// </summary>
10+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
11+
public sealed class ExportForProcessAttribute : ExportAttribute
12+
{
13+
/// <summary>
14+
/// Define an export that is only exposed in a specific named process.
15+
/// </summary>
16+
/// <param name="contractType">The contract type to expose.</param>
17+
/// <param name="processName">Name of the process to expose export from (e.g. 'devenv').</param>
18+
public ExportForProcessAttribute(Type contractType, string processName) : base(ExportForProcess(contractType, processName))
19+
{
20+
ProcessName = processName;
21+
}
22+
23+
static Type ExportForProcess(Type contractType, string processName)
24+
{
25+
return Process.GetCurrentProcess().ProcessName == processName ? contractType : null;
26+
}
27+
28+
/// <summary>
29+
/// The process name export will be exposed in.
30+
/// </summary>
31+
public string ProcessName { get; }
32+
}
33+
}

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
<Reference Include="WindowsBase" />
130130
</ItemGroup>
131131
<ItemGroup>
132+
<Compile Include="Exports\ExportForProcess.cs" />
132133
<Compile Include="GlobalCommands.cs" />
133134
<Compile Include="Models\DiffChangeType.cs" />
134135
<Compile Include="Models\DiffChunk.cs" />

0 commit comments

Comments
 (0)