本文整理汇总了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;
}
示例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;
}
示例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)));
}
示例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;
}
示例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);
}
示例6: MapAssembly
public static void MapAssembly(Assembly assembly)
{
Type[] types = assembly.GetTypes();
foreach (Type type in assembly.GetTypes())
{
MapType(type);
}
Mapper.AssertConfigurationIsValid();
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
示例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
}
示例12: BuildBindingsFromAssembly
public void BuildBindingsFromAssembly(Assembly assembly)
{
foreach (var type in assembly.GetTypes())
{
BuildBindingsFromType(type);
}
}
示例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();
}
示例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);
}
}
}