我使用emacs-mode.如何按名称导航到功能定义?Emacs有"imenu-add-to-menubar"命令,但这不方便,因为我必须从菜单中选择功能名称.
谢谢!
为了实现应用程序的GUI,我希望将所有逻辑从一种形式转移到另一种形式.此GUI管理器将表现为有限状态机.虽然我认为我已经在某处看到过这种实现,但我找不到与这种解决方案相匹配的设计模式.
表单将如下所示:
public class Login : Form
{
...
private void EnterButton_Click()
{
...
string user = loginTextBox.Text;
string password = passwordTextBox.Text;
bool isValid = SecurityManager.CheckUserLogin(user,password);
GUIManager.FormEnd(FormLogin,new LoginData(user, pass, isValid));
}
...
}
Run Code Online (Sandbox Code Playgroud)
GUI管理器将执行以下操作:
public class GUIManager
{
...
public void FormEnd(FormType type, FormData data)
{
switch (type)
{
...
case FormLogin:
LoginData ld = (LoginData)data;
if (ld.Valid)
{
m_loginForm.Hide();
m_mainForm.Show();
}
...
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
达到这一点,我有以下几个问题:是否有一个设计模式正式化这个想法?如果有,.NET会以某种方式支持它吗?如果没有,这听起来像是一个好的实现想法吗?谢谢!
我已经将IOError处理移动到一个单独的函数,以避免在打开文件进行读取时出现样板.
但是如果在读取文件时IOError会触发怎么办?如果sshfs断开连接,或者文件被root删除等?
def safe_open(*args):
try:
return open(*args)
except IOError:
quit('Error when opening file \'{0}\'. Error #{1[0]}: {1[1]}'.format(\
args[0], sys.exc_info()[1].args))
Run Code Online (Sandbox Code Playgroud)
...
with safe_open(myfile, 'r') as f:
for i in f:
print i
with safe_open(anotherfile, 'r') as f:
try:
conf = ''.join(f).format(**args)
except KeyError:
quit('\nOops, your template \'{0}\' has placeholders for' + \
'parameters\nthat were not supplied in the command line: - {1}\n' +
'\nCan\'t proceed. Ending. Nothing has been changed yet.'.format( \
args['host_template'], '\n - '.join(sys.exc_info()[1].args)), 1)
Run Code Online (Sandbox Code Playgroud)
文件以不同的方式读取,所以我没有看到将它放入函数并将更改的部分作为参数传递的方法.
[补充:想到这个解决方案,但它使一个无法关闭的发电机.如果循环停止,则文件保持打开状态.]
def reader(*args): …Run Code Online (Sandbox Code Playgroud) 我有以下代码,但我收到以下编译错误:
属性"WebPartStorage"在此声明类型上无效.它仅对'property,indexer'声明有效.
和
属性'FriendlyName'在此声明类型上无效.它仅对'property,indexer'声明有效.
我已经从MSDN文章修改了我的代码:http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx.有没有人知道我做错了导致这个错误?
[Category("Custom Properties")]
[DefaultValue(RegionEnum.None)]
[WebPartStorage(Storage.Shared)]
[FriendlyName("Region")]
[Description("Select a value from the dropdown list.")]
[Browsable(true)]
protected RegionEnum _Region;
public RegionEnum Region
{
get
{
return _Region;
}
set
{
_Region = value;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个对象数组,我想将其序列化为XML.这些对象注释为设置XML节点名称,但我想知道如何设置XML根节点的名称.
代码如下所示:
// create list of items
List<ListItem> list = new List<ListItem>();
list.Add(new ListItem("A1", new Location(1, 2)));
list.Add(new ListItem("A2", new Location(2, 3)));
list.Add(new ListItem("A3", new Location(3, 4)));
list.Add(new ListItem("A4<&xyz>", new Location()));
// serialise
XmlSerializer ser = new XmlSerializer(typeof(ListItem[]));
FileStream os = new FileStream(@"d:\temp\seri.xml", FileMode.Create);
ser.Serialize(os, list.ToArray());
os.Close();
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
<?xml version="1.0"?>
<ArrayOfPlace xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Place>
<Placename>A1</Placename>
<Location>
<Lat>1</Lat>
<Long>2</Long>
</Location>
</Place>
<Place>
...
Run Code Online (Sandbox Code Playgroud)
ListItem已使用XmlElement注释重命名为Place,但如何设置根节点的名称以重命名'ArrayOfPlace'节点?
我在这里有一个旧的代码库,他们使用受保护的成员变量.可以讨论这是否是一个好主意.但是,代码必须与gcc3编译良好.我有一个派生模板类Bar,它使用类模板Foo中的受保护成员x
template <class Something> class Foo {
public:
// stuff...
protected:
some::type x;
}
template <class Something> Bar : Foo<Something> {
public:
void cleanup();
}
Run Code Online (Sandbox Code Playgroud)
在cleanup()的方法声明中,有一些用x完成的事情
template <class Something> void Bar<Something>::cleanup() {
doSomeThingCleanUpLike (x);
}
Run Code Online (Sandbox Code Playgroud)
这不适用于gcc4,虽然它应该与gcc3一起使用.当我将其更改为时,它可以工作
doSomeThingCleanUpLike (this->x);
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我有兴趣学习一种支持GUI,多线程和简单测试操作(支持正则表达式)的编程语言.
主要在Windows上,但最好是跨平台.Stack Overflow社区提出了什么建议?
我知道这个问题,但提问者似乎满足于另一个问题的答案(如何重载构造函数)
我有一个类作为一个可变类的高级memoizer,所以我可以把它视为外部的不可变:
type Wrapper(args) =
let tool = new MutableTool()
tool.Init(args) //<--"Unexpected identifier in definition"
let lookupTable = //create lookup using tool here
member this.Lookup(s) = //callers use lookupTable here
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何在"工具"上调用Init方法.我错过了什么?
我需要在两种语言之间做出选择,这两种语言对我来说都是新的.
我想选择更简单的一个.
另外,请提及运行该程序所需的设置.