c# 如何通过反射 获取\设置属性值
c# 如何通过反射 获取\设置属性值
//定义类
public class MyClass
{
public int Property1 { get; set; }
}
static void Main()
{
MyClass tmp_Class = new MyClass();
tmp_Class.Property1 = 2;
Type type = tmp_Class.GetType(); //获取类型
System.Reflection.PropertyInfo propertyInfo = type.GetProperty("Property1"); //获取指定名称的属性
int value_Old = (int)propertyInfo.GetValue(tmp_Class, null); //获取属性值
Console.WriteLine(value_Old);
propertyInfo.SetValue(tmp_Class, 5, null); //给对应属性赋值
int value_New = (int)propertyInfo.GetValue(tmp_Class, null);
Console.WriteLine(value_New);
}
c# 如何通过反射 获取\设置属性值的更多相关文章
- c# 如何通过反射 获取\设置属性值、
//定义类public class MyClass{public int Property1 { get; set; }}static void Main(){MyClass tmp_Class = ...
- c#利用反射获取对象属性值
public static string GetObjectPropertyValue<T>(T t, string propertyname){ Type type = type ...
- 【java】之Method和Field反射获取和设置属性值
package com.javaluna.reflect; import java.lang.reflect.Field; import java.lang.reflect.Method; impor ...
- 如何获取value值,获取属性值,设置属性值,
1.获取select下拉框的value值, 2.获取select 的tid值 3.设置属性值 4.判断哪个单选框选中了 prop好像是判断的意思吧,个人理解勿喷谢谢!!!!!!
- JS中使用document.defaultView.getComputedStyle()、currentStyle()方法获取CSS属性值
在对网页进行调试的过程中,经常会用到js来获取元素的CSS样式,方法有很多很多,现在仅把我经常用的方法总结如: 1. obj.style:这个方法只能JS只能获取写在html标签中的写在style属性 ...
- java 通过反射获取类属性结构,类方法,类父类及其泛型,类,接口和包
首先自定义三个类 package reflection1; public interface MtInterface { void info(); } package reflection1; imp ...
- 2019-4-16-C#-使用反射获取私有属性的方法
title author date CreateTime categories C# 使用反射获取私有属性的方法 lindexi 2019-4-16 10:13:3 +0800 2018-09-26 ...
- ASP.NET Core EF 查询获取导航属性值,使用Include封装
// 引用 using Microsoft.EntityFrameworkCore; // 摘要: // Specifies related entities to include in the qu ...
- JQ获取元素属性值
最近在学习JAVA Web,自己也是做个下列表左右选择的小案例. 获取某个元素的属性值一直以为是要调用atrr方法,不过好像获取元素的数组形式再遍历每个元素的时候想获取到它的属性值用attr方法有问题 ...
随机推荐
- Spring配置,JDBC数据源及事务
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- UVA 11300 Spreading the Wealth (数学推导 中位数)
Spreading the Wealth Problem A Communist regime is trying to redistribute wealth in a village. They ...
- References & the Copy-Constructor
1 There are certain rules when using references: (Page 451) A reference must be initialized when it ...
- 九度OJ 1107 搬水果 -- 哈夫曼树 2011年吉林大学计算机研究生机试真题
题目地址:http://ac.jobdu.com/problem.php?pid=1107 题目描述: 在一个果园里,小明已经将所有的水果打了下来,并按水果的不同种类分成了若干堆,小明决定把所有的水果 ...
- std::string stringf(const char* format, ...)
std::string stringf(const char* format, ...){ va_list arg_list; va_start(arg_list, format); // SUSv2 ...
- 网站开发常用jQuery插件总结(八)标签编辑插件Tagit
一.Tagit插件功能 提高网站交互性,增加用户体验.至于其它的功能,还真没有.用一个input text就可以替换了它.但是text没有输入提示功能,而tagit拥有这个功能.官方示例如下图: 将关 ...
- Quartz 之 windowService
(一)创建服务 QuarzService using System.ServiceProcess;using System.Text; using Quartz;using Quartz.Impl; ...
- 定时生成bat命令
windows下,定时生成bat的名. at 14:54 cmd /c "echo net share D=d:\ > d:d.bat" ^对>转义.
- caller和callee的区别
①.caller caller返回一个函数的引用,这个函数调用了当前的函数. 使用这个属性要注意: 1 这个属性只有当函数在执行时才有用 2 如果在javascript程序中,函数是由顶层调用的,则返 ...
- 根据WSDL生成代理类方式
方式一: 1.使用VS2010提供的工具wsdl.exe由WSDL文件生成cs文件 使用wsdl.exe的/serverInterface选项(或缩写的 /si)指定输入的wsdl文件(注意,如果要转 ...