English 中文(简体)
C# Reflection How-to?
原标题:C# Reflection How-to?

我对C#中的思考感到困惑,因此,我会把我的具体情况降下来,看到你可以做些什么。 我在这里读到C#的思考问题,但我仍然只是拿不到。

因此,我在这里想看到我的情况;我试图接触一个我可以接触的一类非公开成员阵列。

“alt

基本上,它带有一个叫做“名单”的阵列,但这种括号是<阵列>的,其反映只是混淆了我的伤口。

我必须做许多这样的出色指南或实例,才能真正提供帮助。 请让我知道,你是否希望获得更多信息。

I black掉了名称空间的名称,不是因为我做的不是通过任何手段非法的,而是我试图首先在网上销售,这样一米试图小心。

最佳回答

http://msdn.microsoft.com/en-us/library/system. Collections. Collectionbase.aspx” rel=“noreferer”>CollectionBase支持索引编制,但只有通过明确接口实施,才能写:

IList list = Acct.Orders;
response = list[0];

你也许需要把结果归入更适当的类别,但我看不出这里需要思考。

EDIT:原始答复没有考虑到明确的接口执行。

问题回答

虽然这无助于你,但它可以帮助他人。 这里是一个简单的反思例子:

using System;
using System.Reflection;


namespace TeamActivity
{
    class Program
    {
        static void Main(string[] args)
        {
            // Dynamically load assembly from the provided DLL file.
            Assembly CustomerAssembly = Assembly.LoadFrom( "BasicCalculations.dll" );
            // Get a Type from the Assembly
            Type runtimeType = CustomerAssembly.GetType( "BasicCalcuation.BasicCalc" );
            // Get all methods from the Type.
            MethodInfo[] methods = runtimeType.GetMethods();

            // Loop through all discovered methods.
            foreach ( MethodInfo method in methods )
            {
                Console.WriteLine( "Method name: " + method.Name );
                // Create an array of parameters from this method.
                ParameterInfo[] parameters = method.GetParameters();
                // Loop through every parameter.
                foreach ( ParameterInfo paramInfo in parameters )
                {
                    Console.WriteLine( "	Paramter name: " + paramInfo.Name );
                    Console.WriteLine( "	Paramter type: " + paramInfo.ParameterType );
                }
                Console.WriteLine( "	Method return parameter: " + method.ReturnParameter );
                Console.WriteLine( "	Method return type: " + method.ReturnType );
                Console.WriteLine("
");
            }
            // Invoke the Type that we got from the DLL.
            object Tobj = Activator.CreateInstance( runtimeType );
            // Create an array of numbers to pass to a method from that invokation.
            object[] inNums = new object[] { 2, 4 };
            // Invoke the  Add  method from that Type invokation and store the return value.
            int outNum = (int)runtimeType.InvokeMember( "Add", BindingFlags.InvokeMethod, null, Tobj, inNums );
            // Display the return value.
            Console.WriteLine( "Output from  Add : " + outNum );

            Console.WriteLine( "
Press any key to exit." );
            Console.ReadKey();
        }
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...