本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}