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


C# Assembly.SafeGetTypes方法代码示例

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


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

示例1: RegisterAssembly

        /// <summary>
        ///     Registers all types marked with a MoonSharpUserDataAttribute that ar contained in an assembly.
        /// </summary>
        /// <param name="asm">The assembly.</param>
        /// <param name="includeExtensionTypes">if set to <c>true</c> extension types are registered to the appropriate registry.</param>
        internal static void RegisterAssembly(Assembly asm = null, bool includeExtensionTypes = false)
        {
            asm = asm ?? Assembly.GetCallingAssembly();

            if (includeExtensionTypes)
            {
                var extensionTypes = from t in asm.SafeGetTypes()
                    let attributes = t.GetCustomAttributes(typeof (ExtensionAttribute), true)
                    where attributes != null && attributes.Length > 0
                    select new {Attributes = attributes, DataType = t};

                foreach (var extType in extensionTypes)
                {
                    UserData.RegisterExtensionType(extType.DataType);
                }
            }


            var userDataTypes = from t in asm.SafeGetTypes()
                let attributes = t.GetCustomAttributes(typeof (MoonSharpUserDataAttribute), true)
                where attributes != null && attributes.Length > 0
                select new {Attributes = attributes, DataType = t};

            foreach (var userDataType in userDataTypes)
            {
                UserData.RegisterType(userDataType.DataType, userDataType.Attributes
                    .OfType<MoonSharpUserDataAttribute>()
                    .First()
                    .AccessMode);
            }
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:36,代码来源:TypeDescriptorRegistry.cs

示例2: RegisterAssembly

		/// <summary>
		/// Registers all types marked with a MoonSharpUserDataAttribute that ar contained in an assembly.
		/// </summary>
		/// <param name="asm">The assembly.</param>
		/// <param name="includeExtensionTypes">if set to <c>true</c> extension types are registered to the appropriate registry.</param>
		internal static void RegisterAssembly(Assembly asm = null, bool includeExtensionTypes = false)
		{
			if (asm == null)
			{
				#if NETFX_CORE || DOTNET_CORE
					throw new NotSupportedException("Assembly.GetCallingAssembly is not supported on target framework.");
				#else
					asm = Assembly.GetCallingAssembly();
				#endif
			}

			if (includeExtensionTypes)
			{
				var extensionTypes = from t in asm.SafeGetTypes()
									 let attributes = Framework.Do.GetCustomAttributes(t, typeof(ExtensionAttribute), true)
									 where attributes != null && attributes.Length > 0
									 select new { Attributes = attributes, DataType = t };

				foreach (var extType in extensionTypes)
				{
					UserData.RegisterExtensionType(extType.DataType);
				}
			}


			var userDataTypes = from t in asm.SafeGetTypes()
								let attributes = Framework.Do.GetCustomAttributes(t, typeof(MoonSharpUserDataAttribute), true)
								where attributes != null && attributes.Length > 0
								select new { Attributes = attributes, DataType = t };

			foreach (var userDataType in userDataTypes)
			{
				UserData.RegisterType(userDataType.DataType, userDataType.Attributes
					.OfType<MoonSharpUserDataAttribute>()
					.First()
					.AccessMode);
			}
		}
开发者ID:abstractmachine,项目名称:Fungus-3D-Template,代码行数:43,代码来源:TypeDescriptorRegistry.cs

示例3: TryAddManagers

 private static void TryAddManagers(List<ConstructorInfo> managers, Assembly assembly)
 {
     foreach (Type type in assembly.SafeGetTypes(false))
     {
         if (!typeof(IDesignTimeManager).IsAssignableFrom(type) || !type.IsPublicNonAbstractClass())
             continue;
         ConstructorInfo constructor = type.GetConstructor(Empty.Array<Type>());
         if (constructor != null)
             managers.Add(constructor);
     }
 }
开发者ID:MuffPotter,项目名称:MugenMvvmToolkit,代码行数:11,代码来源:DesignTimeInitializer.cs

示例4: RegisterItemsFromAssembly

 /// <summary>
 /// Registers named items from the assembly.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="itemNamePrefix">Item name prefix.</param>
 public void RegisterItemsFromAssembly(Assembly assembly, string itemNamePrefix)
 {
     InternalLogger.Debug("ScanAssembly('{0}')", assembly.FullName);
     var typesToScan = assembly.SafeGetTypes();
     foreach (IFactory f in this.allFactories)
     {
         f.ScanTypes(typesToScan, itemNamePrefix);
     }
 }
开发者ID:JvanderStad,项目名称:NLog,代码行数:14,代码来源:ConfigurationItemFactory.cs


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