- 浏览: 3015900 次
- 性别:
- 来自: 海外
文章分类
- 全部博客 (430)
- Programming Languages (23)
- Compiler (20)
- Virtual Machine (57)
- Garbage Collection (4)
- HotSpot VM (26)
- Mono (2)
- SSCLI Rotor (1)
- Harmony (0)
- DLR (19)
- Ruby (28)
- C# (38)
- F# (3)
- Haskell (0)
- Scheme (1)
- Regular Expression (5)
- Python (4)
- ECMAScript (2)
- JavaScript (18)
- ActionScript (7)
- Squirrel (2)
- C (6)
- C++ (10)
- D (2)
- .NET (13)
- Java (86)
- Scala (1)
- Groovy (3)
- Optimization (6)
- Data Structure and Algorithm (3)
- Books (4)
- WPF (1)
- Game Engines (7)
- 吉里吉里 (12)
- UML (1)
- Reverse Engineering (11)
- NSIS (4)
- Utilities (3)
- Design Patterns (1)
- Visual Studio (9)
- Windows 7 (3)
- x86 Assembler (1)
- Android (2)
- School Assignment / Test (6)
- Anti-virus (1)
- REST (1)
- Profiling (1)
- misc (39)
- NetOA (12)
- rant (6)
- anime (5)
- Links (12)
- CLR (7)
- GC (1)
- OpenJDK (2)
- JVM (4)
- KVM (0)
- Rhino (1)
- LINQ (2)
- JScript (0)
- Nashorn (0)
- Dalvik (1)
- DTrace (0)
- LLVM (0)
- MSIL (0)
最新评论
-
mldxs:
虽然很多还是看不懂,写的很好!
虚拟机随谈(一):解释器,树遍历解释器,基于栈与基于寄存器,大杂烩 -
HanyuKing:
Java的多维数组 -
funnyone:
Java 8的default method与method resolution -
ljs_nogard:
Xamarin workbook - .Net Core 中不 ...
LINQ的恶搞…… -
txm119161336:
allocatestlye1 顺序为 // Fields o ...
最近做的两次Java/JVM分享的概要
在IronPython 46307的MemberExpression.cs里,可以看到DLR是如何获取一个get或者set方法对应的属性的PropertyInfo的:
这代码太丑了,居然要自己遍历类型的所有属性,线性的一个个找 = =
.NET Framework的标准库怎么就不提供标准的方法来查询一个方法是否是某个属性的get或者set方法呢,属性明明不只是C#的概念,也是CLI的概念啊。看来类似的功能得加到自己的utils里去,不然每次都这么搞太麻烦了。
DLR里有很多扩展方法都值得借鉴,因为光靠.NET标准库提供的方法很多时候还是会重复不少代码的。像是一些对数组的扩展方法就挺不错的。
/// <summary> /// Creates a <see cref="MemberExpression"/> accessing a property. /// </summary> /// <param name="expression">The containing object of the property. This can be null for static properties.</param> /// <param name="propertyAccessor">An accessor method of the property to be accessed.</param> /// <returns>The created <see cref="MemberExpression"/>.</returns> public static MemberExpression Property(Expression expression, MethodInfo propertyAccessor) { ContractUtils.RequiresNotNull(propertyAccessor, "propertyAccessor"); ValidateMethodInfo(propertyAccessor); return Property(expression, GetProperty(propertyAccessor)); } private static PropertyInfo GetProperty(MethodInfo mi) { Type type = mi.DeclaringType; BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic; flags |= (mi.IsStatic) ? BindingFlags.Static : BindingFlags.Instance; PropertyInfo[] props = type.GetProperties(flags); foreach (PropertyInfo pi in props) { if (pi.CanRead && CheckMethod(mi, pi.GetGetMethod(true))) { return pi; } if (pi.CanWrite && CheckMethod(mi, pi.GetSetMethod(true))) { return pi; } } throw Error.MethodNotPropertyAccessor(mi.DeclaringType, mi.Name); } private static bool CheckMethod(MethodInfo method, MethodInfo propertyMethod) { if (method == propertyMethod) { return true; } // If the type is an interface then the handle for the method got by the compiler will not be the // same as that returned by reflection. // Check for this condition and try and get the method from reflection. Type type = method.DeclaringType; if (type.IsInterface && method.Name == propertyMethod.Name && type.GetMethod(method.Name) == propertyMethod) { return true; } return false; }
这代码太丑了,居然要自己遍历类型的所有属性,线性的一个个找 = =
.NET Framework的标准库怎么就不提供标准的方法来查询一个方法是否是某个属性的get或者set方法呢,属性明明不只是C#的概念,也是CLI的概念啊。看来类似的功能得加到自己的utils里去,不然每次都这么搞太麻烦了。
DLR里有很多扩展方法都值得借鉴,因为光靠.NET标准库提供的方法很多时候还是会重复不少代码的。像是一些对数组的扩展方法就挺不错的。
发表评论
-
对象的重量
2011-08-21 17:15 0http://domino.research.ibm.com/ ... -
IronRuby 1.1系的自适应执行(解释/编译的混合模式)
2010-10-29 14:12 0IronRuby自身的compiler部分基本上还是保持不变的 ... -
Expression Tree中的Constant被编译后放到哪里去了?
2010-02-28 16:21 0Expression.Constant()可以放任意对象进去作 ... -
拿ETv2来生成方法体的两种阳春办法
2009-09-22 06:03 0System.Type System.Reflection.E ... -
C#的语言结构到Expression Tree v2的映射
2009-05-21 03:11 0在.NET Framework 4 Beta 1中,Expre ... -
.NET Framework 4.0 Beta 1里的Expression Tree一例
2009-05-20 10:23 2876既然装上了Visual Studio 20 ... -
用Iron-*语言来探索.NET
2009-05-15 23:21 3345刚才写代码的时候又是在不停查文档,甚是心烦。一怒,拿出Iron ... -
自己关于VM的帖的目录
2009-04-07 14:02 68796JavaEye的blog系统只允许把帖放到单一类别下,而不能用 ... -
MIX09上关于DLR解释器消息的一段听记(3月26更新IronPython 2.6A1消息)
2009-03-23 21:09 1799John Lam在MIX 09上做了一个关于动态语言与Silv ... -
答复: C# 4 DLR & Java 7 Invokedynamic
2009-03-22 17:12 2966原帖地址:C# 4 DLR & Java 7 Invo ... -
同一个ParameterExpression被用在不同嵌套层次的lambda里会怎样?
2009-01-16 00:22 2557今天写代码的时候不小心写错了几个地方,把同一个Paramete ... -
CodePlex上放出DLR v0.9 beta
2008-11-27 14:34 1936之前提到过DLR会在CodePlex上拥有自己独立的项目页面, ... -
IronRuby (r170)中respond_to?的实现
2008-11-13 23:29 0IronRuby.Libraries/Builtins/Ker ... -
DLR中的binder的演变
2008-11-11 23:29 0从模糊的“标准消息”转变为明确完整的MetaObject Pr ... -
DLR即将在Codelex开设独立的站点
2008-10-29 23:01 1406DLR官网:Dynamic Language Runtime ... -
IronPython放出RC1
2008-10-23 09:59 1787下载链接:http://www.codep ... -
新的DLR tree改变了Visitor的设计
2008-10-09 00:35 1581之前的一帖提到过访问DLR tree所使用的visitor的实 ... -
对比DLR
2008-10-08 04:32 0Managed JScript: // // AST: E ... -
目前DLR执行一棵DLR tree的过程(针对10月3日的ChangeSet 41087)
2008-10-07 01:46 1733先在Microsoft.Scripting.Actions.C ... -
LINQ与DLR的Expression tree(4):创建静态类型的LINQ表达式树节点
2008-09-27 00:18 9309(Disclaimer:如果需要转载请先与我联系;文中图片请不 ...
相关推荐
public string Name { get; set; } public bool Gender; public string ShowLove(string targetName) { return targetName + ", i love u .msg from " + this.Name; } public Student(string name) { ...
可以调用这些成员,其方式是调用Type的InvokeMember()方法,或者调用MethodInfo, PropertyInfo和其他类的Invoke()方法。 查看类中的构造方法: NewClassw nc = new NewClassw(); Type t = nc.GetType(); ...
对象为Assembly 可以获取到程序集文件 ... 对象MethodInfo 可以获得类的方法的对象 对象PropertyInfo可以获得类的字段的对象 对象FieldInfo 可以获得类的属性的对象 对象EventInfo 可以获得类的事件的对象
元数据(编译以后的最基本数据单元)就是一大堆的表,当编译程序集或者模块时,编译器会创建一个类定义表,一个字段定义表,和一个方法定义表等。 System.reflection命名空间包含的几个类,允许你反射(解析)这些...
在.NET 4.0(当然也包括4.0以前的版本)下,用反射判断某个方法是否运用了自定义Attribute时,可以通过调用MethodInfo的IsDefined()方法进行确认。...如果获得MethodInfo的方式是通过加载程序集,然后利
在.Net 中, 一旦获得了Type对象,就可以使用GetMethods()方法获取此类型支持的方法列表;该方法的两种形式: MethodInfo [] GetMethods() MethodInfo [] GetMethods(BindingFlags bindingflas) :它的参数带有一些...
一般来说,传统的思路是,通过Reflection.EventInfo获得事件的信息,然后使用GetRaiseMethod方法获得事件被触发后调用的方法,再使用MethodInfo.Invoke来调用以实现事件的动态调用。 但是很不幸的,Reflection....
var propMethod = ctxType.GetMethod("set_ParameterArgs"); il.Emit(OpCodes.Ldloc, ctx); il.Emit(OpCodes.Ldloc_0); il.Emit(OpCodes.Call, propMethod); int m = attrs.Length; LocalBuilder[] lbs = new...
它适用于任何方法、实例或静态、无效返回或其他方式。 所有方法都以相同的方式绑定: using FastDelegate.Net; System.Reflection.MethodInfo myMethodInfo; // fill in myMethodInfo // ... Func<Object, ...
使用反射调用方法:一旦知道一个类型所支持的方法,就可以对方法进行调用。调用时,需使用包含在MethodInfo中的Invoke()方法。...要调用某个方法,只需在一个MethodInfo实例上调用Invoke(),该实例通过调用Ge
可通过NuGet获得弱点: PM>安装软件包 内容 建筑商 为以下内容创建编译的表达式: Builder.DynamicDelegate创建MethodInfo.Invoke的编译版本 Builder.OpenAction创建开放的委托 Builder.OpenFunc创建开放委托 ...
关于【C#反射】文章中涉及到的内容示例项目工程,包含如下功能: ①获取反射类型的三种方式; ②FieldInfo 通过反射获取对象的成员字段示例;...③MethodInfo 通过反射获取某个类的方法且执行示例;
Get-ILDisassembly 反汇编从MethodInfo对象传入的原始MSIL字节数组,其方式与Ildasm相似。恶意软件分析执行恶意软件分析时的有用工具。New-FunctionDelegate 提供X86或X86_64函数的可执行包装。Invoke-LoadLibrary ...
MethodInfo method = type.GetMethod(methodName); object[] parameters = new object[] { param }; // 创建实例;调用方法(传递参数,获取返回值) object instance = assembly.CreateInstance(type.ToString()...
Fastest MethodInfo.MakeGenericMethod ever! It's written using MSIL. 2.5x faster than the original method.
irelia-spi-core: spi 核心模块,提供 spi 的基本方法,如提取 IreliaBean、methodInfo 等。 irelia-spi-dubbo: 为 dubbo 项目提供的快速接入包。 Irelia-upstream: upstream 核心模块,提供了 upstream 的核心接口...
• ClassFile中FieldInfo和MethodInfo介绍 • 类型描述Descriptor介绍 • ClassFile中的Attribute介绍 • JVM指令介绍,获得ClassLoader的途径,CAS指令由硬件提供 • 并发程序设计实现的基础 • 486之后并不需要锁...
格式如下: 类:Autodesk.AutoCAD.ApplicationServices.DocumentLockModeWillChangeEventArgs:System.EventArgs ... Method AS System.Reflection.MethodInfo 可读不可写 Target AS System.Object 可读不可写
动态调用WebService的方法类,可以不用在VS本地引用,直接动态调用即可。 样例如下: /// /// 实例化WebServices /// /// <param name="url">WebServices地址 /// 调用的方法 /// 把webservices里需要的参数...
net.example.jaxrs 这些建立可用资源类和方法的注册表: PathInfo ResourceInfo MethodInfo Introspector 匹配算法的实现: RequestMatching RequestMatchingSpec RequestMatchingEnhanced MatchInfo – ...