我有一个基本上就是这个方法的函数:
/// <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 */
}
在Method中,为参数添加精美的XML文档等等是完全没问题的。但是有没有办法用函数做到这一点?我同事的Intellisense只给了他Arg1,Arg2。
功能将是:
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 */
} );
}
}
嗯,我知道这不是一个完美的例子,但我不能在这里发布真实的代码(公司:/和长途)但这基本上是条纹版本。
非常感谢, 马克
答案 0 :(得分:1)
在我看来,你很想重塑代表轮:
/// <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)
{
//
});
}
}
答案 1 :(得分:1)
不是使用泛型委托Func<...>
,而是声明此属性的特定委托类型,并将文档作为委托定义的一部分。然后,该属性将显示该代表的文档。您看到的 Arg1 , Arg2 来自哪个地方 - Func<R,S,T>
的文档。
例如,试试这个:
/// <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; }