如果写入if条件,F#中最好的方法是什么?
现在我写的是这样的:
if condition <> true then do
Run Code Online (Sandbox Code Playgroud)
有没有其他更短的方式来写它?喜欢用!运营商?
我有一个Visual Studio 2010解决方案,其中包含多个Web应用程序.我已经设置了一个作为启动项目,但是当我调试Visual Studio时,为我的解决方案中的每个Web应用程序启动了一个开发服务器.反正我是否可以让Visual Studio只启动默认启动项目的开发服务器?
所以,我的小测试应用程序遇到了一个非常奇怪的问题.问题是,我的意思是崩溃......很难.没有例外(至少,我没有抓到任何东西)被抛出,只是"Blah Blah已经停止响应......"的消息.它崩溃只有当我在运行应用程序64,发行方式和外界的IDE.如果我在x86模式下运行它,或者我在x64中的IDE中运行它,或者我在x64中独立运行它作为DEBUG它可以正常工作.
我把它缩小到我的p/invoke PeekMessage调用.所以,我需要聪明的头脑来看看我写的废话并告诉我,如果我做得对.因为,严肃地说,我即将失去我的头脑.我在2台计算机上试过这个,它们都表现出相同的行为.我有点担心这可能是.NET 4.0的错误.
无论如何,这是我的p/invoke代码.如果你看到任何奇怪或简单的愚蠢,请告诉我:
这是对PeekMessage的调用:
private static bool PeekMessage()
{
MSG message = new MSG(); // Message to retrieve.
return Win32API.PeekMessage(ref message, IntPtr.Zero, 0, 0, PeekMessageFlags.NoRemove);
}
Run Code Online (Sandbox Code Playgroud)
这是PeekMessage(注意:抑制安全性属性在类定义上,因此它正在应用):
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool PeekMessage(ref MSG msg, IntPtr hwnd, uint wFilterMin, uint wFilterMax, PeekMessageFlags flags);
Run Code Online (Sandbox Code Playgroud)
这是味精:
[StructLayout(LayoutKind.Sequential)]
internal struct MSG
{
/// <summary>Window handle.</summary>
public IntPtr hwnd;
/// <summary>Message to process.</summary>
public uint Message;
/// <summary>Window message parameter 1.</summary>
public uint wParam; …Run Code Online (Sandbox Code Playgroud) 据我所知,jQuery的1.10或2.0分支没有正式的jQuery externs文件.我的问题是,我是否会使用带有1.10和2.0版本的jQuery 1.9 externs文件遇到麻烦?
我正在尝试获取对web.config customErrors部分的引用.当我使用以下代码时,我总是得到一个null.当我得到一个我创建的自定义部分的引用时,我没有这个问题,所以我有点傻眼为什么这不起作用.
CustomErrorsSection customErrorSection =
ConfigurationManager.GetSection("customErrors") as CustomErrorsSection;
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
CustomErrorsSection customErrorSection =
WebConfigurationManager.GetSection("customErrors") as CustomErrorsSection;
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
CustomErrorsSection customErrorSection =
WebConfigurationManager.GetWebApplicationSection("customErrors") as CustomErrorSection;
Run Code Online (Sandbox Code Playgroud)
编辑:
哎呀!大多数情况都是如此,我在问到这个问题之后就找到了答案.
这对我有用:
System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/");
CustomErrorsSection customErrorsSection = (CustomErrorsSection)configuration.GetSection("system.web/customErrors");
Run Code Online (Sandbox Code Playgroud)
或者更简单地这样:
CustomErrorsSection customErrors = (CustomErrorsSection) WebConfigurationManager.OpenWebConfiguration("/").GetSection("system.web/customErrors");
Run Code Online (Sandbox Code Playgroud)
这也有效:
CustomErrorsSection customErrorsSection = ConfigurationManager.GetSection("system.web/customErrors") as CustomErrorsSection;
Run Code Online (Sandbox Code Playgroud)
所以我想我现在明白了为什么我首先遇到了这个问题.我错误地认为我可以通过尝试GetSection("customErrors")来获取对customErrors部分的引用,但是我没有告诉它它所居住的根部分,并且我的基础是我的尝试基于我知道如何当我没有意识到我的自定义部分是该部分的根时,得到一个自定义部分,所以当我调用GetSection()时,我不必在它前面添加类似system.Web /的东西.
Vim将方法定义缩进到属性后的额外级别.这让我发疯,但我无法弄清楚如何让它停下来.我完全禁用了缩进,但这不是我想要的行为.有没有办法让Vim在属性定义后不缩进额外的级别?
这是一个示例:
[Foo]
public void Bar()
{
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现一个具有属性的界面,但似乎无法让它工作,我还没有通过谷歌找到任何相关的例子(还).我确定我在这里做了一些完全错误但却不知道如何解决它.
(System.Reflection.Assembly/LoadWithPartialName "System.Web")
; naive, just trying to figure out how to implement the IHttpHandler interface in Clojure
(defn foo-handler []
(reify System.Web.IHttpHandler
(IsReusable [] false)
(ProcessRequest [context] ())))
Run Code Online (Sandbox Code Playgroud)
IsReusable是一个属性,我不知道如何告诉reify它不是一个传统的功能.
CompilerException clojure.lang.CljCompiler.Ast.ParseException: Must supply at least one argument for 'this' in: IsReusable
Run Code Online (Sandbox Code Playgroud)
好的,我为IsReusable提供'this'
CompilerException clojure.lang.CljCompiler.Ast.ParseException: Can't define method not in interfaces: IsReusable
Run Code Online (Sandbox Code Playgroud)
我也试过代理,但我得到了类似的结果.
我也尝试将IsReusable命名为get_IsReusable,这实际上没有什么区别,我得到的编译错误与上面相同.
我也试过deftype但是我得到了一个完全不同的错误:
(deftype foo-handler []
System.Web.IHttpHandler
(get_IsReusable [this] false)
(ProcessRequest [this context] ()))
Run Code Online (Sandbox Code Playgroud)
编译错误:
InvalidCastException Unable to cast object of type 'clojure.lang.Var' to type 'System.Type'. clojure.lang.Namespace.ReferenceClass
Run Code Online (Sandbox Code Playgroud)
更新: …
我试图围绕F#进行思考,所以我认为使用System.DirectoryServices命名空间转换一些在Active Directory中看起来像用户的简单C#代码并返回DirectoryEntry对象会很有趣.我正在努力的部分是索引DirectoryEntry中包含的PropertyCollection.
在C#中,有了DirectoryEntry,我可以通过这样做获取PropertyCollection中的属性:
entry.Properties["displayName"].Value
Run Code Online (Sandbox Code Playgroud)
我目前正在努力解决如何在F#中索引集合的问题.有人可以对此有所了解吗?
我已经创建了一个HttpHandler,我正在向它发布数据.我希望在发布时获取表单ID,但无法弄清楚如何获取它.我没有看到HttpRequest中的任何字段会给我这些信息.是否可以从HttpRequest获取已发布的表单ID?
c# ×4
asp.net ×3
f# ×2
.net ×1
clojure ×1
clojureclr ×1
http ×1
pinvoke ×1
vim ×1
web-config ×1