forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssemblyHelpers.cs
More file actions
44 lines (38 loc) · 1.38 KB
/
Copy pathAssemblyHelpers.cs
File metadata and controls
44 lines (38 loc) · 1.38 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Microsoft.ClearScript.Util
{
internal static class AssemblyHelpers
{
public static T GetAttribute<T>(this Assembly assembly, bool inherit) where T : Attribute
{
return Attribute.GetCustomAttributes(assembly, typeof(T), inherit).SingleOrDefault() as T;
}
public static IEnumerable<T> GetAttributes<T>(this Assembly assembly, bool inherit) where T : Attribute
{
return Attribute.GetCustomAttributes(assembly, typeof(T), inherit).OfType<T>();
}
public static bool IsFriendOf(this Assembly thisAssembly, Assembly thatAssembly)
{
if (thatAssembly == thisAssembly)
{
return true;
}
var thisName = thisAssembly.GetName();
foreach (var attribute in thatAssembly.GetAttributes<InternalsVisibleToAttribute>(false))
{
var thatName = new AssemblyName(attribute.AssemblyName);
if (AssemblyName.ReferenceMatchesDefinition(thatName, thisName))
{
return true;
}
}
return false;
}
}
}