让我们列出你发布优秀和最喜欢的扩展方法的答案.
要求是必须发布完整代码并提供示例和如何使用它的说明.
基于对该主题的高度关注,我在Codeplex上设置了一个名为extensionoverflow的开源项目.
请标记您的答案并接受将代码放入Codeplex项目中.
请发布完整的源代码而不是链接.
Codeplex新闻:
24.08.2010 Codeplex页面现在在这里:http://extensionoverflow.codeplex.com/
11.11.2008 XmlSerialize/XmlDeserialize现在已实现并且已经过单元测试.
11.11.2008仍有更多开发人员的空间.;-) 现在加入!
11.11.2008第三个贡献者加入了ExtensionOverflow,欢迎来到BKristensen
11.11.2008 FormatWith现在已实现且已经过单元测试.
09.11.2008第二个贡献者加入了ExtensionOverflow.欢迎来到chakrit.
09.11.2008我们需要更多开发人员.;-)
很抱歉再次询问,已经有一些关于此关键字的问题.但他们所有人都说出了"这个"的目的.
什么时候使用这个关键字
C#何时使用此关键字
在C#中使用静态方法的形式参数中的"this"关键字在C#中
正确使用"this."关键字?
我的问题是何时不使用'this'关键字.
或者
在代码之类的情况下始终使用此关键字是否正确
class RssReader
{
private XmlTextReader _rssReader;
private XmlDocument _rssDoc;
private XmlNodeList _xn;
protected XmlNodeList Item { get { return _xn; } }
public int Count { get { return _count; } }
public bool FetchFeed(String url)
{
this._rssReader = new XmlTextReader(url);
this._rssDoc = new XmlDocument();
_rssDoc.Load(_rssReader);
_xn = _rssDoc.SelectNodes("/rss/channel/item");
_count = _xn.Count;
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
这里我没有使用'this'和"_xn"和"_count"也没有使用"_rssDoc.Load(_rssReader);" 好吗?我应该在类中使用"this"以及所有类变量吗?
编辑:在类中为自己的变量使用'this' 是没用的吗?
特定
[
1,"test2"
3,"test"
]
|> dict
// turn it into keyvaluepair sequence
|> Seq.map id
|> fun x -> x.ToDictionary<_,_,_>((fun x -> x.Key), fun x -> x.Value)
Run Code Online (Sandbox Code Playgroud)
如果我没有明确使用<_,_,_>after ,则无法编译ToDictionary.
Intellisense工作正常,但编译失败并出现错误:基于此程序点之前的信息查找不确定类型的对象
因此,似乎Intellisense知道如何解决方法调用.
这似乎是一个线索
|> fun x -> x.ToDictionary<_,_>((fun x -> x.Key), fun x -> x.Value)
Run Code Online (Sandbox Code Playgroud)
失败了
Type constraint mismatch.
The type 'b -> 'c is not compatible with type IEqualityComparer<'a>
The type 'b -> 'c' is not compatible with the type 'IEqualityComparer<'a>'
(using external F# …Run Code Online (Sandbox Code Playgroud) 我有一堂课:
public static class PictureBoxExtensions
{
public static Point ToCartesian(this PictureBox box, Point p)
{
return new Point(p.X, p.Y - box.Height);
}
public static Point FromCartesian(this PictureBox box, Point p)
{
return new Point(p.X, box.Height - p.Y);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是this前面的关键字有什么用PictureBox,而不是省略关键字?
我在解决this flowDocument doc以下方法中的参数时遇到问题:
public static FormattedText GetFormattedText(this FlowDocument doc)
{
if (doc == null)
{
throw new ArgumentNullException("doc");
}
...
}
Run Code Online (Sandbox Code Playgroud)
调用方没有调用上述方法时指定一个参数:
myRichTextBox.TextChanged +=
new TextChangedEventHandler((o, e) => myRichTextBox.Width =
myRichTextBox.Document.GetFormattedText().WidthIncludingTrailingWhitespace + 20);
Run Code Online (Sandbox Code Playgroud)
我肯定的方法并没有创造doc本身.我之前没见过this以这种方式使用过.