开发者

How do you use an extension method in an InvokeMethod workflow?

开发者 https://www.devze.com 2023-01-09 02:17 出处:网络
I have a System.Activities.Statements.InvokeMethod activity. I\'m trying to activate it with TargetType: (null)

I have a System.Activities.Statements.InvokeMethod activity. I'm trying to activate it with

TargetType: (null)
TargetObject: licxFiles //a开发者_开发百科n ICollection<string>
MethodName: StoreIfHasValue

The StoreIfHasValue:

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

The only param I'm passing from the workflow designer is :

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);
    }

Is a problem that I'm using a method call as a param? Or why does this give the error

'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'.


Never tried this but I suspect you need to treat this as a static method call, which it really is, and pass the object as the first parameter. So empty the TargetObject property and set the TargetType to the class that implements the extension method.

0

精彩评论

暂无评论...
验证码 换一张
取 消