当前位置: 首页>>代码示例>>C#>>正文


C# Assembly.GetReferencedAssemblies方法代码示例

本文整理汇总了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);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:AxImporter.cs

示例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);
            }
        }
开发者ID:Powerino73,项目名称:paradox,代码行数:27,代码来源:AssemblyHash.cs

示例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);
                }
            }
        }
开发者ID:philippdolder,项目名称:ninject.features,代码行数:25,代码来源:AssemblyLoader.cs

示例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);
            }
        }
开发者ID:killbug2004,项目名称:WSProf,代码行数:25,代码来源:TestForWindowForms.cs

示例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>();
 }
开发者ID:JohnFunari,项目名称:Simple.Data,代码行数:32,代码来源:ProviderAssemblyAttributeBase.cs

示例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;
        }
开发者ID:netxph,项目名称:deep,代码行数:34,代码来源:AssemblyBrowser.cs

示例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) { }
                    }
                }
            }
        }
开发者ID:az312748248,项目名称:ProjectFramework,代码行数:26,代码来源:Invoker.cs

示例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;
            }
        }
开发者ID:nbarbettini,项目名称:polyglot-dotnet,代码行数:27,代码来源:AssemblyAnalyzer.cs

示例9: FindClientCodeAssembly

 private static string FindClientCodeAssembly(Assembly globalAssembly)
 {
     return globalAssembly
         .GetReferencedAssemblies()
         .First(name => !(name.Name.Contains("System.") && !(name.Name.Contains("mscorlib"))))
         .Name;
 }
开发者ID:rauhryan,项目名称:warmup-templates,代码行数:7,代码来源:__NAME__StructureMapApplication.cs

示例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;
        }
开发者ID:niallmerrigan,项目名称:azure-webjobs-sdk,代码行数:30,代码来源:DefaultTypeLocator.cs

示例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);
                }
            }
        }
开发者ID:bigbearstudios,项目名称:sharp-test,代码行数:34,代码来源:TestSuiteLoader.cs

示例12: IsEntityAssembly

        public static bool IsEntityAssembly(Assembly assembly)
        {
            Argument.IsNotNull(assembly, "assembly");

            return assembly.GetReferencedAssemblies().Any(assemblyName => assemblyName.FullName == _thisAssemblyFullName) &&
                   assembly.GetTypes().Any(IsEntityType);
        }
开发者ID:hudo,项目名称:Pragmatic,代码行数:7,代码来源:EntityAssembly.cs

示例13: CollectMetadataReferences

 public IEnumerable<MetadataReference> CollectMetadataReferences(Assembly sourceReferencesAssembly)
 {
     var references = sourceReferencesAssembly.GetReferencedAssemblies();
     return references
         .Select(GetAssembly)
         .Select(asm => MetadataReference.CreateFromFile(asm.Location));
 }
开发者ID:alex123098,项目名称:EditablePlugins,代码行数:7,代码来源:AssemblyReferenceProvider.cs

示例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");
        }
开发者ID:hudo,项目名称:Pragmatic,代码行数:27,代码来源:EntityAssembly.cs

示例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;
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:42,代码来源:GetTypes.cs


注:本文中的System.Reflection.Assembly.GetReferencedAssemblies方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。