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


C# Assembly.GetTypes方法代码示例

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


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

示例1: SearchPackageHandler

        public static int SearchPackageHandler(Assembly ass)
        {
            int count = 0;
            m_packagesHandlers.Clear();

            Type[] tList = ass.GetTypes();

            string interfaceStr = typeof(IPackageHandler).ToString();

            foreach (Type type in tList)
            {
                if (type.IsClass != true) continue;

                if (type.GetInterface(interfaceStr) == null) continue;

                PackageHandlerAttribute[] atts = (PackageHandlerAttribute[])type.GetCustomAttributes(typeof(PackageHandlerAttribute), true);

                if (atts.Length > 0)
                {
                    count++;
                    RegisterPacketHandler(atts[0].Code, (IPackageHandler)Activator.CreateInstance(type));
                    //m_packagesHandlers[atts[0].Code] = (IPackageHandler)Activator.CreateInstance(type);
                }
            }

            return count;
        }
开发者ID:W8023Y2014,项目名称:jsion,代码行数:27,代码来源:PackageHandlers.cs

示例2: PrecompiledMvcEngine

        public PrecompiledMvcEngine(Assembly assembly, string baseVirtualPath, IViewPageActivator viewPageActivator)
        {
            if (!Assemblies.Contains(assembly))
                Assemblies.Add(assembly);

            _assemblyLastWriteTime = new Lazy<DateTime>(() => assembly.GetLastWriteTimeUtc(fallback: DateTime.MaxValue));
            _baseVirtualPath = NormalizeBaseVirtualPath(baseVirtualPath);
            BaseLocationFormats();
            #if DEBUG
            var map = (from type in assembly.GetTypes()
                       where typeof(WebPageRenderingBase).IsAssignableFrom(type)
                       let pageVirtualPath =
                           type.GetCustomAttributes(inherit: false).OfType<PageVirtualPathAttribute>().FirstOrDefault()
                       where pageVirtualPath != null
                       select pageVirtualPath.VirtualPath);
            #endif

            _mappings = (from type in assembly.GetTypes()
                         where typeof(WebPageRenderingBase).IsAssignableFrom(type)
                         let pageVirtualPath = type.GetCustomAttributes(inherit: false).OfType<PageVirtualPathAttribute>().FirstOrDefault()
                         where pageVirtualPath != null
                         select new KeyValuePair<string, Type>(CombineVirtualPaths(_baseVirtualPath, pageVirtualPath.VirtualPath), type)
                         ).ToDictionary(t => t.Key, t => t.Value, StringComparer.OrdinalIgnoreCase);

            this.ViewLocationCache = new PrecompiledViewLocationCache(assembly.FullName, this.ViewLocationCache);
            _viewPageActivator = viewPageActivator
                ?? DependencyResolver.Current.GetService<IViewPageActivator>() /* For compatibility, remove this line within next version */
                ?? DefaultViewPageActivator.Current;
        }
开发者ID:akrisiun,项目名称:git-dot-aspx,代码行数:29,代码来源:PrecompiledMvcEngine.cs

示例3: FindAllTheTypesThatHaveTechDebt

 private static IEnumerable<MemberInfo> FindAllTheTypesThatHaveTechDebt(Assembly assembly)
 {
     return assembly.GetTypes()
         .SelectMany(type => type.GetMembers())
         .Union(assembly.GetTypes())
         .Where(type => Attribute.IsDefined(type, typeof(TechDebtAttribute)));
 }
开发者ID:ChrisMissal,项目名称:TechDebtAttributes,代码行数:7,代码来源:Reporter.cs

示例4: GetMethodRules

        /// <summary>
        /// Read all the <see cref="MethodDescriptor"/>s for an <see cref="Assembly"/>.
        /// </summary>
        /// <param name="assembly">The <see cref="Assembly"/> to read attributes from.</param>
        /// <returns>All the <see cref="MethodDescriptor"/>s for an <see cref="Assembly"/>.</returns>
        public static IList<MethodDescriptor> GetMethodRules(Assembly assembly)
        {
            var list = new List<MethodDescriptor>();

            for (var typeIndex = 0; typeIndex < assembly.GetTypes().Length; typeIndex++)
            {
                var type = assembly.GetTypes()[typeIndex];
                //we only care about classes and interfaces.
                if (type.IsClass || type.IsInterface)
                {
                    foreach (var methodInfo in type.GetMethods(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
                    {
                        //TODO: support generic methods
                        if (!TypeExtensions.IsPropertyMethod(methodInfo) && !methodInfo.ContainsGenericParameters && methodInfo.GetParameters().Length > 0)
                        {
                            var descriptor = MethodCache.GetMethod(methodInfo.MethodHandle);
                            foreach (var parameter in descriptor.Parameters)
                            {
                                if (parameter.Rules.Count > 0)
                                {
                                    list.Add(descriptor);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return list;
        }
开发者ID:thekindofme,项目名称:.netcf-Validation-Framework,代码行数:35,代码来源:RuleDescriber.cs

示例5: Library

        public Library(Config.Library libConfig, Assembly _assembly)
        {
            name = libConfig.Name;
            assembly = _assembly;

            ArrayList typeList = new ArrayList();
            assembly.GetTypes();
            foreach (Type type in assembly.GetTypes()) {
                if (libConfig == null || !libConfig.GetIgnoreType(type))
                    typeList.Add(type);
            }
            types = (Type[])typeList.ToArray(typeof(Type));

            typesByName = new TypeTable(types.Length);
            typesByFullName = new TypeTable(types.Length);

            Type typeofTypeAliasAttribute = typeof(TypeAliasAttribute);

            foreach (Type type in types) {
                typesByName.Add(type.Name, type);
                typesByFullName.Add(type.FullName, type);

                if (type.IsDefined(typeofTypeAliasAttribute, false)) {
                    object[] attrs = type.GetCustomAttributes(typeofTypeAliasAttribute, false);

                    if (attrs != null && attrs.Length > 0 && attrs[0] != null) {
                        TypeAliasAttribute attr = attrs[0] as TypeAliasAttribute;
                        foreach (string alias in attr.Aliases)
                            typesByFullName.Add(alias, type);
                    }
                }
            }

            typeCache = new TypeCache(types, typesByName, typesByFullName);
        }
开发者ID:BackupTheBerlios,项目名称:sunuo-svn,代码行数:35,代码来源:Library.cs

示例6: MapAssembly

        public static void MapAssembly(Assembly assembly)
        {
            Type[] types = assembly.GetTypes();
            foreach (Type type in assembly.GetTypes())
            {
                MapType(type);
            }

            Mapper.AssertConfigurationIsValid();            
        }
开发者ID:ysminnpu,项目名称:OpenLawOffice,代码行数:10,代码来源:ObjectMapper.cs

示例7: AddHubsFromAssembly

        /*
         declare var client: IClient // To be filled by the user...
         declare var server: IServer

         */
        public static void AddHubsFromAssembly(Assembly assembly)
        {
            assembly.GetTypes()
                .Where(t => t.BaseType != null && t.BaseType.Name == "Hub").ToList()
                .ForEach(t => MakeHubInterface(t) );

            assembly.GetTypes()
                .Where(t => t.BaseType != null && t.BaseType.Name == "Hub`1").ToList()
                .ForEach(t => MakeHubInterface(t));
        }
开发者ID:slovely,项目名称:SRTS,代码行数:15,代码来源:ServiceTypes.cs

示例8: CheckResultInternal

        private static bool CheckResultInternal(ref Assembly assembly, List<string> errors, CompilerResults result,bool isIngameScript)
        {
            if (result.Errors.HasErrors)
            {
                var en = result.Errors.GetEnumerator();
                while (en.MoveNext())
                {
                    if (!(en.Current as CompilerError).IsWarning)
                        errors.Add((en.Current as CompilerError).ToString());
                }
                return false;
            }
            assembly = result.CompiledAssembly;
            Type failedType;
            var dic = new Dictionary<Type, List<MemberInfo>>();
            foreach (var t in assembly.GetTypes()) //allows calls inside assembly
                dic.Add(t, null);

            List<MethodBase> typeMethods = new List<MethodBase>();
            BindingFlags bfAllMembers = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;

            foreach (var t in assembly.GetTypes())
            {
                typeMethods.Clear();
                typeMethods.AddArray(t.GetMethods(bfAllMembers));
                typeMethods.AddArray(t.GetConstructors(bfAllMembers));

                foreach (var m in typeMethods)
                {
                    if (IlChecker.IsMethodFromParent(t,m))
                    {
                        if (IlChecker.CheckTypeAndMember(m.DeclaringType, isIngameScript) == false)
                        {
                            errors.Add(string.Format("Class {0} derives from class {1} that is not allowed in script", t.Name, m.DeclaringType.Name));
                            return false;
                        }
                        continue;
                    }
                    if ((!IlChecker.CheckIl(m_reader.ReadInstructions(m), out failedType,isIngameScript, dic)) || IlChecker.HasMethodInvalidAtrributes(m.Attributes))
                    {
                        // CH: TODO: This message does not make much sense when we test not only allowed types, but also method attributes
                        errors.Add(string.Format("Type {0} used in {1} not allowed in script", failedType == null ? "FIXME" : failedType.ToString(), m.Name));
                        assembly = null;
                        return false;
                    }
                }
            }
            return true;
        }
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:49,代码来源:IlCompiler.cs

示例9: HasCurrentTag

        private static bool HasCurrentTag(Assembly assembly)
        {
            // Check for classes that are tagged as "current".
            var taggedClasses = 
                from t in assembly.GetTypes()
                where t.GetCustomAttributes(typeof(TagAttribute), true).Count(attr => ((TagAttribute)attr).Tag == TagCurrent) > 0 
                select t;
            if (taggedClasses.Count() > 0) return true;

            var testMethods =
                from t in assembly.GetTypes()
                where t.GetMethods().Where(item => item.GetCustomAttributes(typeof(TagAttribute), true).Count(attr => ((TagAttribute)attr).Tag == TagCurrent) > 0).Count() > 0
                select t;
            return testMethods.Count() > 0;
        }
开发者ID:philcockfield,项目名称:Open.TestHarness.SL,代码行数:15,代码来源:Initialization.cs

示例10: RPS

        /// <summary>
        /// RPS Wrapper constructor
        /// </summary>
        public RPS()
        {
            // Load dynamically the assembly
            _rpsAssembly = Assembly.Load("Microsoft.Passport.RPS, Version=6.1.6206.0, Culture=neutral, PublicKeyToken=283dd9fa4b2406c5, processorArchitecture=MSIL");

            // Extract the types that will be needed to perform authentication
            _rpsType = _rpsAssembly.GetTypes().ToList().Where(t => t.Name == "RPS").Single();
            _rpsTicketType = _rpsAssembly.GetTypes().ToList().Where(t => t.Name == "RPSTicket").Single();
            _rpsPropBagType = _rpsAssembly.GetTypes().ToList().Where(t => t.Name == "RPSPropBag").Single();
            _rpsAuthType = _rpsAssembly.GetTypes().ToList().Where(t => t.Name == "RPSAuth").Single();
            _rpsTicketPropertyType = _rpsTicketType.GetNestedTypes().ToList().Where(t => t.Name == "RPSTicketProperty").Single();

            // Create instance of the RPS object
            _rps = Activator.CreateInstance(_rpsType);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:18,代码来源:Rps.cs

示例11: GetAllTypesFromAssembly

        static Type[] GetAllTypesFromAssembly(Assembly asm) {
#if SILVERLIGHT // ReflectionTypeLoadException
            try {
                return asm.GetTypes();
            } catch (Exception) {
                return ArrayUtils.EmptyTypes;
            }
#else
            try {
                return asm.GetTypes();
            } catch (ReflectionTypeLoadException rtlException) {
                return rtlException.Types;
            }
#endif
        }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:15,代码来源:AssemblyTypeNames.cs

示例12: BuildBindingsFromAssembly

 public void BuildBindingsFromAssembly(Assembly assembly)
 {
     foreach (var type in assembly.GetTypes())
     {
         BuildBindingsFromType(type);
     }
 }
开发者ID:Galad,项目名称:SpecFlow,代码行数:7,代码来源:RuntimeBindingRegistryBuilder.cs

示例13: AddSuitableValidators

        /// <summary>
        /// Register existent suitable validators in specified assembly to be available during link generation and before execute actions.
        /// </summary>
        public static IServiceCollection AddSuitableValidators([NotNull] this IServiceCollection services, Assembly mappersAssembly)
        {
            services.Configure<MvcOptions>(options =>
            {
                options.Filters.Add(new SuitableValidationFilter());
            });

            var serviceTypes = mappersAssembly.GetTypes()
                .Select(x => new
                {
                    type = x,
                    info = x.GetTypeInfo()
                })
                .Where(x => !x.info.IsAbstract
                    && !x.info.IsInterface
                    && x.info.IsPublic
                    && x.info.Namespace != null
                    && x.info.ImplementedInterfaces.Contains(typeof(ISuitableValidator)))
                .Select(x => x.type);

            foreach (var type in serviceTypes)
            {
                services.AddScoped(type);
            }

            return services;
        }
开发者ID:MakingSense,项目名称:aspnet-hypermedia-api,代码行数:30,代码来源:DefaultSuitableValidatorsServiceCollectionExtensions.cs

示例14: GetAllTypesWithStaticFieldsImplementingType

 public static IEnumerable<Type> GetAllTypesWithStaticFieldsImplementingType(Assembly assembly, Type type)
 {
     return assembly.GetTypes().Where(t =>
     {
         return t.GetFields(BindingFlags.Public | BindingFlags.Static).Any(f => type.IsAssignableFrom(f.FieldType));
     }).ToList();
 }
开发者ID:jkotas,项目名称:roslyn,代码行数:7,代码来源:TestHelpers.cs

示例15: InstantiateConfigurableViewModels

    private void InstantiateConfigurableViewModels(Assembly assembly)
    {
      Type[] types;
      try
      {
        types = assembly.GetTypes();  // Using this in a foreach caused the app to stop loading dll's. Hence this structure. 
      }
      catch (ReflectionTypeLoadException ex)
      {
        Log.Warn("[MappedViewModelProcessor] " + ex.Message, ex, this);
        return;
      }

      foreach (var type in types)
      {
        try
        {
          if (!type.IsClass || type.IsNotPublic)
            continue;

          if (type.BaseType != null && !string.IsNullOrWhiteSpace(type.BaseType.Name) &&
              typeof (MappedViewModelConfiguration<>).Name == type.BaseType.Name)
          {
            Activator.CreateInstance(type);
          }
        }
        catch (Exception ex)
        {
          Log.Error(ex.Message, ex, this);
        }
      }
    }
开发者ID:galtrold,项目名称:SitecoreMvc,代码行数:32,代码来源:MappedViewModelProcessor.cs


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