本文整理汇总了C#中System.GetTypes方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetTypes方法的具体用法?C# System.GetTypes怎么用?C# System.GetTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.GetTypes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public Type[] Execute(System.Reflection.Assembly assembly)
{
var targetNamespaces = new HashSet<string>();
var resourceNames = assembly.GetManifestResourceNames().Where(n => n.EndsWith("VenusIoc.config"));
foreach (var resourceName in resourceNames)
{
var xmlDoc = new XmlDocument();
using (var sr = new StreamReader(assembly.GetManifestResourceStream(resourceName)))
{
xmlDoc.Load(sr);
foreach (var node in xmlDoc.DocumentElement.SelectNodes("components/assemblyScan/namespace"))
{
var name = ((XmlElement)node).GetAttribute("name");
if (!string.IsNullOrWhiteSpace(name))
{
targetNamespaces.Add(name.Trim());
}
}
}
}
var types = new List<Type>();
foreach (var type in assembly.GetTypes())
{
if (targetNamespaces.Contains(type.Namespace) && !type.IsAbstract && type.IsDefined(typeof(NamedAttribute), false))
{
types.Add(type);
}
}
return types.ToArray();
}
示例2: FindTasksAndConditionsInAssembly
internal static void FindTasksAndConditionsInAssembly(System.Reflection.Assembly assembly,
Dictionary<string, Type> updateTasks, Dictionary<string, Type> updateConditions)
{
foreach (Type t in assembly.GetTypes())
{
if (typeof(IUpdateTask).IsAssignableFrom(t))
{
updateTasks.Add(t.Name, t);
UpdateTaskAliasAttribute[] tasksAliases = (UpdateTaskAliasAttribute[])t.GetCustomAttributes(typeof(UpdateTaskAliasAttribute), false);
foreach (UpdateTaskAliasAttribute alias in tasksAliases)
{
updateTasks.Add(alias.Alias, t);
}
}
else if (typeof(IUpdateCondition).IsAssignableFrom(t))
{
updateConditions.Add(t.Name, t);
UpdateConditionAliasAttribute[] tasksAliases = (UpdateConditionAliasAttribute[])t.GetCustomAttributes(typeof(UpdateConditionAliasAttribute), false);
foreach (UpdateConditionAliasAttribute alias in tasksAliases)
{
updateConditions.Add(alias.Alias, t);
}
}
}
}
示例3: GetTypesAssignableFrom
public static IEnumerable<Type> GetTypesAssignableFrom(System.Reflection.Assembly assemb, System.Type rootType)
{
foreach (var tp in assemb.GetTypes())
{
if (rootType.IsAssignableFrom(tp) && rootType != tp) yield return tp;
}
}
示例4: AddAssembly
public void AddAssembly( System.Reflection.Assembly assembly )
{
Details details = new Details();
details.Assembly = assembly;
foreach( Type type in assembly.GetTypes() )
{
List<Type> types;
if( details.TypeMap.ContainsKey( type.Name ) )
{
types = details.TypeMap[type.Name];
}
else
{
types = new List<Type>();
details.TypeMap[type.Name] = types;
}
types.Add( type );
}
_details.Add( details );
}
示例5: GetAllPlayerActions
public static PlayerAction[] GetAllPlayerActions(System.Reflection.Assembly assembly)
{
var result = new List<PlayerAction>();
foreach (Type innerType in assembly.GetTypes())
{
if (!innerType.IsClass)
continue;
if (innerType.Namespace != "Strategies")
continue;
System.Reflection.MethodInfo playerMethodInfo = innerType.GetMethod("Player", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
if (playerMethodInfo == null)
continue;
if (playerMethodInfo.ContainsGenericParameters)
continue;
if (playerMethodInfo.GetParameters().Length > 0)
{
continue;
}
PlayerAction playerAction = playerMethodInfo.Invoke(null, new object[0]) as PlayerAction;
if (playerAction == null)
continue;
result.Add(playerAction);
}
return result.ToArray();
}
示例6: Start
public bool Start(
System.Reflection.Assembly DatabaseAssembly,
Action<String> Output)
{
GameInfo gameInfo = null;
foreach (var type in DatabaseAssembly.GetTypes())
if (type.IsSubclassOf(typeof(GameInfo)))
gameInfo = Activator.CreateInstance(type) as GameInfo;
if (gameInfo == null) throw new InvalidOperationException("No GameInfo defined in game assembly.");
var assemblies = new List<ModuleAssembly>();
assemblies.Add(new ModuleAssembly(DatabaseAssembly, new ModuleInfo { BaseNameSpace = gameInfo.DatabaseNameSpace }));
foreach (var module in gameInfo.Modules)
assemblies.Add(new ModuleAssembly(module));
if (RMUD.Core.Start(StartupFlags.Silent,
new RMUD.SinglePlayer.CompiledDatabase(DatabaseAssembly, gameInfo.DatabaseNameSpace),
assemblies.ToArray()))
{
Player = RMUD.MudObject.GetObject<RMUD.Player>(RMUD.Core.SettingsObject.PlayerBaseObject);
Player.CommandHandler = RMUD.Core.ParserCommandHandler;
Client = new DummyClient(Output);
RMUD.Core.TiePlayerToClient(Client, Player);
Player.Rank = 500;
DetectAndAssignDriver(DatabaseAssembly);
Core.GlobalRules.ConsiderPerformRule("singleplayer game started", Player);
return true;
}
return false;
}
示例7: buildTreeFromAssembly
public void buildTreeFromAssembly(System.Reflection.Assembly CurrentAsm)
{
//code from Platt's example
TreeNode BaseNode;
BaseNode = treeViewAssembly.Nodes.Add("Assy:" + CurrentAsm.GetName().ToString());
BaseNode.Tag = CurrentAsm;
// Enumerate each type contained in the assembly
foreach (System.Type ThisType in CurrentAsm.GetTypes())
{
TreeNode MyNode;
MyNode = BaseNode.Nodes.Add(ThisType.ToString() + " : " + ThisType.BaseType.ToString());
MyNode.Tag = ThisType;
// Enumerate all the members of this type
// Add each member to the tree
foreach (System.Reflection.MemberInfo Member in
ThisType.GetMembers(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static))
{
TreeNode typenode = MyNode.Nodes.Add(Member.MemberType.ToString() + " : " + Member.Name);
typenode.Tag = Member;
}
}
}
示例8: AssemblyInfo
public AssemblyInfo(System.Reflection.Assembly assembly, bool structure)
{
Classes = new List<TypeInfo>();
Interfaces = new List<InterfaceInfo>();
Enumerations = new List<EnumInfo>();
Exceptions = new List<ExceptionInfo>();
Attributes = new List<AttributeInfo>();
Structures = new List<StructureInfo>();
try
{
foreach (Type type in assembly.GetTypes())
if (type.IsSubclassOf(typeof(System.Exception)))
Exceptions.Add(new ExceptionInfo(type));
else if (type.IsSubclassOf(typeof(System.Attribute)))
Attributes.Add(new AttributeInfo(type));
else if (type.IsClass)
Classes.Add(new TypeInfo(type));
else if (type.IsInterface)
Interfaces.Add(new InterfaceInfo(type));
else if (type.IsEnum)
Enumerations.Add(new EnumInfo(type));
}
catch (Exception ex)
{
}
if (!structure)
return;
Structure = NamespaceInfo.CreateStructureByAssembly(this);
}
示例9: AddByAssembly
internal void AddByAssembly(System.Reflection.Assembly assembly)
{
var commands = assembly.GetTypes().Where(t => typeof(ICommand) == t.BaseType);
foreach (var type in commands)
{
// this.Add(type);
}
}
示例10: Register
public static void Register(System.Reflection.Assembly assembly)
{
foreach (Type type in assembly.GetTypes())
{
if(!type.IsAbstract && !type.IsInterface && type.GetCustomAttributes(typeof(ProtoContractAttribute),false).Length>0)
mTables[type.Name]=type;
}
}
示例11: ServerRepo
public ServerRepo(string prefix, System.Reflection.Assembly typesAsm)
{
_subscriptions = new Dictionary<string, Subscription>();
_types = new List<Type>(typesAsm.GetTypes());
_server = new Server (this, prefix);
_handlersByClientId = new Dictionary<string, ClientHandler> ();
_queryInfos = new Dictionary<string, Dictionary<SqlQuery, QueryInfo>> ();
}
示例12: Register
public static void Register(System.Reflection.Assembly assembly)
{
foreach (Type type in assembly.GetTypes())
{
if(!type.IsAbstract && !type.IsInterface)
mTables[type.FullName]=type;
}
}
示例13: DiscoverHardware
static void DiscoverHardware(System.Reflection.Assembly Assembly)
{
foreach (var type in Assembly.GetTypes())
{
var attr = type.GetCustomAttributes(false).FirstOrDefault(a => a is HardwareAttribute) as HardwareAttribute;
if (attr != null && !HardwareTypes.ContainsKey(attr.ID))
HardwareTypes.Add(attr.ID, type);
}
}
示例14: DiscoverClasses
public static void DiscoverClasses(System.Reflection.Assembly assembly)
{
var collection = GetMarkedTypes(assembly.GetTypes().AsParallel(), typeof(ContextClassAttribute));
foreach (var type in collection)
{
RegisterSystemType(type);
}
}
示例15: GetTableClasses
/// <summary>
/// Get all the DTOs/classes that will be stored in our data storage
/// </summary>
/// <param name="assembly"></param>
/// <returns></returns>
public static IEnumerable<Type> GetTableClasses(System.Reflection.Assembly assembly)
{
foreach (Type type in assembly.GetTypes())
{
if (type.GetCustomAttributes(typeof(TableAttribute), true).Length > 0)
{
yield return type;
}
}
}