-
Notifications
You must be signed in to change notification settings - Fork 87
/
ExportTypeIdentityConstraint.cs
74 lines (60 loc) · 2.45 KB
/
ExportTypeIdentityConstraint.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
// Copyright (c) Microsoft. All rights reserved.
namespace Microsoft.VisualStudio.Composition
{
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Composition.Reflection;
public class ExportTypeIdentityConstraint : IImportSatisfiabilityConstraint, IDescriptiveToString
{
public ExportTypeIdentityConstraint(Type typeIdentity)
{
Requires.NotNull(typeIdentity, nameof(typeIdentity));
this.TypeIdentityName = ContractNameServices.GetTypeIdentity(typeIdentity);
}
public ExportTypeIdentityConstraint(string typeIdentityName)
{
Requires.NotNullOrEmpty(typeIdentityName, nameof(typeIdentityName));
this.TypeIdentityName = typeIdentityName;
}
public string TypeIdentityName { get; private set; }
public static ImmutableDictionary<string, object> GetExportMetadata(Type type)
{
Requires.NotNull(type, nameof(type));
return GetExportMetadata(ContractNameServices.GetTypeIdentity(type));
}
public static ImmutableDictionary<string, object> GetExportMetadata(string typeIdentity)
{
Requires.NotNullOrEmpty(typeIdentity, nameof(typeIdentity));
return ImmutableDictionary<string, object>.Empty.Add(CompositionConstants.ExportTypeIdentityMetadataName, typeIdentity);
}
public bool IsSatisfiedBy(ExportDefinition exportDefinition)
{
Requires.NotNull(exportDefinition, nameof(exportDefinition));
string value;
if (exportDefinition.Metadata.TryGetValue(CompositionConstants.ExportTypeIdentityMetadataName, out value))
{
return this.TypeIdentityName == value;
}
return false;
}
public void ToString(TextWriter writer)
{
var indentingWriter = IndentingTextWriter.Get(writer);
indentingWriter.WriteLine("TypeIdentityName: {0}", this.TypeIdentityName);
}
public bool Equals(IImportSatisfiabilityConstraint obj)
{
var other = obj as ExportTypeIdentityConstraint;
if (other == null)
{
return false;
}
return this.TypeIdentityName == other.TypeIdentityName;
}
}
}