
c#-泛型 委托 反射
c#-泛型 委托 反射
科学的发展-只不过是读大自然写的代码
科学的发展-只不过是读大自然写的代码
展开
-
动态添加类成员
动态添加类成员原创 2023-05-27 08:43:41 · 311 阅读 · 0 评论 -
反射创建泛型类
反射创建泛型类原创 2022-10-24 17:03:07 · 263 阅读 · 0 评论 -
具有自己依赖协议获取数据功能的类
具有自己依赖协议获取数据功能的类、反射、泛型原创 2022-10-24 16:21:04 · 134 阅读 · 0 评论 -
c# 属性是否支持重载
c# 属性是否支持重载、反射、特性原创 2022-10-23 14:24:28 · 366 阅读 · 0 评论 -
c# GetProperties() 返回的内容是什么?
1.概要返回为当前 System.Type 的所有公共属性。2.代码using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;namespace 属性实验{ class Program { static void Main(string[原创 2022-01-15 16:31:31 · 3104 阅读 · 0 评论 -
c# 特性实验
1.概要1.1特性的价值,就是作为类的元数据使用,不是对象的元数据,因为只有类有特性。而对象没有。或者说对象没有特性的那个概念,因为一个类无论创建多少对象,他的特性是固定的。1.2 元数据的价值,就是可以通过对这个特性数据的赋值,改变类的运行行为。2.代码using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;using Sy原创 2022-01-15 15:23:43 · 181 阅读 · 0 评论 -
根据类型名创建对象-有参数
1.概要方式1 Assembly assembly = Assembly.GetExecutingAssembly(); // 获取当前程序集 Object[] objects = { "a" }; A a = (A)assembly.CreateInstance(t.FullName,true, BindingFlags.CreateInstance, null, objects, null, null);方式2Type type ..原创 2021-11-13 15:46:42 · 294 阅读 · 0 评论 -
根据类型名创建对象
1.概要方式1Assembly assembly = Assembly.GetExecutingAssembly(); // 获取当前程序集A a = (A)assembly.CreateInstance(t.FullName);方式2A a = (A)Activator.CreateInstance(t.Namespace, t.FullName).Unwrap();方式3Type type = Type.GetType(t.FullName);A a = (A)c...原创 2021-11-13 15:12:08 · 661 阅读 · 0 评论 -
c# 反射 结构体 简单实验
1.概述前提:使用反射的时候,遇到了结构体,不确定结构体与类的反射有什么区别,做了一个简单的实验,设置获取属性值。结论:对属性值的设置和获取,结构体与类是相同的2.代码using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;namespace 结构体_反射{原创 2021-07-31 11:35:53 · 461 阅读 · 0 评论 -
c# 编码笔记 泛型继承
概述想做一个泛型的继承,形如下面A<T>B<T>:A<T>结果失败,为s'm原创 2021-05-29 10:07:10 · 518 阅读 · 0 评论 -
c# 自定义控件 单选列表 反射+枚举
代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace 单选按钮控件{ public enum eMs { 状态1, 状态2, 状态3 }; class Program { static void Mai.原创 2021-03-27 08:02:44 · 333 阅读 · 0 评论 -
c# 反射实践 由控件中自动获取值
代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading;using System.Threading.Tas.原创 2021-03-12 21:21:20 · 263 阅读 · 0 评论 -
c#-反射-ui对象自动为model对象赋值-简单实验
1.代码using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace ConsoleApp1{ class Program { static void Main(strin.原创 2021-03-09 21:56:16 · 223 阅读 · 0 评论 -
c#-反射-泛型反射
注:关于重载的泛型函数,没有好的解决办法,系统函数也没有为这种情况提供支持,这里用了一种简单的还原字符差别的方式解决的问题,考虑这种情况应该也不常用,价值也不大,所以系统没有提供这里支持(这种情况对应的是代码中的D) 普通反射 泛型类 反射函数 泛型重载 反射加工类 A B C D 处理函数 main1() main2()...原创 2019-09-26 14:31:01 · 625 阅读 · 1 评论 -
c#-泛型-关于属性
using System;/* * 证明 * 1.接口支持属性,且不用做特殊的多态标识 * 2.泛型完全支持多态。对多态的泛型表现和通常的多态完全一样。A<B>后的 t 的表现完全和多态的表现一样 */namespace 泛型{ class Program { static void Main(string[] args) ...原创 2019-09-25 10:18:54 · 1615 阅读 · 0 评论 -
c#-泛型-多态泛型
using System;// 目的:泛型理解/* 泛型支持继承和多态,因为泛型可以接受一个接口,通过该实验可以证明 * 接口泛型可以控制协变和抗变 * // 抗变 * public interface IB<in T>{ * void fun(T t);// 单可以有外部传入 * //T fun();//err 不能想外输出 * } * 抗变:in 标识的T 不能...原创 2019-09-25 08:58:44 · 900 阅读 · 0 评论 -
c#-特性理解
所谓特性就是系统级别的属性。一直对特性和属性的理解比较模糊,发现了下面这句话PropertyInfo Class 发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。属性是一个类别,而给这个类别定义的属性就是特性,任何一个属性的类型也是用一个对象表示的,而表示这个类型的属性,就叫特性。我们可以给属性添加特性,就是给...原创 2019-09-20 11:14:21 · 392 阅读 · 0 评论 -
c#-反射学习笔记2
代码using System;using System.Reflection;class Af{ public int af = 10; protected int bf = 20; public void funf(){ } protected void funfProtected(){ } public event EventHandler<AEventArgs&...原创 2019-07-05 15:44:46 · 223 阅读 · 0 评论 -
c# -event实践
代码using System;class A{}class CarInfoEventArgs: EventArgs{ public CarInfoEventArgs(string car){ this.Car = car; } public string Car{get;private set;}}class CarDealer{ public e...原创 2019-07-05 15:17:47 · 151 阅读 · 0 评论 -
c#-反射学习笔记
类图代码using System;using System.Reflection;class Af{ public int af = 10; protected int bf = 20; public void funf(){ } protected void funfProtected(){ }}class A : Af{ public int a=1; int...原创 2019-07-05 14:09:16 · 185 阅读 · 0 评论 -
c#-自定义特性
代码using System;using System.Reflection;namespace HelloWorldApplication{ class MyAttribute: System.Attribute{ public int a = 5; } [My()] class A{ public void fun(){ Console.WriteLine("A...原创 2019-07-05 13:34:44 · 282 阅读 · 0 评论 -
c#反射
using System;using System.Reflection;class A{ public void fun(){ Console.WriteLine("A fun"); } public void fun2(int a){ Console.WriteLine("A fun2"+ a); } public int fun3(int a){ return a;...原创 2019-06-28 16:29:58 · 590 阅读 · 3 评论 -
c# 特性学习笔记
https://www.cnblogs.com/liuxinxin/articles/2265672.htmlc#中的特性,以及一些思考C#中的特性https://www.runoob.com/csharp/csharp-attribute.html转载 2019-06-28 11:15:21 · 187 阅读 · 0 评论 -
c#委托-多播委托
代码using System;class A{ public int mA = 0; public void add(int a){ mA=mA+a; } public void cheng(int a){ mA = mA*a; }}class ag{ static void Main(string[] args){ Console.WriteLine("Hello...原创 2019-06-26 13:59:45 · 297 阅读 · 0 评论 -
c#委托简单实践
代码using System;class A{ public int add(int a,int b){ return a+b; }}delegate int Dadd(int a,int b);class g{ static void Main(string[] args) { Console.WriteLine("Hello World")...原创 2019-06-26 13:35:59 · 184 阅读 · 0 评论 -
c#-泛型-约束(new)
代码using System;class A<T> where T:new(){ public static int a = 5; public T fun(){ return new T(); }}class B{ public int a = 5;}public class Fanxing{ public static void Main(){ Con...原创 2019-07-06 19:36:55 · 774 阅读 · 0 评论 -
c#-泛型-静态成员
代码using System;class A<T>{ public static int a = 5;}public class Fanxing{ public static void Main(){ Console.WriteLine("hello word"); A<int> a = new A<int>(); Console.Wri...原创 2019-07-06 19:30:11 · 736 阅读 · 0 评论 -
c#-泛型-协变、抗变
代码using System;class A<B>{ }class ASub:A<B>{ public B fun(B t){ return t; }}class B{ public int a = 5;}class Bsub:B{}public class Fanxing{ public static void Main(){ C...原创 2019-07-06 18:47:13 · 264 阅读 · 0 评论 -
c#-泛型-继承2
代码1using System;class A<B>{ }class ASub<T>:A<B>{ public T fun(T t){ return t; }}class B{ public int a = 5;}public class Fanxing{ public static void Main(){ Console....原创 2019-07-06 18:23:25 · 181 阅读 · 0 评论 -
c#-泛型-抽象继承
代码using System;abstract class A<T>{ abstract public T fun(T t); }class ASub:A<B>{ public override B fun(B t){ return t; }}class B{ public int a = 5;}public class Fanxing{ pu...原创 2019-07-06 18:11:52 · 417 阅读 · 0 评论 -
c#-泛型-继承
代码using System;public class A<T>{ public T fun(T t){ return t; }}public class ASub<T>:A<T>{}class B{ public int a = 5;}public class Fanxing{ public static void Main(){...原创 2019-07-06 17:57:52 · 468 阅读 · 0 评论 -
c#-泛型-约束
代码using System;class A<T> where T:IB{ public void fun(T t){ t.fun(); }}interface IB{ void fun(); }class B:IB{ public void fun(){ Console.WriteLine("B fun"); }}public class Fanx...原创 2019-07-06 17:39:58 · 161 阅读 · 0 评论 -
c#-泛型默认值
代码using System;class A<T>{ T mb = default(T); public void set(T t){ mb = t; } public T get(){ return mb; }}class B{ public int a = 5;}public class Fanxing{ public static void Ma...原创 2019-07-06 17:30:06 · 2461 阅读 · 0 评论 -
c#-泛型1
代码using System;class A<T>{ public T fun(T t){ return t; }}class B{ public int a = 5;}public class Fanxing{ public static void Main(){ Console.WriteLine("hello word"); B b = new B...原创 2019-07-06 17:23:17 · 142 阅读 · 0 评论