Repository navigation
Expand file tree
/
Copy pathBasicExtensions.cs
More file actions
69 lines (58 loc) · 1.72 KB
/
Copy pathBasicExtensions.cs
File metadata and controls
69 lines (58 loc) · 1.72 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
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
using System;
using System.Collections.Generic;
using StructureMap.Pipeline;
namespace StructureMap
{
internal static class BasicExtensions
{
public static TReturn FirstValue<TItem, TReturn>(this IEnumerable<TItem> enumerable, Func<TItem, TReturn> func)
where TReturn : class
{
foreach (var item in enumerable)
{
var @object = func(item);
if (@object != null) return @object;
}
return null;
}
public static string ToName(this ILifecycle lifecycle)
{
if (lifecycle == null) throw new ArgumentNullException("lifecycle");
return lifecycle.Description;
}
public static void Fill<T>(this IList<T> list, T value)
{
if (list.Contains(value)) return;
list.Add(value);
}
public static void SafeDispose(this object target)
{
var disposable = target as IDisposable;
if (disposable == null) return;
try
{
disposable.Dispose();
}
catch (Exception)
{
}
}
public static void TryGet<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key,
Action<TValue> action)
{
TValue value;
if (dictionary.TryGetValue(key, out value))
{
action(value);
}
}
internal static T As<T>(this object target) where T : class
{
return target as T;
}
public static bool IsIn<T>(this T target, IList<T> list)
{
return list.Contains(target);
}
}
}