0

I got a Function that is basically this Method:

/// <summary>Extracts the parent id.</summary>
/// <param name="nameEntities">The name entities.</param>
/// <param name="tcdMakeId">The TCD make id.</param>
/// <returns>Parent Id.</returns>
public Nullable<int> ExtractParentId( IEnumerable<NameEntity> nameEntities, int childId )
{
    /* Do some Extraction here */
}

In the Method it is no problem at all to add nice XML documentation for parameter and so forth. But is there a Way to do this with a Function? The Intellisense of my colleague gives him nothing but Arg1, Arg2.

The Function would be:

private Func<IEnumerable<NameEntity>, int, Nullable<int>> ExtractParentId
{
    get
    {
        return this._extractParentId = this._extractParentId ??
            new Func<IEnumerable<NameEntity>, int, Nullable<int>>( ( nameEntities, childId ) =>
            {
                /* Do some Extraction here */
            } );
    }
}

Well I know this is not a perfect example, but I can't post the real code here ( corporate :/ and way to long ) but this is basicly a striped down version.

Thanks quite a lot, Marc

2
  • 1
    that's not a function. that's a read-only property Commented Feb 6, 2013 at 9:30
  • Are you asking "I have a property of type Func<R,S,T>, can I give it XML documentation so intellisense shows the same details for the property as it would a regular method?" Commented Feb 6, 2013 at 9:38

2 Answers 2

1

It looks to me a lot like you're trying to reinvent the Delegate wheel:

/// <summary>
/// 
/// </summary>
/// <param name="nameEntities"></param>
/// <param name="childID"></param>
/// <returns></returns> <!--etc-->
private delegate Nullable<int> ExtractParentIdDelegate(IEnumerable<int> nameEntities, int childID);

/// <summary>
/// 
/// </summary>
private ExtractParentIdDelegate FuncExtractParentId
{
    get
    {
        return this._extractParentId = this._extractParentId ?? new ExtractParentIdDelegate(delegate(IEnumerable<int> nameEntites, int childID)
                                                                    {
                                                                            //
                                                                    });
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

You know, in Germany we have a saing "to miss the forest for the trees". Shurly simply making it a delegate solves the problem!
1

Rather than using the generic delegate Func<...>, declare a specific delegate type for this property and put the documentation as part of the delegate definition. Then the property will show the documentation for the delegate. That's where the Arg1, Arg2 that you saw are coming from - the documentation for the Func<R,S,T>.

For example, try this:

    /// <summary>
    /// Using Func<int,int,int>, we get generic documentation
    /// </summary>
    public Func<int,int,int> UsingFunc{ get; }

    /// <summary>
    /// Example of a delegate with XML documentation as if it was a method.
    /// </summary>
    /// <param name="left">Left operand</param>
    /// <param name="right">Right operand</param>
    /// <returns>Whatever it returns</returns>
    public delegate int CustomDelegate(int left, int right);

    /// <summary>
    /// Using a custom delegate to get full documentation.
    /// </summary>
    public CustomDelegate UsingCustomDelegate{ get; }

1 Comment

As I said obove... I must have had way to less sleep. Delegate is what I was looking for!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.