小编Dan*_*ker的帖子

Visual Studio对TypeScript文件的隐式引用如何工作?

我正在给TypeScript另一个尝试版本0.9.5,让它独自留了一段时间.

在我发现的新旧信息的混合中,我认为项目中的所有TypeScript文件都会"隐式地引用"彼此.

我无法弄清楚这意味着什么.我的一个理论是,它意味着每个文件都能够查看从其他所有文件导出的所有函数,类等,所有这些都在全局范围内.(如果这是真的,这听起来不是一个好主意.)

问题是,我无法确定是否有任何解释是正确的,因为0.9.5与Visual Studio的集成似乎存在错误,因此它没有做到(人们)所期望的.

我的测试是在Visual Studio 2013中创建的"带有TypeScript的HTML应用程序"项目,其中从项目模板页面的链接安装了TypeScript插件.

我添加了第二个.ts文件,导出一个愚蠢名称的类:

export class Hedgehog {
    spikes() {
        return 100;
    }
}
Run Code Online (Sandbox Code Playgroud)

并且还knockout.d.tsDefinitelyTyped添加.

在主app.ts文件中,如果我尝试使用我的类,VS会给出智能感知错误app.ts:

var h = new Hedgehog(); // Could not find symbol Hedgehog
Run Code Online (Sandbox Code Playgroud)

如果我尝试使用以下任何内容,它也会抱怨ko:

var five = ko.observable(5); // Could not find symbol ko
Run Code Online (Sandbox Code Playgroud)

这个问题抱怨隐式引用不起作用,并且有一个暗示解决方案的注释,即手工编辑项目文件.但是,那个人改变了他们项目的这一行:

<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets"
        Condition="'$(Configuration)' == 'Debug'" />
Run Code Online (Sandbox Code Playgroud)

对此:

<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" 
        Condition="Exists('$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets')" />
Run Code Online (Sandbox Code Playgroud)

然后他们显然很高兴(虽然结果如何?!)

但是我刚刚产生的项目已经看起来像第二个版本.我试图完全删除这个条件:

<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
Run Code Online (Sandbox Code Playgroud)

然后我取得了一些进展.我现在在两个.ts文件中对Knockout进行智能感知,但我仍然无法使用我的Hedgehog课程.我需要添加:

import otherFile …
Run Code Online (Sandbox Code Playgroud)

visual-studio typescript

3
推荐指数
1
解决办法
3597
查看次数

从成员指针获取类/结构对象

我有C++结构

struct myStruct {
    int a;
    int b;
    int c;
}; 

myStruct b;
int *ptr = &b.c;
Run Code Online (Sandbox Code Playgroud)

如何从ptr中恢复myStruct对象?

(我知道我可以使用像C中的container_Of()这样的指针算术来实现这一点.基本上就像

reinterpret_cast<myStruct*>(reinterpret_cast<char *>(ptr) - offsetof(myStruct, c));
Run Code Online (Sandbox Code Playgroud)

我问是否有任何推荐/优雅的方式?)

c++

2
推荐指数
1
解决办法
513
查看次数

在C#和C之间传递对象

我的应用程序包含带有非托管C dll调用的C#代码.在我的C#代码中,我有一个对象/类,其属性是系统类型,如string和int以及我定义的其他对象.

我想将这个复杂的(Graph.cs)对象传递给我的C(dll)代码,你会在这里建议什么实现?

我已经尝试过移动结构但是我没有使用除了string和int之外的任何东西.

谢谢.

码:

public Class Grpah {

    TupleCollection m_TupleCollection;
    int m_nGeneralIndex;       
    bool m_bPrintWRF;
    string m_sLink;  
}

public Class TupleCollection {

    IList<Tuple> _collection;

}     

public Class Tuple {

    Globals.TupleType m_ToppleType;        
    ArrayList m_Parameters;

}

public class TupleArgs {

    public string Value { get; set; }       
    public Globals.PAS PAS;
    public RefCollection RefCollection { get; set; }
    public int Time{ get; set; }      

}

public class RefCollection {

    public List<int> SynSet{ get; set; } 
    public Globals.PAS PAS;

}
Run Code Online (Sandbox Code Playgroud)

c c# dll struct unmanaged

2
推荐指数
1
解决办法
3591
查看次数

Java相当于CLR的UnhandledException事件

在CLR(C#,VB.NET等使用的运行时)中,有一种方法可以在抛出未处理的异常时注册要调用的回调.

Java中有类似的东西吗?

我猜它可能是一些API,你传递一个对象,用一个方法实现一些接口.抛出异常并且catch堆栈上没有匹配时,运行时将调用已注册对象上的方法,并将传递异常对象.

这将允许程序员保存堆栈跟踪.它还允许它们调用System.exit,以停止finally仅针对未处理的异常执行的块.

更新1.

为了说明这一点,这里有一个C#示例:

// register custom handler for unhandled exceptions
AppDomain.CurrentDomain.UnhandledException += (sender, evt) =>
{
    Console.WriteLine("unhandled exception");
    Environment.FailFast(null);
};

try
{
    throw new NullReferenceException();
}
finally
{
    Console.WriteLine("finally is executing");
}
Run Code Online (Sandbox Code Playgroud)

关键是通过调用Environment.FailFast(null)我可以阻止finally块执行.

果然,在Windows 7上运行的.NET 3.5和4.0中,我看不到输出中的"finally is execution"字符串.但是如果我注释掉这个FailFast调用,那么我确实在输出中看到了这个字符串.

更新2.

基于到目前为止的答案,这是我尝试用Java重现它.

// register custom handler for unhandled exceptions
Thread.currentThread().setUncaughtExceptionHandler(

    new Thread.UncaughtExceptionHandler() {

        public void uncaughtException(
                final Thread t, final Throwable e) {

            System.out.println("Uncaught exception");
            System.exit(0);
        } …
Run Code Online (Sandbox Code Playgroud)

java clr exception unhandled-exception

2
推荐指数
1
解决办法
445
查看次数

帮我将处理代码转换为C#

我正在尝试将此代码从Java转换为C#(位于此处

我有一些winform经验,但在winform应用程序上绘制像素时经验不足。

我很自信我可以转换大多数子方法,但不清楚如何在屏幕上绘制单个像素

将Java转换为C#的任何帮助或工具将不胜感激

// Buddhabrot
// j.tarbell   January, 2004
// Albuquerque, New Mexico
// complexification.net

// based on code by Paul Bourke
// astronomy.swin.edu.au/~pbourke/

// Processing 0085 Beta syntax update
// j.tarbell   April, 2005

int dim = 800;             // screen dimensions (square window)
int bailout = 200;         // number of iterations before bail
int plots = 10000;        // number of plots to execute per frame (x30 = plots per second)

// 2D array to hold exposure values …
Run Code Online (Sandbox Code Playgroud)

c# processing system.drawing

-1
推荐指数
1
解决办法
5350
查看次数