没关系为什么人们想要这样做,我只是想知道它是否可以完成.
这是我的代码不起作用:
if (!Debugger.IsAttached)
{
try
{
Debugger.Launch();
while (!Debugger.IsAttached)
{
Thread.Sleep(1000);
}
}
catch (System.Security.SecurityException e)
{
Console.WriteLine("exception " + e.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
基本上我很想知道如何使用该Debugger.Launch()方法.
以下为什么不工作?
List<string> castMe = new List<string>();
IEnumerable<string> getFromCast = (IEnumerable<string>)castMe; // allowed.
Dictionary<int, List<string>> castMeDict = new Dictionary<int, List<string>>();
Dictionary<int, IEnumerable<string>> getFromDict = (Dictionary<int, IEnumerable<string>>)castMeDict; // Not allowed
Run Code Online (Sandbox Code Playgroud)
这是Dictionary铸造机制中的一个缺陷,还是我认为应该允许这样做?
谢谢.
我想这可能会使用Reflection.Emit,
但是关于SO的类似问题只回答了如何动态创建类/方法,而不是如何更新现有类.
与此类似,是否可以在运行时删除方法/类?如果是这样,我想可以删除该类,并使用旧方法和新方法将其添加回来.
提前致谢.
PS我没有这个用途,只是好奇心问题.
在根据具体情况处理枚举值时,使用switch语句或字典会更好吗?
我认为字典会更快.就空间而言,它占用了一些内存,但case语句也会占用程序本身所需的内存中的一些内存.所以底线我认为只使用字典总是更好.
以下是两个并列的实现进行比较:
鉴于这些枚举:
enum FruitType
{
Other,
Apple,
Banana,
Mango,
Orange
}
enum SpanishFruitType
{
Otra,
Manzana, // Apple
Naranja, // Orange
Platano, // Banana
Pitaya // Dragon fruit, only grown in Mexico and South American countries, lets say
// let's say they don't have mangos, because I don't remember the word for it.
}
Run Code Online (Sandbox Code Playgroud)
以下是使用switch语句执行此操作的方法:
private static SpanishFruitType GetSpanishEquivalent(FruitType typeOfFruit)
{
switch(typeOfFruit)
{
case FruitType.Apple:
return SpanishFruitType.Manzana;
case FruitType.Banana:
return SpanishFruitType.Platano;
case FruitType.Orange:
return SpanishFruitType.Naranja;
case FruitType.Mango:
case …Run Code Online (Sandbox Code Playgroud) 我的线程如何工作的模型是有些ThreadManager给每个线程转一圈.当它是一个线程时,它会执行几行代码.
暂停一个线程,是不是只有ThreadManager(暂时)停止允许该线程转弯?
要中止一个线程,不能ThreadManager只是永远不会给那个线程另一个转弯?
有什么问题?
有没有办法确定使用javascript本身在javascript中执行的所有函数的堆栈深度?
我想它可能涉及修改Function原型,但我真的不知道.
另外,能够在堆栈深度足够高的任何时候断开都是很好的.
原因是我在IE中有一个堆栈溢出错误,显然是不可调试的.我很懒,而且我宁愿不必去寻找我正在寻找原因的代码.
谢谢你帮助我的懒惰.
有没有一种很好的方法来实现它,以便在我使用NUnit进行测试时函数是公共的,但是否则是私有的?
不必生成大量无关代码也不错.
- - - - - - - - - - - - 编辑 - - - - - - - - - - - -
似乎解决方案属于3种类型:
有没有办法以编程方式执行此操作?即只需创建一个新的临时应用程序,使所有protected/private/internal功能public,插入NUnit,在那里运行测试,然后回到使用私有函数的发布版本?
简短版本:
提前致谢.
长版(带背景!!):
使用in关键字,我们可以获得对象的所有属性.(并且使用该hasOwnProperty方法允许我们仅过滤掉属于该对象的属性,而不过滤掉继承的属性.)
for (var prop in obj) {
if (typeof(obj[prop]) == 'object' && obj.hasOwnProperty(prop)) {
showObjectsOfInternal(obj[prop], visitedObjects); // recursion.
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个很好的起点,但我想得到所有的对象.可以想象迭代所有属性并累积对象,然后递归迭代这些属性.但是,如果有一个对象引用循环,就像一个自己引用的对象,比如in window.window,那么最好不要陷入困境.因此,需要一种方法来跟踪递归期间的所有"访问对象".
要跟踪被访问对象,需要根据内部对象键真正需要对象的哈希集.我尝试通过制作一个visitedObjects对象并将其设置为要添加的对象,并且值无关紧要.
if(visitedObjects[obj] == 1){return;}
visitedObjects[obj] = 1;
Run Code Online (Sandbox Code Playgroud)
但这对我不起作用.(似乎将对象转换为键的字符串,而不是使用其内部引用键)
所以我决定使用一个数组并添加一个indexOf方法.
Array.prototype.indexOf = function(obj){
for(var i = 0; i < this.length; i++)
{
if(this[i] == obj) // reference comparison for non-primitive objects.
{
return i;
}
}
return -1;
}
Run Code Online (Sandbox Code Playgroud)
但这也没有用(最终我得到了我不能做的,for(var prop in obj) …
我在C#代码上使用Visual Studio 2008.
如果另一个断点被击中(并打破了),我只想在断点处打破.有没有办法做到这一点?
我认为作为子问题,访问调试器具有的信息会很好.
这个的基本原理是我只对给定某个callstack(以及在callstack中执行其中一个函数的某个点)打破某个断点感兴趣.也许我应该使用callstack代替?另一个原因是编程访问调试器知道的东西会很有趣.
谢谢.
我想添加这些接口:
public interface IIndexGettable<TKey, TValue>
{
TValue this[TKey key]{ get; }
}
public interface IIndexSettable<TKey, TValue>
{
TValue this[TKey key]{ set; }
}
public interface IIndexable<TKey, TValue> : IIndexGettable<TKey, TValue>, IIndexSettable<TKey, TValue>
{
// new TValue this[TKey key]{ get; set; } // as suggested by SO question 1791359 this will "fix" the issue.
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用IIndexablegetter时,我得到以下编译器错误:
The call is ambiguous between the following methods or properties: 'IIndexGettalbe<TKey, TValue>.this[Tkey]' and 'IIndexSettable<TKey, TValue>.this[TKey]'
这是我运行的代码:
public static class IIndexableExtensions
{
public static …Run Code Online (Sandbox Code Playgroud) c# ×7
debugging ×3
dictionary ×2
javascript ×2
.net ×1
casting ×1
covariance ×1
dynamic ×1
enums ×1
generics ×1
inheritance ×1
interface ×1
nunit ×1
stack ×1