本文整理汇总了C#中System.Reflection.Assembly.GetReferencedAssemblies方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetReferencedAssemblies方法的具体用法?C# Assembly.GetReferencedAssemblies怎么用?C# Assembly.GetReferencedAssemblies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.GetReferencedAssemblies方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDependentAssemblies
private void AddDependentAssemblies(Assembly assem, string assemPath)
{
foreach (AssemblyName name in assem.GetReferencedAssemblies())
{
if (!string.Equals(name.Name, "mscorlib", StringComparison.OrdinalIgnoreCase))
{
string comReference = this.GetComReference(name);
if (comReference == null)
{
Assembly assembly = null;
try
{
assembly = Assembly.ReflectionOnlyLoad(name.FullName);
}
catch (FileNotFoundException)
{
if (name.CodeBase != null)
{
throw;
}
assembly = Assembly.ReflectionOnlyLoad(AssemblyName.GetAssemblyName(Path.Combine(Path.GetDirectoryName(assemPath), name.Name + ".dll")).FullName);
}
comReference = assembly.EscapedCodeBase;
if (comReference != null)
{
comReference = this.GetLocalPath(comReference);
}
}
this.AddReferencedAssembly(comReference);
}
}
}
示例2: ComputeAssemblyHash
private static void ComputeAssemblyHash(Assembly assembly, HashSet<Assembly> assemblies, StringBuilder outputString)
{
if (assemblies.Contains(assembly))
return;
outputString.Append(assembly.FullName);
var attribute = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
if (attribute != null)
{
outputString.Append(",").Append(attribute.Version);
outputString.AppendLine();
}
assemblies.Add(assembly);
foreach (var referencedAssemblyName in assembly.GetReferencedAssemblies())
{
// Avoid processing system assemblies
// TODO: Scan what is actually in framework folders (and unify it with ProcessDataSerializerGlobalAttributes)
if (referencedAssemblyName.Name == "mscorlib" || referencedAssemblyName.Name.StartsWith("System")
|| referencedAssemblyName.FullName.Contains("PublicKeyToken=31bf3856ad364e35")) // Signed with Microsoft public key (likely part of system libraries)
continue;
var assemblyRef = Assembly.Load(referencedAssemblyName);
ComputeAssemblyHash(assemblyRef, assemblies, outputString);
}
}
示例3: AddReferencedAssemblies
private void AddReferencedAssemblies(Assembly current)
{
if (this.loadedAssemblies.Contains(current))
{
return;
}
this.loadedAssemblies.Add(current);
foreach (var assemblyName in current.GetReferencedAssemblies())
{
try
{
var assembly = Assembly.Load(assemblyName);
Console.WriteLine("loaded assembly " + current.FullName);
this.AddReferencedAssemblies(assembly);
}
catch
{
Console.WriteLine("skipping assembly because it is not found: " + assemblyName.Name);
}
}
}
示例4: TestForWindowFormsByReflection
public void TestForWindowFormsByReflection()
{
string location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string assemblyToLoad = location + "\\Workshare.Policy.Engine.dll";
if (!System.IO.File.Exists(assemblyToLoad))
{
#if DEBUG
assemblyToLoad = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Win32\debug\Workshare.Policy.Engine.dll");
#else
assemblyToLoad = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Win32\release\Workshare.Policy.Engine.dll");
#endif
}
a = System.Reflection.Assembly.LoadFile(assemblyToLoad);
foreach (AssemblyName an in a.GetReferencedAssemblies())
{
Assert.AreNotEqual("System.Windows.Forms", an.Name, "System.Windows.Forms should not be referenced in Policy Engine");
// Call this when Action interfaces have been refacored out of Workshare.Policy.Action
// We will then ensure that we don't indirectly reference Windows.Forms
//CheckAssemblyForReference(an);
}
}
示例5: Get
public static IEnumerable<ProviderAssemblyAttributeBase> Get(Assembly assembly)
{
if (assembly.ReflectionOnly)
{
foreach (var referencedAssembly in assembly.GetReferencedAssemblies())
{
if (AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies().All(a => a.GetName().FullName != referencedAssembly.FullName))
{
try
{
Assembly.ReflectionOnlyLoad(referencedAssembly.FullName);
}
catch (FileNotFoundException)
{
return Enumerable.Empty<ProviderAssemblyAttributeBase>();
}
}
}
var hasAttribute = assembly.GetCustomAttributesData().Any(
cad => typeof (ProviderAssemblyAttributeBase).IsAssignableFrom(cad.Constructor.DeclaringType));
if (hasAttribute)
{
assembly = Assembly.Load(assembly.GetName());
}
else
{
return Enumerable.Empty<ProviderAssemblyAttributeBase>();
}
}
return assembly.GetCustomAttributes(typeof (ProviderAssemblyAttributeBase), false)
.Cast<ProviderAssemblyAttributeBase>();
}
示例6: Analyze
public AssemblyRecord Analyze(Assembly assembly)
{
var record = new AssemblyRecord();
record.AssemblyName = assembly.GetName();
record.Name = record.AssemblyName.Name;
var version = record.AssemblyName.Version;
record.Version = string.Format("{0}.{1}.{2}.{3}", version.Major.ToString().PadLeft(2), version.Minor.ToString().PadLeft(2), version.MajorRevision.ToString().PadLeft(2), version.MinorRevision.ToString().PadLeft(2));
record.References = new List<AssemblyRecord>();
foreach (var reference in assembly.GetReferencedAssemblies())
{
try
{
var referenceAssembly = Assembly.ReflectionOnlyLoad(reference.FullName);
if (!referenceAssembly.GlobalAssemblyCache)
{
if (!_localCache.ContainsKey(referenceAssembly.FullName))
{
var referenceRecord = Analyze(referenceAssembly);
_localCache.Add(referenceAssembly.FullName, referenceRecord);
}
record.References.Add(_localCache[referenceAssembly.FullName]);
}
}
catch { }
}
record.References.Sort((a1, a2) => a1.Name.CompareTo(a2.Name));
return record;
}
示例7: AddTypeSearchAssemblyTree
public static void AddTypeSearchAssemblyTree(Assembly asm)
{
if (asm == null) return;
lock (typeSearchAssemblies)
{
if (!typeSearchAssemblies.Contains(asm))
{
typeSearchAssemblies.Add(asm);
// get reference assemblies
AssemblyName[] childrenAsmNames = asm.GetReferencedAssemblies();
foreach (AssemblyName asmName in childrenAsmNames)
{
// this may take more space, which is normally OK
try
{
Assembly child = Assembly.Load(asmName);
if (!typeSearchAssemblies.Contains(child))
typeSearchAssemblies.Add(child);
}
catch (Exception e) { }
}
}
}
}
示例8: Analyze
private IEnumerable<AnalysisResult> Analyze(Assembly assembly)
{
try
{
var internalTypeNames = assembly.DefinedTypes.Select(t => t.FullName);
#if NET451
var referencedAssemblyNames = assembly.GetReferencedAssemblies().Select(x => x.Name);
#else
var referencedAssemblyNames = Enumerable.Empty<string>(); // not currently supported :(
#endif
var analysisData = new AnalysisData(referencedAssemblyNames, internalTypeNames);
var runner = new HeuristicRunner(HeuristicProvider.GetAll());
return runner.GetResults(analysisData);
}
catch
{
if (this.failSilently)
{
return null;
}
throw;
}
}
示例9: FindClientCodeAssembly
private static string FindClientCodeAssembly(Assembly globalAssembly)
{
return globalAssembly
.GetReferencedAssemblies()
.First(name => !(name.Name.Contains("System.") && !(name.Name.Contains("mscorlib"))))
.Name;
}
示例10: AssemblyReferencesSdkOrExtension
// Helper to filter out assemblies that don't reference the SDK or
// binding extension assemblies (i.e. possible sources of binding attributes, etc.)
private static bool AssemblyReferencesSdkOrExtension(Assembly assembly, IEnumerable<Assembly> extensionAssemblies)
{
// Don't index methods in our assemblies.
if (typeof(DefaultTypeLocator).Assembly == assembly)
{
return false;
}
AssemblyName[] referencedAssemblyNames = assembly.GetReferencedAssemblies();
foreach (var referencedAssemblyName in referencedAssemblyNames)
{
if (String.Equals(referencedAssemblyName.Name, WebJobsAssemblyName, StringComparison.OrdinalIgnoreCase))
{
// the assembly references our core SDK assembly
// containing our built in attribute types
return true;
}
if (extensionAssemblies.Any(p => string.Equals(referencedAssemblyName.Name, p.GetName().Name, StringComparison.OrdinalIgnoreCase)))
{
// the assembly references an extension assembly that may
// contain extension attributes
return true;
}
}
return false;
}
示例11: _LoadSuitesFromAssembly
private void _LoadSuitesFromAssembly(Assembly assembly, Int32 level, RunnableContainer testSuites)
{
if(ShouldProcessAssembly(assembly) && (level < 3))
{
/*
* Check the types which are contained inside of the assembly for any TestSuite
* linkages
*/
Type[] types = assembly.GetTypes();
foreach(Type type in types)
{
if(type.IsSubclassOf(typeof(TestSuite)))
{
ConstructorInfo constructor = type.GetConstructor(new Type[]{});
if(constructor != null)
{
TestSuite testSuite = (TestSuite)constructor.Invoke(new object[]{});
testSuites.Add(testSuite);
}
}
}
/*
* Move onto the referenceAssemblies of the current Assemblie and continue loading them
*/
AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies();
foreach(AssemblyName assemblyName in referencedAssemblies)
{
Assembly referencedAssembly = Assembly.Load(assemblyName);
_LoadSuitesFromAssembly(referencedAssembly, ++level, testSuites);
}
}
}
示例12: IsEntityAssembly
public static bool IsEntityAssembly(Assembly assembly)
{
Argument.IsNotNull(assembly, "assembly");
return assembly.GetReferencedAssemblies().Any(assemblyName => assemblyName.FullName == _thisAssemblyFullName) &&
assembly.GetTypes().Any(IsEntityType);
}
示例13: CollectMetadataReferences
public IEnumerable<MetadataReference> CollectMetadataReferences(Assembly sourceReferencesAssembly)
{
var references = sourceReferencesAssembly.GetReferencedAssemblies();
return references
.Select(GetAssembly)
.Select(asm => MetadataReference.CreateFromFile(asm.Location));
}
示例14: EntityAssembly
public EntityAssembly(Assembly assembly)
{
Argument.IsNotNull(assembly, "assembly");
Argument.IsValid(assembly.GetReferencedAssemblies().Any(assemblyName => assemblyName.FullName == _thisAssemblyFullName), // TODO-IG: Add override for Argument.IsValid() where the second argument is Func<string>.
string.Format("The assembly '{1}' is not an entity assembly because it does not reference '{2}'.{0}" +
"Entity assembly is an assembly that references '{2}' and has at least one class that derives from '{3}'.",
System.Environment.NewLine,
assembly,
_thisAssembly,
typeof(Entity)
),
"assembly");
Assembly = assembly;
_entityTypes = assembly.GetTypes().Where(IsEntityType).ToArray();
Argument.IsValid(_entityTypes.Length > 0,
string.Format("The assembly '{1}' is not an entity assembly because it does have any class that derives from '{3}'.{0}" +
"Entity assembly is an assembly that references '{2}' and has at least one class that derives from '{3}'.",
System.Environment.NewLine,
assembly,
_thisAssembly,
typeof(Entity)
),
"assembly");
}
示例15: ThatImplement
/// <summary>
/// Returns all type implementing the specified interface in all loaded assemblies
/// </summary>
/// <param name="expectedInterface"></param>
/// <param name="assembly"></param>
/// <param name="checkReferencedAssemblies">Check referenced assemblies also</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">when <paramref name="assembly"/> is null</exception>
public static IList<Type> ThatImplement(Type expectedInterface, Assembly assembly, bool checkReferencedAssemblies)
{
if (assembly == null) throw new ArgumentNullException("assembly");
var results = new List<Type>();
var assemblies = new List<AssemblyName> {assembly.GetName()};
if( checkReferencedAssemblies ) assemblies.AddRange(assembly.GetReferencedAssemblies());
foreach( var referencedAssembly in assemblies )
{
// Catch loader exceptions for referenced assemblies
var loadedAssembly = Assembly.Load(referencedAssembly);
if( loadedAssembly == assembly)
{
results.AddRange(ThatImplement(expectedInterface, loadedAssembly));
}
else
{
try
{
results.AddRange(ThatImplement(expectedInterface, loadedAssembly));
}
catch (ReflectionTypeLoadException)
{
continue;
}
}
}
return results;
}