首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏大内老A

    晚绑定场景下对象属性赋值和取值可以不需要PropertyInfo

    在这个程序中我们比较三种典型的属性操作耗费的时间:直接通过属性赋值(或者取值)、通过IL Emit(即PropertyAccessor)和PropertyInfo对属性赋值(或者取值)。 propertyInfo = typeof(Foo).GetProperty("Bar"); 8: stopwatch.Start(); 9: for (int i = 0 propertyInfo = typeof(Foo).GetProperty("Bar"); 7: stopwatch.Start(); 8: for (int i = 0 我们关心的是,IL Emit的方式和单纯使用PropertyInfo进行反射(并且值得一提的是:PropertyInfo之前已经保存起来,并没有频繁去创建)的方式这两者的性能依然有本质的差别。 三种属性操作性能比较:PropertyInfo + Expression Tree + Delegate.CreateDelegate 关于Expression Tree和IL Emit的所谓的"

    1.1K110发布于 2018-02-07
  • 来自专栏大内老A

    三种属性操作性能比较:PropertyInfo + Expression Tree + Delegate.CreateDelegate

    《上篇》主要介绍如何通过DataBinder实现批量的数据绑定,以及如何解决常见的数据绑定问题,比如数据的格式化。接下来,我们主要来谈谈DataBinder的设计,看看它是如何做到将作为数据源实体的属性值绑定到界面对应的控件上的。此外,需要特别说明一点:《上篇》中提供了DataBinder最初版本的下载,但已经和本篇文章介绍的已经大不一样了。最新版本的主要解决两个主要问题:通过Expression Tree的方式进行属性操作(属性赋值和取值),添加了“数据捕捉”(Data Capture)的功能,以实现将控

    1K110发布于 2018-02-08
  • 来自专栏DotNet NB && CloudNative

    C# 中的高性能动态属性访问方法

    Person person =newPerson{ Name ="Alice", Age =}; Type type = person.GetType(); PropertyInfo propertyInfo = type.GetProperty("Name"); string name =(string)propertyInfo.GetValue(person); > cache =newDictionary<string, PropertyInfo>(); publicstaticPropertyInfoGetPropertyInfo(object obj cache.ContainsKey(cacheKey)) { PropertyInfo propertyInfo = type.GetProperty(propertyName propertyInfo = ReflectionCache.GetPropertyInfo(person,"Name"); string name =(string)propertyInfo.GetValue

    82010编辑于 2025-03-27
  • 来自专栏微卡智享

    【干货】C#根据类生成签名字符串(附DEMO下载地址)

    public string GetSign<T>(T t, int otype=1) { string retstr = ""; //定义PropertyInfo 的List List<PropertyInfo> proplist = new List<PropertyInfo>(); //遍历泛型类的每个属性加入到List里面 Array.ForEach<PropertyInfo>(typeof(T).GetProperties(), p => proplist.Add(p)); //根据参数进行排序 (这个的用法我们就不在这介绍了,大家可以搜一下),其实 PropertyInfo里的Name就是我们的类里属性的名称,GetValue就是我们获取的属性的值。 代码里的实现步骤: 定义生成的List<PropertyInfo>(new List<PropertyInfo>()) 把传入进来的泛型类的属性生数组,然后再插入到我们的List里面(List.add(

    1.4K20发布于 2019-07-25
  • 来自专栏magicodes

    Magicodes.IE 2.3重磅发布——.NET Core开源导入导出库

    fieldsAfterSplit) { var propertyName = field.Trim(); var propertyInfo = typeof(Person).GetProperty(propertyName); ​ if (propertyInfo == null) ) { var shapedObj = new ExpandoObject(); ​ foreach (var propertyInfo in propertyInfoList) { var propertyValue = propertyInfo.GetValue (person); ((IDictionary<string, object>)shapedObj).Add(propertyInfo.Name, propertyValue

    66720发布于 2020-09-18
  • 来自专栏雪雁的专栏

    Magicodes.IE 2.3重磅发布——.NET Core开源导入导出库

    fieldsAfterSplit) { var propertyName = field.Trim(); var propertyInfo = typeof(Person).GetProperty(propertyName); if (propertyInfo == null) Property: {propertyName} 没有找到:{typeof(Person)}"); } propertyInfoList.Add(propertyInfo in propertyInfoList) { var propertyValue = propertyInfo.GetValue (person); ((IDictionary<string, object>)shapedObj).Add(propertyInfo.Name, propertyValue

    66310发布于 2020-09-18
  • 来自专栏草根专栏

    使用 dynamic 类型让 ASP.NET Core 实现 HATEOAS 结构的 RESTful API

    BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); foreach (var propertyInfo var propertyInfo = typeof(TSource).GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); if (propertyInfo == null) { in propertyInfoList) { var propertyValue = propertyInfo.GetValue (sourceObject); ((IDictionary<string, object>)dataShapedObject).Add(propertyInfo.Name

    1.5K60发布于 2018-04-19
  • 来自专栏跟着阿笨一起玩NET

    .NET常用的扩展方法整理

    [] propertyInfo = jsonObject.GetType().GetProperties(); for (int i = 0; i < propertyInfo.Length ; i++) { object objectValue = propertyInfo[i].GetGetMethod().Invoke(jsonObject (); foreach (PropertyInfo pro in properties) { foreach = target.GetType()) return; PropertyInfo[] properties = target.GetType(). GetProperties(); foreach (PropertyInfo pro in properties) { if

    1.4K10发布于 2018-09-19
  • 来自专栏.NET企业级解决方案应用与咨询

    xBIM 高级02 插入复制功能

    == nameof(IIfcProduct.IsDefinedBy) || property.PropertyInfo.Name == nameof(IIfcProduct.IsTypedBy ) )) return null; return property.PropertyInfo.GetValue(parentObject, null); }; ( property.PropertyInfo.Name == nameof(IIfcProduct.IsDefinedBy) || property.PropertyInfo.Name == nameof(IIfcProduct.IsTypedBy) )) return null; return property.PropertyInfo.GetValue(parentObject, null);

    82110发布于 2019-09-17
  • 来自专栏林德熙的博客

    dotnet 5 静态字段和属性的反射获取 没有想象中那么伤性能

    ,分别是缓存起来字段或属性的 FieldInfo 或 PropertyInfo 对象,用来减少 GetField 或 GetProperty 方法的调用。 propertyInfo) { _propertyInfo = propertyInfo; } } private readonly PropertyInfo _propertyInfo; } 而根据 Type 和对应的字段或属性名可以获取静态的字段或属性的方法 propertyInfo) { _propertyInfo = propertyInfo; } } private readonly PropertyInfo _propertyInfo; } private bool GetFieldOrPropertyValueWithCache

    1.5K10发布于 2021-01-29
  • 来自专栏林德熙的博客

    C# 解析 sln 文件 使用

    Microsoft.Build, Version=4.0.0.0 static readonly Type s_SolutionParser; static readonly PropertyInfo s_ProjectInSolution_ProjectName; static readonly PropertyInfo s_ProjectInSolution_RelativePath ; static readonly PropertyInfo s_ProjectInSolution_ProjectGuid; static readonly PropertyInfo configInSolution_configurationname; static readonly PropertyInfo configInSolution_fullName; static readonly PropertyInfo configInSolution_platformName; static SolutionConfiguration

    1.7K00发布于 2018-09-18
  • 来自专栏一枝花算不算浪漫的专栏

    [C#反射]C#中的反射解析及使用.

    的多个公用行为  Module            该类可以使你能访问多个程序集中的给定模块  ParameterInfo 该类保存给定的参数信息        PropertyInfo    该类保存给定的属性信息 [] listPropertyInfo=type.GetProperties(); 3 foreach(PropertyInfo propertyInfo in listPropertyInfo) 4 propertyInfo=obj.GetProperty("Name"); //获取Name属性对象 5 var name=propertyInfo.GetValue(obj,null); //获取Name属性的值 6 PropertyInfo propertyInfo2=obj.GetProperty("Age"); //获取Age属性对象 7 propertyInfo.SetValue propertyInfo=type.GetProperty("Name"); //获取Example类的Name属性 11 foreach (object attribute in propertyInfo.GetCustomAttributes

    2.6K140发布于 2018-05-18
  • 来自专栏跟着阿笨一起玩NET

    C# 对JS编码/解码进行转换

    this T o, bool isEscape = false) { object objValue; System.Reflection.PropertyInfo [] propertys = o.GetType().GetProperties(); foreach (System.Reflection.PropertyInfo p in ToJSEncodeEntity<T>(this T o) { object objValue; System.Reflection.PropertyInfo [] propertys = o.GetType().GetProperties(); foreach (System.Reflection.PropertyInfo p in [] propertys = o.GetType().GetProperties(); foreach (System.Reflection.PropertyInfo p in

    5.8K20发布于 2018-09-19
  • 来自专栏林德熙的博客

    C# 使用反射获取私有属性的方法

    Foo { private string F { set; get; } = "123"; } 如果需要拿到 Foo 的 属性 F 可以通过 PropertyInfo 直接拿到,从一个类拿到对应的 PropertyInfo 可以通过下面的代码 var foo = new Foo(); var type = foo.GetType | BindingFlags.Public | BindingFlags.NonPublic; var propertyName = "F"; PropertyInfo ) { throw new MissingFieldException(propertyName); } 现在就获得了 PropertyInfo | BindingFlags.Public | BindingFlags.NonPublic; var propertyName = "F"; PropertyInfo

    2.5K10编辑于 2022-08-04
  • 来自专栏全栈程序员必看

    【c#】把Dataset类型转为List<T>

    创建泛型对象 T _t = Activator.CreateInstance<T>(); //获取对象所有属性 PropertyInfo [] propertyInfo = _t.GetType().GetProperties(); for (int j = 0; j < dt.Columns.Count; j++) { foreach (PropertyInfo info in propertyInfo)

    1.8K20编辑于 2022-08-10
  • 来自专栏C#

    浅析.NET的反射特性

    [MethodImplAttribute(MethodImplOptions.InternalCall)] public extern Type GetType();       (2).PropertyInfo 的GetProperty()方法: public PropertyInfo GetProperty(String name,BindingFlags bindingAttr,Binder binder GetPropertyImpl(name,Type.DefaultLookup,null,returnType,types,modifiers); } public PropertyInfo return GetPropertyImpl(name,bindingAttr,null,null,null,null); } public PropertyInfo </returns> public static IEnumerable<PropertyInfo> GetProperties(this object obj, BindingFlags

    89470发布于 2018-01-04
  • 来自专栏walterlv - 吕毅的博客

    如何快速编写和调试 Emit 生成 IL 的代码

    public static Action<object, object> CreatePropertySetter(PropertyInfo propertyInfo) { var declaringType = propertyInfo.DeclaringType; var propertyType = propertyInfo.PropertyType; // 创建一个动态方法,参数依次为方法名 var setValue = QuickEmit.CreatePropertySetter(propertyInfo); // 测试生成的核心代码能否正常工作。 public static void OutputPropertySetter(PropertyInfo propertyInfo) { var declaringType = propertyInfo.DeclaringType ; var propertyType = propertyInfo.PropertyType; // 准备好要生成的程序集的信息。

    2K10发布于 2018-09-18
  • 来自专栏跟着阿笨一起玩NET

    C#反射读取和设置类的属性

    = Activator.CreateInstance(type); T instance = obj as T; System.Reflection.PropertyInfo propertyInfo = type.GetProperty("Url"); fullWebUrlPath = Prefix_WebServiceURL + string.Format ("/{0}/{0}.asmx", type.Name); propertyInfo.SetValue(obj, fullWebUrlPath, null);

    3.5K10发布于 2018-09-19
  • 来自专栏跟着阿笨一起玩NET

    DataGridView列自适应宽度

    { 167 //通过反射的方式添加列 168 Type type = typeof(FileMessage); 169 PropertyInfo [] propertyInfos = type.GetProperties(); 170 foreach (PropertyInfo propertyInfo in propertyInfos ) 171 { 172 object[] objs = propertyInfo.GetCustomAttributes(typeof(DescriptionAttribute

    2.5K10发布于 2018-09-20
  • 来自专栏明明如月的技术专栏

    使用 BeanUtils.getProperty 获取属性时出现 NoSuchMethodException: Unknown property 问题分析

    代码如下: public static Map<String,PropertyInfo> get(Class<? returnType.equals(void.class) && isPrefix(name, "get")) { PropertyInfo info propertyInfo.initialize()); return !map.isEmpty() ? this property as a bound property * * @since 9 */ PropertyDescriptor(Entry<String,PropertyInfo > entry, boolean bound) { String base = entry.getKey(); PropertyInfo info = entry.getValue

    2.5K40编辑于 2023-03-10
领券