感谢下面这篇博文给我的思路: http://www.cnblogs.com/daimage/archive/2012/04/10/2440186.html 上面文章的博主给出的代码是可用的,但是调用方法时需要写的代码过于冗长,例如博主给出的示例代码 var name = TypeInfoHelper.GetClassPropertiesName<MyClass,List<string>>(s => myClass.UserName); 代码中的List<string&g
public class TypeInfoHelper { public static string GetPropertyName<T>(Expression<Func<T, dynamic>> property) { var propertyName = string.Empty; var body = property.Body; if (body.NodeType == ExpressionType.Convert) { var o = (body as Una
用反射控制的,不过获取属性名称的方法,用方法形式获取的,不知道消耗大不大 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Qxun.Framework.Utility; using System.Linq.Expressions; namespace ConsoleApplication1 { clas
package junereflect624; import java.lang.reflect.Modifier; class A { } interface B{ } interface C{ } public class BaseDemo3 extends A implements B,C{ //内部类 public class C{} public interface D{} public static void main(String[] args) { //类可以,接口也可以 Cla
如何获取类或属性的自定义特性(Attribute) 问题说明: 在ActiveRecord或者其他的ORM等代码中, 我们经常可以看到自定义特性(Attribute)的存在(如下面的代码所示) [PrimaryKey(PrimaryKeyType.Native, "PostId")] public int Id { ...... } 看似非常神秘的东西, 我们在什么场合需要使用它, 我们该如何使用它?自定义特性(Attribute)在一些需要声明