forked from OmniSharp/omnisharp-roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMefValueProvider.cs
More file actions
36 lines (32 loc) · 1.21 KB
/
MefValueProvider.cs
File metadata and controls
36 lines (32 loc) · 1.21 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
using System.Collections.Generic;
using System.Composition.Hosting.Core;
using System.Linq;
namespace OmniSharp.Mef
{
internal class MefValueProvider<T> : ExportDescriptorProvider
{
private readonly T _item;
private readonly IDictionary<string, object> _metadata;
public MefValueProvider(T item, IDictionary<string, object> metadata)
{
_item = item;
_metadata = metadata;
}
public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor)
{
if (contract.ContractType == typeof(T))
{
yield return new ExportDescriptorPromise(contract, string.Empty, true,
() => Enumerable.Empty<CompositionDependency>(),
deps => ExportDescriptor.Create((context, operation) => _item, _metadata ?? new Dictionary<string, object>()));
}
}
}
internal static class MefValueProvider
{
public static MefValueProvider<T> From<T>(T value, IDictionary<string, object> metadata = null)
{
return new MefValueProvider<T>(value, metadata);
}
}
}