有人给我一个类型t.
我想知道这种类型是否是枚举.
public bool IsEnumeration(Type t)
{
// Mystery Code.
throw new NotImplementedException();
}
public void IsEnumerationChecker()
{
Assert.IsTrue(IsEnumeration(typeof(Color)));
Assert.IsFalse(IsEnumeration(typeof(float)));
}
Run Code Online (Sandbox Code Playgroud) 我正在运行构建,我希望能够在发生这种情况时查看进度.但是如果构建有错误,我还想保存输出.
我知道我可以使用Process.UseShellExecute = false,RedirectStandardOutput但是,这只是故事的一部分.
我怎样才能做到这一点?
问题是没有得到一般的callstack,这可以按照这里描述的方式完成:http: //eriwen.com/javascript/js-stack-trace/ ,而是访问触发事件的callstack,来自处理程序事件.
特别是我有兴趣从窗口错误事件中记录callstack
window.onerror = function(msg, url, line) {
//callstack // would be nice to have.
//log callstack or whatever. (note this can be done w/ ajax and service, and is not the question at hand.
}
Run Code Online (Sandbox Code Playgroud)
但我知道如何记录错误.(我使用jquery .ajax和服务)
浏览器能否实现这一目标?目前有可能吗?也许我会以错误的方式解决这个问题.如何添加一个简单的函数(即不修改我的代码库中的所有函数)来检测何时出现错误,并记录调用堆栈.
到目前为止,感谢您的答案,如果问题最初措辞不当,那就很抱歉.
使用时打印堆栈跟踪并不困难System.Diagnostics.我想知道是否有可能打印传递给堆栈跟踪上的每个方法的参数的值,如果不是,为什么不.
这是我的初步代码:
public static class CallStackTracker
{
public static void Print()
{
var st = new StackTrace();
for (int i = 0; i < st.FrameCount; i++)
{
var frame = st.GetFrame(i);
var mb = frame.GetMethod();
var parameters = mb.GetParameters();
foreach (var p in parameters)
{
// Stuff probably goes here, but is there another way?
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
好的,我只是放弃了这一点.
我希望能够使用用户配置文件记录用户首选项,该文件将从应用程序配置文件中引用.我正在尝试使用ConfigurationManager和配置文件.我可以从用户设置中读取得很好,但设置它们是另一个问题.我想将应用程序设置与两个不同文件中的用户设置分开.
我用这个时:
<appSettings file="user.config">
</appSettings>
Run Code Online (Sandbox Code Playgroud)
和user.config看起来像:
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="localSetting" value="localVal"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
我可以使用ConfigurationManager来读取本地设置,但不能保存到文件中.
var oldLocVal = ConfigurationManager.AppSettings["localSetting"];
ConfigurationManager.AppSettings.Set("localSetting", "newLocalValue"); // Doesn't save to file.
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="localSetting" value="localVal"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
然后我想以这种方式调用并保存AppSettings:
var uMap = new ConfigurationFileMap("user.config");
var uConfig = ConfigurationManager.OpenMappedMachineConfiguration(uMap);
var oldLocalVarFromConfig = uConfig.AppSettings.Settings["localSetting"]; // NO
uConfig.AppSettings.Settings.Remove("localSetting"); // NO
uConfig.AppSettings.Settings.Add("localSetting", "newValue");
uConfig.Save();
Run Code Online (Sandbox Code Playgroud)
但它不会让我访问配置的应用程序设置.(将某些内容转换为AppSettings时出现问题)
configSource而不是file属性appSettings.
提前致谢.
我添加了一个global.asax文件,后来决定我不需要它,所以我将它从项目中排除,但是现在当我尝试运行我的项目时,我得到了一个解析器错误.
以下是视图上显示的错误:
Line 1: <%@ Application Codebehind="Global.asax.cs" Inherits="[assembly].WebApiApplication" Language="C#" %>
Run Code Online (Sandbox Code Playgroud)
发生了什么以及如何解决它(除了明显将其添加回项目)?
在以下代码中:
ThreadStart ts = new ThreadStart((MethodInvoker)delegate
{
executingThreads.Add(Thread.CurrentThread);
// work done here.
executingThreads.Remove(Thread.CurrentThread);
});
Thread t = new Thread(ts);
t.Start();
Run Code Online (Sandbox Code Playgroud)
也许你可以看到我想跟踪我开始的线程,所以我可以在必要时中止它们.
但我担心Thread.CurrentThread是从创建Thread t的线程计算的,因此中止它不会中止生成的线程.
我目前有一个像这样的javascript错误处理程序:
window.onerror = function(msg, url, line){ //stuff }};
Run Code Online (Sandbox Code Playgroud)
但我希望能够使用jquery附加到onerror上,如下所示:
$(window).error(function(evtData){//stuff});
Run Code Online (Sandbox Code Playgroud)
我的问题是,从jquery的eventData对象,我如何获得错误的消息,url和行号,就像我在非jquery函数中所做的那样?
提前致谢.
拥有IAddable,IRemovable,IIndexable之类的接口来支持每个操作是否有意义,或者这种方法最终会导致代码难以管理?
我希望用户提供一个枚举名称,说"颜色"和一个值,比如"红色",并告诉他们这是否是该枚举的成员值,或者枚举是否存在.
我怎样才能做到这一点?
在过去,我使用了Type.GetType("UserProvidedType").Parse/Convert.ChangeType,但是当用户提供的类型是枚举时,这似乎不起作用.请参阅: 根据c#中的用户输入解析原始类型,以 获取在此上下文中似乎不起作用的过去解决方案.
谢谢.
我希望有一个在后台运行的程序,监听任何文件传输,然后取消资源管理器的文件传输机制,并启动它自己的.
我该怎么做呢?有什么dll我可以pinvoke?
为什么?
*通过文件传输我的意思是通过拖放移动/复制文件/文件夹,但我只关心从磁盘到磁盘的文件传输,而不是从互联网.
let在某些浏览器中不起作用.也不在他们的互操作/网络控制台中.为什么?
(最初我认为浏览器插件和jsFiddle存在不一致,但事实证明并非如此,只是我的测试结果不好.)
c# ×10
javascript ×3
reflection ×2
app-config ×1
asp.net ×1
automation ×1
callstack ×1
config ×1
enumeration ×1
enums ×1
jquery ×1
let ×1
onerror ×1
parameters ×1
parsing ×1
pinvoke ×1
process ×1
redirect ×1
stack-frame ×1
stack-trace ×1
stdout ×1
typechecking ×1
types ×1