- Notifications
You must be signed in to change notification settings - Fork 549
/
Copy pathAssemblyExtensions.cs
53 lines (47 loc) · 1.63 KB
/
AssemblyExtensions.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
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
#if EF_FUNCTIONALS
namespaceSystem.Data.Entity.Functionals.Utilities
#else
namespaceSystem.Data.Entity.Utilities
#endif
{
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Reflection;
internalstaticclassAssemblyExtensions
{
publicstaticstringGetInformationalVersion(thisAssemblyassembly)
{
DebugCheck.NotNull(assembly);
returnassembly
.GetCustomAttributes<AssemblyInformationalVersionAttribute>()
.Single()
.InformationalVersion;
}
publicstaticIEnumerable<Type>GetAccessibleTypes(thisAssemblyassembly)
{
try
{
#if NET40
returnassembly.GetTypes();
#else
returnassembly.DefinedTypes.Select(t =>t.AsType());
#endif
}
catch(ReflectionTypeLoadExceptionex)
{
// The exception is thrown if some types cannot be loaded in partial trust.
// For our purposes we just want to get the types that are loaded, which are
// provided in the Types property of the exception.
returnex.Types.Where(t =>t!=null);
}
}
#if NET40
publicstaticIEnumerable<T>GetCustomAttributes<T>(thisAssemblyassembly)whereT:Attribute
{
DebugCheck.NotNull(assembly);
returnassembly.GetCustomAttributes(typeof(T),inherit:false).OfType<T>();
}
#endif
}
}