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


C# SortedDictionary.AddOrIgnore方法代码示例

本文整理汇总了C#中SortedDictionary.AddOrIgnore方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.AddOrIgnore方法的具体用法?C# SortedDictionary.AddOrIgnore怎么用?C# SortedDictionary.AddOrIgnore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedDictionary的用法示例。


在下文中一共展示了SortedDictionary.AddOrIgnore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindTypes

        /// <summary>
        /// Finds the all the types that implement or inherit from the baseType.  The baseType
        /// will not be included in the result
        /// </summary>
        /// <param name="baseType">base type.</param>
        /// <param name="typeName">typeName can be specified to filter it to a specific type name</param>
        /// <returns></returns>
        public static SortedDictionary<string, Type> FindTypes( Type baseType, string typeName = null )
        {
            SortedDictionary<string, Type> types = new SortedDictionary<string, Type>();

            Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();

            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            assemblies.Add( executingAssembly.FullName.ToLower(), executingAssembly );

            foreach ( Assembly assembly in AppDomain.CurrentDomain.GetAssemblies() )
            {
                if ( assembly.GlobalAssemblyCache || assembly.IsDynamic )
                {
                    continue;
                }

                bool searchAssembly = false;

                string fileName = Path.GetFileName( assembly.CodeBase );

                // only search inside dlls that are Rock.dll or reference Rock.dll
                if ( fileName.Equals( "Rock.dll", StringComparison.OrdinalIgnoreCase ) )
                {
                    searchAssembly = true;
                }
                else
                {
                    List<AssemblyName> referencedAssemblies = assembly.GetReferencedAssemblies().ToList();

                    if ( referencedAssemblies.Any( a => a.Name.Equals( "Rock", StringComparison.OrdinalIgnoreCase ) ) )
                    {
                        searchAssembly = true;
                    }
                }

                if ( searchAssembly )
                {
                    if ( !assemblies.Keys.Contains( assembly.FullName.ToLower() ) )
                    {
                        assemblies.Add( assembly.FullName.ToLower(), assembly );
                    }
                }
            }

            // Add any dll's in the Plugins folder
            var httpContext = System.Web.HttpContext.Current;
            if ( httpContext != null )
            {
                var pluginsDir = new DirectoryInfo( httpContext.Server.MapPath( "~/Plugins" ) );
                if ( pluginsDir.Exists )
                {
                    foreach ( var file in pluginsDir.GetFiles( "*.dll", SearchOption.AllDirectories ) )
                    {
                        var assembly = Assembly.LoadFrom( file.FullName );
                        if ( !assemblies.Keys.Contains( assembly.FullName.ToLower() ) )
                        {
                            assemblies.Add( assembly.FullName.ToLower(), assembly );
                        }
                    }
                }
            }

            foreach ( KeyValuePair<string, Assembly> assemblyEntry in assemblies )
            {
                var typeEntries = SearchAssembly( assemblyEntry.Value, baseType );
                foreach ( KeyValuePair<string, Type> typeEntry in typeEntries )
                {
                    if ( string.IsNullOrWhiteSpace( typeName ) || typeEntry.Key == typeName )
                    {
                        types.AddOrIgnore( typeEntry.Key, typeEntry.Value );
                    }
                }
            }

            return types;
        }
开发者ID:,项目名称:,代码行数:83,代码来源:


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