我写了几十种扩展方法,它们都按预期工作.但这是我第一次在这种情况下使用扩展方法.
public static class ControllerExtensions
{
public static RedirectToRouteResult RedirectToAction<TController>(
this Controller controller
, Expression<Action<TController>> action
) where TController : Controller
{
RouteValueDictionary routeValuesFromExpression =
ExpressionHelper.GetRouteValuesFromExpression<TController>(action);
return new RedirectToRouteResult(routeValuesFromExpression);
}
}
Run Code Online (Sandbox Code Playgroud)
看起来很正常吧?但在我的控制器中,我无法通过键入来访问此扩展方法.相反,我必须在前面添加关键字"this".例如:
// This does not work, I get a compiler error because
// RedirectToAction has no overload for the generic.
//
return
RedirectToAction<MembershipController>(
c => c.RegisterSuccess(Server.UrlEncode(code) ));
// But, this does work?!?!
//
return
this.RedirectToAction<MembershipController>(
c => c.RegisterSuccess(Server.UrlEncode(code) ));
Run Code Online (Sandbox Code Playgroud)
很奇怪.也许是因为我在我正在扩展的实例对象中?"控制器"实例是什么?
果然,我能够在一个简单的控制台应用程序中复制它:
class Program
{
static void Main(string[] args)
{ …Run Code Online (Sandbox Code Playgroud) 我想在我的Mac上使用64位python解释器,所以我不得不从源代码重建.但是,使用我自己的自定义构建解释器时,当我从shell内部运行解释器时尝试导航时会遇到问题.将python键入bash shell会导致熟悉:
Python 2.6.3 (r263:75183, Oct 23 2009, 14:23:25)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用左箭头和右箭头导航时,我会得到奇怪的字符:
Python 2.6.3 (r263:75183, Oct 23 2009, 14:23:25)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^[[A^[[A^[[A^[[D^[[C^[[C^[[A^[[B^[[D^[[C
Run Code Online (Sandbox Code Playgroud)
这在Apple的默认解释器中不会发生.
是什么造成的?我该如何解决?
访问链接树的所有节点的最佳方法是什么(所有节点都引用了父节点和所有子节点,根节点的空节点为null),以便在任何节点之前没有访问任何节点?布朗尼指出非递归.
由于NSString字符串是不可变的,stringWithString:类方法的价值是什么?
我在使用时得到了实用程序NSMutableString,我只是没有看到NSString该类的实用程序.
例如,如果我有
我怎样才能得到
我正在寻找一个.NET函数调用.
我有一个文件
<Doc>
<Text>
....
</Text>
</Doc>
<Doc>
<Text>
</Text>
</Doc>
Run Code Online (Sandbox Code Playgroud)
如何仅提取<text>元素,处理它们,然后有效地提取下一个文本元素?
我不知道我有多少文件?
我试图自己学习数据结构和算法.我在C中编写了自己的双链表,现在我想编写一些算法来执行列表.交换列表项的首选方法是什么?交换内容或重新排列指向下一个和上一个列表项的指针是否更好?
如果我的代码中有一个空的while循环,例如:
while(true);
Run Code Online (Sandbox Code Playgroud)
它将使处理器使用率提高约25%.但是,如果我执行以下操作:
while(true)
Sleep(1);
Run Code Online (Sandbox Code Playgroud)
它只会使用大约1%.
那为什么呢?
更新:感谢所有伟大的回复,但我想我真的应该问这个问题,睡眠()背后的算法是什么?这更像是我想知道的.
我试图将两个子图彼此相邻(而不是彼此相对).我期待看到[sp1] [sp2]
而是只显示第二个图[sp2].
from matplotlib import pyplot
x = [0, 1, 2]
pyplot.figure()
# sp1
pyplot.subplot(211)
pyplot.bar(x, x)
# sp2
pyplot.subplot(221)
pyplot.plot(x, x)
pyplot.show()
Run Code Online (Sandbox Code Playgroud)
此致,
Axel
.net ×2
algorithm ×2
c ×2
python ×2
shell ×2
c++ ×1
cocoa ×1
cocoa-touch ×1
hierarchy ×1
linux ×1
matplotlib ×1
navigation ×1
nsstring ×1
objective-c ×1
perl ×1
tree ×1
unix ×1
xml ×1