用PowerShell探索System.RuntimeType类型
来源:互联网 发布:ubuntu java 路径 编辑:程序博客网 时间:2024/06/05 07:46
PowerShell绝对是学习.Net Framework的好工具, 这句话是PowerShell团队中某人说的, 实际确实如此, 我们可以通过Get-Member来窥探.Net中很多神秘的元素. 要学习.Net Framework, 我想很多人会拜读Jeffrey Richter所编写的<<Applied Microsoft .NET Framework Programming>>一书.
.Net Framework中的类在加载到应用域(Application Domain)时, 转化为System.RuntimeType的一个实例, System.RuntimeType是一个非公开的类, 你无法在MSDN上找到详细信息, PowerShell提供了简单途径来窥探System.RuntimeType中的成员. 在Jeffrey Richter书中也介绍过System.RuntimeType的内容, 我们下面以System.String为例, 用PowerShell进行详细介绍:
PS C:/> [System.String].GetType().FullName
System.RuntimeType
我们看到了神秘System.RuntimeType类的实例, 我们可以用Get-Member看看这个类上都有哪些成员:
PS C:/> [System.String] | Get-Member | Sort-Object MemberType, Name
TypeName: System.RuntimeType
Name MemberType Definition
---- ---------- ----------
Assembly Property System.Reflection.Assembly Assembly {get;}
AssemblyQualifiedName Property System.String AssemblyQualifiedName {get;}
Attributes Property System.Reflection.TypeAttributes Attributes {get;}
BaseType Property System.Type BaseType {get;}
ContainsGenericParameters Property System.Boolean ContainsGenericParameters {get;}
DeclaringMethod Property System.Reflection.MethodBase DeclaringMethod {get;}
DeclaringType Property System.Type DeclaringType {get;}
FullName Property System.String FullName {get;}
GenericParameterAttributes Property System.Reflection.GenericParameterAttributes GenericParameterAttributes {g...
GenericParameterPosition Property System.Int32 GenericParameterPosition {get;}
GUID Property System.Guid GUID {get;}
HasElementType Property System.Boolean HasElementType {get;}
IsAbstract Property System.Boolean IsAbstract {get;}
IsAnsiClass Property System.Boolean IsAnsiClass {get;}
IsArray Property System.Boolean IsArray {get;}
IsAutoClass Property System.Boolean IsAutoClass {get;}
IsAutoLayout Property System.Boolean IsAutoLayout {get;}
IsByRef Property System.Boolean IsByRef {get;}
IsClass Property System.Boolean IsClass {get;}
IsCOMObject Property System.Boolean IsCOMObject {get;}
IsContextful Property System.Boolean IsContextful {get;}
IsEnum Property System.Boolean IsEnum {get;}
IsExplicitLayout Property System.Boolean IsExplicitLayout {get;}
IsGenericParameter Property System.Boolean IsGenericParameter {get;}
IsGenericType Property System.Boolean IsGenericType {get;}
IsGenericTypeDefinition Property System.Boolean IsGenericTypeDefinition {get;}
IsImport Property System.Boolean IsImport {get;}
IsInterface Property System.Boolean IsInterface {get;}
IsLayoutSequential Property System.Boolean IsLayoutSequential {get;}
IsMarshalByRef Property System.Boolean IsMarshalByRef {get;}
IsNested Property System.Boolean IsNested {get;}
IsNestedAssembly Property System.Boolean IsNestedAssembly {get;}
IsNestedFamANDAssem Property System.Boolean IsNestedFamANDAssem {get;}
IsNestedFamily Property System.Boolean IsNestedFamily {get;}
IsNestedFamORAssem Property System.Boolean IsNestedFamORAssem {get;}
IsNestedPrivate Property System.Boolean IsNestedPrivate {get;}
IsNestedPublic Property System.Boolean IsNestedPublic {get;}
IsNotPublic Property System.Boolean IsNotPublic {get;}
IsPointer Property System.Boolean IsPointer {get;}
IsPrimitive Property System.Boolean IsPrimitive {get;}
IsPublic Property System.Boolean IsPublic {get;}
IsSealed Property System.Boolean IsSealed {get;}
IsSerializable Property System.Boolean IsSerializable {get;}
IsSpecialName Property System.Boolean IsSpecialName {get;}
IsUnicodeClass Property System.Boolean IsUnicodeClass {get;}
IsValueType Property System.Boolean IsValueType {get;}
IsVisible Property System.Boolean IsVisible {get;}
MemberType Property System.Reflection.MemberTypes MemberType {get;}
MetadataToken Property System.Int32 MetadataToken {get;}
Module Property System.Reflection.Module Module {get;}
Name Property System.String Name {get;}
Namespace Property System.String Namespace {get;}
ReflectedType Property System.Type ReflectedType {get;}
StructLayoutAttribute Property System.Runtime.InteropServices.StructLayoutAttribute StructLayoutAttribute...
TypeHandle Property System.RuntimeTypeHandle TypeHandle {get;}
TypeInitializer Property System.Reflection.ConstructorInfo TypeInitializer {get;}
UnderlyingSystemType Property System.Type UnderlyingSystemType {get;}
Clone Method System.Object Clone()
Equals Method System.Boolean Equals(Object obj), System.Boolean Equals(Type o)
FindInterfaces Method System.Type[] FindInterfaces(TypeFilter filter, Object filterCriteria)
FindMembers Method System.Reflection.MemberInfo[] FindMembers(MemberTypes memberType, Binding...
GetArrayRank Method System.Int32 GetArrayRank()
GetConstructor Method System.Reflection.ConstructorInfo GetConstructor(BindingFlags bindingAttr,...
GetConstructors Method System.Reflection.ConstructorInfo[] GetConstructors(BindingFlags bindingAt...
GetCustomAttributes Method System.Object[] GetCustomAttributes(Boolean inherit), System.Object[] GetC...
GetDefaultMembers Method System.Reflection.MemberInfo[] GetDefaultMembers()
GetElementType Method System.Type GetElementType()
GetEvent Method System.Reflection.EventInfo GetEvent(String name, BindingFlags bindingAttr...
GetEvents Method System.Reflection.EventInfo[] GetEvents(BindingFlags bindingAttr), System....
GetField Method System.Reflection.FieldInfo GetField(String name, BindingFlags bindingAttr...
GetFields Method System.Reflection.FieldInfo[] GetFields(BindingFlags bindingAttr), System....
GetGenericArguments Method System.Type[] GetGenericArguments()
GetGenericParameterConstraints Method System.Type[] GetGenericParameterConstraints()
GetGenericTypeDefinition Method System.Type GetGenericTypeDefinition()
GetHashCode Method System.Int32 GetHashCode()
GetInterface Method System.Type GetInterface(String fullname, Boolean ignoreCase), System.Type...
GetInterfaceMap Method System.Reflection.InterfaceMapping GetInterfaceMap(Type ifaceType)
GetInterfaces Method System.Type[] GetInterfaces()
GetMember Method System.Reflection.MemberInfo[] GetMember(String name, MemberTypes type, Bi...
GetMembers Method System.Reflection.MemberInfo[] GetMembers(BindingFlags bindingAttr), Syste...
GetMethod Method System.Reflection.MethodInfo GetMethod(String name, BindingFlags bindingAt...
GetMethods Method System.Reflection.MethodInfo[] GetMethods(BindingFlags bindingAttr), Syste...
GetNestedType Method System.Type GetNestedType(String fullname, BindingFlags bindingAttr), Syst...
GetNestedTypes Method System.Type[] GetNestedTypes(BindingFlags bindingAttr), System.Type[] GetN...
GetObjectData Method System.Void GetObjectData(SerializationInfo info, StreamingContext context)
GetProperties Method System.Reflection.PropertyInfo[] GetProperties(BindingFlags bindingAttr), ...
GetProperty Method System.Reflection.PropertyInfo GetProperty(String name, BindingFlags bindi...
GetType Method System.Type GetType(), System.Type GetType()
InvokeMember Method System.Object InvokeMember(String name, BindingFlags bindingFlags, Binder ...
IsAssignableFrom Method System.Boolean IsAssignableFrom(Type c)
IsDefined Method System.Boolean IsDefined(Type attributeType, Boolean inherit)
IsInstanceOfType Method System.Boolean IsInstanceOfType(Object o)
IsSubclassOf Method System.Boolean IsSubclassOf(Type type)
MakeArrayType Method System.Type MakeArrayType(), System.Type MakeArrayType(Int32 rank)
MakeByRefType Method System.Type MakeByRefType()
MakeGenericType Method System.Type MakeGenericType(Type[] instantiation)
MakePointerType Method System.Type MakePointerType()
ToString Method System.String ToString()
我们可以通过System.RuntimeType上的GetContructors方法知道System.String上的构造函数:
PS C:/> [System.String].GetConstructors() | %{ $_.ToString() }
Void .ctor(Char*)
Void .ctor(Char*, Int32, Int32)
Void .ctor(SByte*)
Void .ctor(SByte*, Int32, Int32)
Void .ctor(SByte*, Int32, Int32, System.Text.Encoding)
Void .ctor(Char[], Int32, Int32)
Void .ctor(Char[])
Void .ctor(Char, Int32)
下面是MSDN上关于System.String类构造器的定义:
是不是很方便呢??
- 用PowerShell探索System.RuntimeType类型
- 个推推送时,Log4net 无法将类型"System.RuntimeType"的对象强制转换为类型"log4net
- 用PowerShell删除所有指定类型的文件
- 探索Settings.System.putInt()
- 探索Settings.System.putInt()
- 用powershell
- 探索 System P 逻辑分区
- 合理运用PowerShell中的异常处理类型
- 在PowerShell中使用枚举类型
- 用PowerShell下载网页
- 用PowerShell做音乐
- 用Powershell下载文件
- 用 PowerShell 读写注册表
- 用PowerShell隐藏磁盘驱动器
- 用PowerShell做计算
- PowerShell
- PowerShell
- PowerShell
- 几秒后才能点按扭的源代码
- J2EE总体的学习步骤
- 配置jboss,mysql,seam,eclipse步骤(一)
- 配置jboss,mysql,seam,eclipse步骤(二)
- 配置jboss,mysql,seam,eclipse步骤(三)
- 用PowerShell探索System.RuntimeType类型
- asp删除文件夹中的文件
- 工作中娱乐人生, 是我么向往的境界!
- 发布一个本人开发的一个js验证框架
- 写了一个MYSQL的行转列的存储过程 zz
- 在fedora 9 上给我的TP-Link 620G+网卡安装驱动
- 8253实验
- Linux下Mail命令收集 - linux windows network - linux windows centos windows2003
- Linux下Mail命令收集 - linux windows network - linux windows centos windows2003