I am getting a compile error when I attempt to add a method/function to a Dictionary <string, Delegate>
. Can you tell me how I can add my method geometryContentParser()
to the dictionary? Maybe I need to change the Dictionary value type to Event
instead of Delegate
?
Compile Error:
Cannot convert method group 'geometryContentParser' to non-delegate type 'System.Delegate'. Consider using parentheses to invoke the method
Heres my simple code:
public class FileParser
{
private Dictionary<string, Delegate> customParsingCallbacks = new Dictionary<string, Delegate>();
public FileParser()
{
customParsingCallbacks["points"] = geometryContentParser; // compile error: "Cannot convert method group `geometryContentParser' to non-delegate type `System.Delegate'. Consider using parentheses to invoke the method"
}
private bool geometryContentParser(string formattedLine) {
// Post: Returns True if this custom content parser is still running (needs to look at the next line) else false for completion
if (formattedLine.Contains("}")) {
return false;
}
return true;
}
}
Also which is the correct invocation method?
customParsingCallbacks["points"]("");
// OR
customParsingCallbacks["points"].DynamicInvoke("");