2010-07-26 66 views
2

我有一个System.Activities.Statements.InvokeMethod活动。我试图用激活它如何在InvokeMethod工作流程中使用扩展方法?

TargetType: (null) 
TargetObject: licxFiles //an ICollection<string> 
MethodName: StoreIfHasValue 

StoreIfHasValue

public static void StoreIfHasValue(this ICollection<string> collection, string value) 
    { 
     if (value.IsNullOrEmpty()==false) 
      collection.Add(value); 
    } 

我从工作流设计器通过唯一的参数是:

Direction: In 
Type: String 
Value: LicxUtilities.CheckForLicx(projectPath,doc) 

CheckForLicx

 public static string CheckForLicx(string projPath, XDocument proj) 
    { 
     var ns=proj.Root.Name.Namespace; 
     var q = from refs in proj.Root.Elements(ns+"ItemGroup").Descendants(ns+"EmbeddedResource") 
       where refs.Attribute("Include").Value.EndsWith(".licx", StringComparison.CurrentCultureIgnoreCase) 
       select refs.Attribute("Include").Value; 
     var licx=q.FirstOrDefault(); //assume there is only one .licx file reference in the project 
     if (licx.IsNullOrEmpty()) 
      return null; 
     return System.IO.Path.Combine(projPath, licx); 
    } 

是我使用方法调用作为参数的问题?或者为什么这给错误

'ICollection`1' does not have a public instance method named 'StoreIfHasValue' matching the parameter types, generic type arguments, and generic type constraints supplied to InvokeMethod 'Check for and store'. 

回答

2

从未尝试过这一点,但我怀疑你需要把它当作一个静态方法调用,它确实是,并传递对象作为第一个参数。因此清空TargetObject属性并将TargetType设置为实现扩展方法的类。

+0

啊,所以假装它不是扩展方法。我会给它一个镜头。 – Maslow 2010-07-26 18:49:44

相关问题