forked from git-tfs/git-tfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTfsApiBridge.cs
42 lines (35 loc) · 1.25 KB
/
TfsApiBridge.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
using System.Collections;
using System.Linq;
using Sep.Git.Tfs.Core.TfsInterop;
using StructureMap;
namespace Sep.Git.Tfs.VsCommon
{
public class TfsApiBridge
{
private readonly IContainer _container;
public TfsApiBridge(IContainer container)
{
_container = container;
}
public TWrapper Wrap<TWrapper, TWrapped>(TWrapped wrapped) where TWrapper : class
{
return wrapped == null ? null : _container.With(this).With(wrapped).GetInstance<TWrapper>();
}
public TWrapper[] Wrap<TWrapper, TWrapped>(IEnumerable wrapped) where TWrapper : class
{
return wrapped == null ? null : wrapped.OfType<TWrapped>().Select(x => Wrap<TWrapper, TWrapped>(x)).ToArray();
}
public TTfs Unwrap<TTfs>(object wrapper) where TTfs : class
{
return wrapper == null ? null : ((WrapperFor<TTfs>) wrapper).Unwrap();
}
public TTfs[] Unwrap<TTfs>(IEnumerable wrappers) where TTfs : class
{
return wrappers == null ? null : wrappers.Cast<object>().Select(x => Unwrap<TTfs>(x)).ToArray();
}
public TEnum Convert<TEnum>(object originalEnum)
{
return (TEnum) originalEnum;
}
}
}