Domanda

I am having problem understanding the argument this flowDocument doc in the following method:

public static FormattedText GetFormattedText(this FlowDocument doc)
{
    if (doc == null)
    {
        throw new ArgumentNullException("doc");
    }
    ...
}

The caller does not specify an argument when calling the above method:

myRichTextBox.TextChanged +=
    new TextChangedEventHandler((o, e) => myRichTextBox.Width = 
        myRichTextBox.Document.GetFormattedText().WidthIncludingTrailingWhitespace + 20);

I am positive that the method does not create doc itself. I have not seen this used in this manner before.

È stato utile?

Soluzione

GetFormattedText() is not a normal method, but an extension method.

You can call it like this:

 document.GetFormattedText()

or this:

 ClassName.GetFormattedText(document)

Altri suggerimenti

This is the syntax for an extension method, the parameter is the FlowDocument object that the method is called on:

myRichTextBox.Document.GetFormattedText().WidthIncludingTrailingWhitespace + 20);
                   ^           
                   |
-------------------|
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top