-
Notifications
You must be signed in to change notification settings - Fork 87
/
ExportMetadataValueImportConstraint.cs
60 lines (49 loc) · 1.75 KB
/
ExportMetadataValueImportConstraint.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
// Copyright (c) Microsoft. All rights reserved.
namespace Microsoft.VisualStudio.Composition
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ExportMetadataValueImportConstraint : IImportSatisfiabilityConstraint, IDescriptiveToString
{
public ExportMetadataValueImportConstraint(string name, object value)
{
Requires.NotNullOrEmpty(name, nameof(name));
this.Name = name;
this.Value = value;
}
public string Name { get; private set; }
public object Value { get; private set; }
public bool IsSatisfiedBy(ExportDefinition exportDefinition)
{
Requires.NotNull(exportDefinition, nameof(exportDefinition));
object exportMetadataValue;
if (exportDefinition.Metadata.TryGetValue(this.Name, out exportMetadataValue))
{
if (EqualityComparer<object>.Default.Equals(this.Value, exportMetadataValue))
{
return true;
}
}
return false;
}
public bool Equals(IImportSatisfiabilityConstraint obj)
{
var other = obj as ExportMetadataValueImportConstraint;
if (other == null)
{
return false;
}
return this.Name == other.Name
&& EqualityComparer<object>.Default.Equals(this.Value, other.Value);
}
public void ToString(TextWriter writer)
{
var indentingWriter = IndentingTextWriter.Get(writer);
indentingWriter.WriteLine("{0} = {1}", this.Name, this.Value);
}
}
}