了解反射API [英] Understanding Reflection API

查看:83
本文介绍了了解反射API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解ASP.Net c#中反射的概念,并想知道如何在ASP.Net中实现反射API?

I want to understand the concept of Reflection in ASP.Net c# and want to know how to implement Reflection API in ASP.Net ?

推荐答案

我建​​议您开始阅读有关该主题的一些CodeProject文章:
反射 [ ^ ]
.NET中的反射 [ C#教程中的反思 [动态代码生成与反射 [反射是慢还是快?实用演示 [ ^ ]
反射101:.NET中的反射简介 [ ^ ]
...
或使用Google!
I suggest you start reading through some CodeProject articles about that topic:
Reflection[^]
Reflection in .NET[^]
Reflection in C# Tutorial[^]
Dynamic Code Generation vs Reflection[^]
Reflection is Slow or Fast? A Practical Demo[^]
Reflection 101: An Introduction to Reflection in .NET[^]
...
or use Google!


Reflection提供的对象(类型为Type)封装了程序集,模块和类型.您可以使用反射来动态创建类型的实例,将类型绑定到现有对象,或者从现有对象获取类型并调用其方法或访问其字段和属性.如果您在代码中使用属性,则Reflection使您可以访问它们.有关更多信息,请参见属性.


例如,如果要以编程方式显示类的所有方法,则可以这样操作:

Reflection provides objects (of type Type) that encapsulate assemblies, modules and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties. If you are using attributes in your code, Reflection enables you to access them. For more information, see Attributes.


For example, if you want to programmatically display all the methods of a class, you could do it like so:

using System;
using System.Reflection;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            var t = typeof(MyClass);

            foreach (var m in t.GetMethods())
            {
                Console.WriteLine(m.Name);
            }
            Console.ReadLine();
        }
    }


    public class MyClass
    {
        public int Add(int x, int y)
        {
            return x + y;
        }

        public int Subtract(int x, int y)
        {
            return x - y;
        }
    }
}




有关更多信息,请参见链接: .NET中的反射 [




For More Information You Can Refer The Link : Reflection in .NET[^]


先生.梅加尔邦..
hemu给出的答案很好,但不足以使您完全放心..
我认为您应该对反射进行更多的探索,因为它是我职业生涯中最重要的话题.
来吧..
祝你好运.
Mr. Meghal..
The answer given by hemu is good but not enough to get full confidence..
I think you should more explore about reflection because it is the most important topic i''ve learnt in my career..
Go ahead..
Best of luck..


这篇关于了解反射API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆