我已经粘贴了Jon Skeet的C#In Depth网站的一些代码:
static void Main()
{
// First build a list of actions
List<Action> actions = new List<Action>();
for (int counter = 0; counter < 10; counter++)
{
actions.Add(() => Console.WriteLine(counter));
}
// Then execute them
foreach (Action action in actions)
{
action();
}
}
Run Code Online (Sandbox Code Playgroud)
http://csharpindepth.com/Articles/Chapter5/Closures.aspx
注意这一行:
actions.Add(()
()括号内的含义是什么?
我已经看到了lambda表达式,委托,Action对象的使用等几个例子,但我没有看到这种语法的解释.它有什么作用?为什么需要?
是否可以使用API从Word 2007"docm"文档中提取所有VBA代码?
我已经找到了如何在运行时插入VBA代码,以及如何删除所有VBA代码,但是没有将实际代码拉出到我可以存储的流或字符串中(以及将来插入到其他文档中).
任何提示或资源将不胜感激.
编辑:感谢大家,Aardvark的回答正是我所寻找的.我已将其代码转换为C#,并且能够使用Visual Studio 2008从类库中调用它.
using Microsoft.Office.Interop.Word;
using Microsoft.Vbe.Interop;
...
public List<string> GetMacrosFromDoc()
{
Document doc = GetWordDoc(@"C:\Temp\test.docm");
List<string> macros = new List<string>();
VBProject prj;
CodeModule code;
string composedFile;
prj = doc.VBProject;
foreach (VBComponent comp in prj.VBComponents)
{
code = comp.CodeModule;
// Put the name of the code module at the top
composedFile = comp.Name + Environment.NewLine;
// Loop through the (1-indexed) lines
for (int i = 0; i < code.CountOfLines; i++)
{
composedFile += …Run Code Online (Sandbox Code Playgroud) 在Visual Studio 2010"Productivity Power Tools"插件(非常棒)中,您可以将文件选项卡配置为基于正则表达式进行颜色编码.
我有一个RegEx来区分接口文件(IMyInterface.cs)的标签颜色与常规的.cs文件:
[I]{1}[A-Z]{1}.*\.cs$
Run Code Online (Sandbox Code Playgroud)
不幸的是,这也会对任何以大写字母"I"(例如,Information.cs)开头的文件进行颜色编码.
如何将此RegEx修改为仅包含第一个字母为"I"且第二个字母不是小写的文件?
我试图在提取方法中提取出常见的代码模式,但是找不到Presenter类型的正确类型.有帮助吗?
public bool CanGotoHome
{
get { return !(CurrentPresenter is IHomePresenter) && IsLoggedIn; }
}
public bool CanGotoImportanceOfAimsAndObjectives
{
get { return !(CurrentPresenter is IImportanceOfAimsAndObjectivesPresenter) && IsLoggedIn; }
}
public bool CanGotoGotoAimsAndObjectives
{
get { return !(CurrentPresenter is IAimsAndObjectivesPresenter) && IsLoggedIn; }
}
Run Code Online (Sandbox Code Playgroud) Windows窗体应用程序我想要像pda设备一样的desine键盘.我想要一组中的所有数字键因此我想在一个框架或面板上安排所有这些按钮.第二个框架或面板,包含所有特殊功能键.我想在阅读键盘的xml文件描述后在运行时设计这个键盘.请指导我实施这个.