IEnumerable'需要'1'类型参数 [英] IEnumerable'requires '1' type arguments
本文介绍了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 theProvideAspects
method has to be anIEnumerable<t></t>
, not justIEnumerable
. Here is a link to a demo code block that implements theIAspectProvider
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 aList
calledinstances
to pass into theProcessType
method. However, you aren''t passing it in as a reference, which means your return would be of the originalList
, not the one you addedAspectInstances
to. The same is true when you recursively call theProcessType
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:
Frompublic IEnumerable ProvideAspects
Topublic IEnumerable<AspectInstance> ProvideAspects
FromList instances = new List();
ToList<AspectInstance> instances = new List<AspectInstance>();
Then it should work.
这篇关于IEnumerable'需要'1'类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文