IEnumerable'需要'1'类型参数 [英] IEnumerable'requires '1' type arguments

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

问题描述

为了更改提供给我们的dll,我使用IAspectProvider接口并满足其必需的ProvideAspects方法.如

In order to make changes in the dll given to us i used IAspectProvider interface and satisfy its required ProvideAspects method. as

public class TraceAspectProvider : IAspectProvider
{
    readonly SomeTracingAspect aspectToApply = new SomeTracingAspect();

    public IEnumerable ProvideAspects(object targetElement)
    {
        Assembly assembly = (Assembly)targetElement;

        List instances = new List();
        foreach (Type type in assembly.GetTypes())
        {
            ProcessType(type, instances);
        }

        return instances;
    }

    private void ProcessType(Type type, List instances)
    {
        foreach (MethodInfo targetMethod in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
        {
            instances.Add(new AspectInstance(targetMethod, aspectToApply));
        }

        foreach (Type nestedType in type.GetNestedTypes())
        {
            ProcessType(nestedType, instances);
        }
    }
}



运行此程序时出现这些错误

等待您的宝贵意见



while running this i am getting these error

waiting for your valuable comments

推荐答案

看来,您在ProvideAspects方法上的返回类型必须是IEnumerable<t></t>,而不仅仅是IEnumerable.以下是实现IAspectProvider接口的演示代码块的链接:

http://doc .sharpcrafters.com/postsharp-2.0/Default.aspx ## PostSharp-2.0.chm/html/fa546b6c-9107-4d5f-b921-b93ead7c42a7.htm [
It looks like your return type on the ProvideAspects method has to be an IEnumerable<t></t>, not just IEnumerable. Here is a link to a demo code block that implements the IAspectProvider interface:

http://doc.sharpcrafters.com/postsharp-2.0/Default.aspx##PostSharp-2.0.chm/html/fa546b6c-9107-4d5f-b921-b93ead7c42a7.htm[^]

Also, I''m not sure this code is doing what you think it is doing. You are creating a List called instances to pass into the ProcessType method. However, you aren''t passing it in as a reference, which means your return would be of the original List, not the one you added AspectInstances to. The same is true when you recursively call the ProcessType method inside itself.


您需要泛型.首先,使用
using System.Collections.Generic;
然后,更改一些类型:
来自public IEnumerable ProvideAspects
public IEnumerable<AspectInstance> ProvideAspects
来自List instances = new List();
List<AspectInstance> instances = new List<AspectInstance>();
然后它应该起作用.
You need Generics. First of all, use
using System.Collections.Generic;
Then, change some types:
From public IEnumerable ProvideAspects
To public IEnumerable<AspectInstance> ProvideAspects
From List instances = new List();
To List<AspectInstance> instances = new List<AspectInstance>();
Then it should work.


这篇关于IEnumerable'需要'1'类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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