我正在尝试创建一个行首标记:
lexer grammar ScriptLexer;
BOL : {getCharPositionInLine() == 0;}; // Beginning Of Line token
Run Code Online (Sandbox Code Playgroud)
但上面发出错误
The name 'getCharPositionInLine' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)
当它创建此代码时:
private void BOL_action(RuleContext _localctx, int actionIndex) {
switch (actionIndex) {
case 0: getCharPositionInLine() == 0; break;
}
}
Run Code Online (Sandbox Code Playgroud)
当getCharPositionInLine()方法不存在...
Win32 API 中的窗口过程必须是静态\全局函数,因为它不能采用类对象(the this)参数。当然可以使用 hWnd->object 字典等解决方法。
我想知道D是否有办法优雅地解决它,比如为每个对象创建一个微小的成员函数副本(以调用对象的真实处理程序)或我可以分配给的匿名函数WNDCLASS.lpfnWndProc(我知道有匿名函数,但我不能使用extern(Windows)他们的财产)?
我可以做这样的事情吗:
class Window {
extern (Windows)
LRESULT delegate (HWND hWnd, UINT msg, WPARAM w, LPARAM l) MyWinProcDelegate;
this() {
MyWinProcDelegate = &Events;
}
extern (Windows)
LRESULT Events (HWND hWnd, UINT msg, WPARAM w, LPARAM l) {
MessageBoxA(null , "Success!!!" , null ,0);
return DefWindowProcA(hWnd, message, wParam, lParam);
}
}
Run Code Online (Sandbox Code Playgroud)
(省略注册\创建\msg-loop...)
Events() 似乎没有触发...我错过了什么吗?
我只是想在一些命令的帮助中找到特定的部分:
help rd | select-string -pattern 'cmd'
Run Code Online (Sandbox Code Playgroud)
但我得到的只是错误.怎么了?
我有PHP服务器,其中我需要更新客户端A关于一些客户端B动作,此刻它已经完成.通常如何完成?
我目前的解决方案是:
$.ajax(...).done(function myCallBack(){...});呼吁.myCallBack(){...}其中时发出另一个$.ajax(...).done(function myCallBack(){...});.这样,与服务器的通信保持打开状态,以便随时接收新信息离开$.ajax(...).done(function myCallBack(){...});(并一直产生新的)是这样做的方法吗?
对于会话间通信 - 有没有办法发出事件或类似信号(而不是连续监视某些文件[浪费资源!])?
在PHPStorm中,我想调试一个PHPUnit类.如果我在单元测试类(继承的类PHPUnit_Framework_TestCase)的方法中设置断点,每当我运行测试时,PHPStorm执行测试,但永远不会在断点处停止,即使在其他地方有断点过去常常停下来.
这是PHPStorm中的错误吗?怎么停在一个PHPUnit_Framework_TestCase方法?
我正在寻找一种自动生成(例如)的方法singleton,如:
[SingletonPatternAttribute]
public class Logger {
public void Log (string txt) { /* do logging... */ }
}
Run Code Online (Sandbox Code Playgroud)
作为消除样板的尝试.
有人知道如何实现吗?我知道有CodeDOM,Reflection.Emit,T4等.此外 - (最值得注意的是)PostSharp,但我很高兴看到上述挑战的真正解决方案.
例如,我可以在构造函数中执行代码生成,但编译时间显然要好得多.
这里的问题不是Singleton,而是生成/元编程C#- 如何以最佳方式创建代码/消除样板 - 有什么样的具体例子?
TL/DR:更改命名空间值的最简单方法是什么?LINQ to XML比如说?xmlns:gcs="clr-namespace:NsOne;assembly=AsmOne"xmlns:gcs="clr-namespace:NsTwo;assembly=AsmTwo"
为什么?因为:
我Xaml使用了序列化System.Windows.Markup.XamlWriter.Save(myControl).我想System.Windows.Markup.XamlReader.Parse(raw)在另一个项目中将这个GUI外观可视化到其他地方(反序列化使用).
我不想链接到原始程序集!
我只需要更改命名空间,因此XamlReader.Parse(raw)不会抛出异常.我目前使用正则表达式来做它并且它可以工作,但我不喜欢那种方法(例如,如果我在xmlns:gcs="clr-namespace:NsOne;assembly=AsmOne"里面CDATA)
这是我的序列化Xaml:
<FlowDocument PagePadding="5,0,5,0" AllowDrop="True"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:gcs="clr-namespace:NsOne;assembly=AsmOne"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<gcs:MyParagraph Margin="0,0,0,0">
<gcs:MyParagraph.MetaData>
<gcs:ParagraphMetaData UpdaterParagraphUniqueId="1" />
</gcs:MyParagraph.MetaData>
<Span>some text...</Span>
</gcs:MyParagraph>
<gcs:MyParagraph Margin="0,0,0,0" Background="#FFF0F0F0">
<gcs:MyParagraph.MetaData>
<gcs:ParagraphMetaData UpdaterParagraphUniqueId="2" />
</gcs:MyParagraph.MetaData>
<Span Foreground="#FF0000FF">some more text...</Span>
</gcs:MyParagraph>
</FlowDocument>
Run Code Online (Sandbox Code Playgroud)
(MyParagraph并且ParagraphMetaData是自定义类型,它们都存在于源程序集和目标程序MyParagraph集中.继承自WPF的Paragraph)
我们有现有的Java Android代码.我们想要无痛地慢慢开始转向Kotlin.我们使用Dagger 2,Butterknife和Realm.我们使用Java编译器8(但我们targetCompatibility并sourceCompatibility是1.7).
构建成功,但在尝试调试时,我们得到:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jetbrains/annotations/NotNull.class
Run Code Online (Sandbox Code Playgroud)
有没有办法解决Gradle中的重复条目(可能使用packagingOptions或resolutionStrategy?因为它是来自插件的重复...?)?
build project没有任何错误,只有transformClassesWithJarMergingForDebug失败!这是应用程序的gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
//apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
kapt { generateStubs = true }
android {
signingConfigs {
config {
keyAlias 'MyAndroidKey'
keyPassword 'password'
storeFile file('android.jks')
storePassword 'password'
}
}
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId "com.acme.app"
minSdkVersion 15 …Run Code Online (Sandbox Code Playgroud) android gradle kotlin android-gradle-plugin kotlin-android-extensions
我想使用Runtime.loadLibrary和加载Win32 API函数GetProcAddress(...).使用mixin:
template GetProcA(alias func, alias name_in_DLL)
{
const char[] GetProcA = func ~ ` = cast(typeof(`~func~`)) GetProcAddress(hModule,"`~name_in_DLL~`");`;
}
...
static extern (Windows) Object function (HWND hWnd, int nIndex) GetWindowLong;
static extern (Windows) Object function (HWND hWnd, int nIndex, Object dwNewLong) SetWindowLong;
Run Code Online (Sandbox Code Playgroud)
我可以通过这种方式实例化它(在类构造函数中):
mixin GetProcA!("SetWindowLong", "SetWindowLongA");
Run Code Online (Sandbox Code Playgroud)
但如果再次使用它为另一个功能:
mixin GetProcA!("GetWindowLong", "GetWindowLongA");
Run Code Online (Sandbox Code Playgroud)
编译器抱怨:
mixin GetProcA!("GetWindowLong","GetWindowLongA") GetProcA isn't a template...
Run Code Online (Sandbox Code Playgroud)
我没有看到这一点:如果创建了第一个实例GetProcA,我又不能再使用它,那么它对我有什么帮助呢?
在调试会话中第一次尝试显示可视化工具时,它引发了该异常(显示在底部),我单击异常消息对话框上的“继续”并再次显示可视化工具(通过单击“放大镜”)变量旁边的图标)。这是我拥有的简单可视化工具:
[assembly: DebuggerVisualizer(
typeof(TestVisualizer),
Target = typeof (string),
Description = "Test Visualizer")]
namespace VuTree {
public class TestVisualizer : DialogDebuggerVisualizer {
protected override void Show(IDialogVisualizerService svc, IVisualizerObjectProvider provider) {
var text = provider.GetObject() as string ?? "no object found...";
using (var form = new Form())
{
form.Text = text;
form.Size = new Size(400, 400);
svc.ShowDialog(form);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是例外(部分):
************** Exception Text **************
System.Runtime.InteropServices.COMException (0x8013134F): Object is in a zombie state. (Exception from HRESULT: 0x8013134F)
Server stack trace:
at …Run Code Online (Sandbox Code Playgroud) c# ×4
d ×2
dmd ×2
php ×2
android ×1
antlr4 ×1
antlr4cs ×1
boilerplate ×1
comexception ×1
concurrency ×1
debugging ×1
gdc ×1
gradle ×1
ipc ×1
javascript ×1
jquery ×1
kotlin ×1
phpstorm ×1
phpunit ×1
powershell ×1
winapi ×1
xaml ×1
xml ×1