再谈 C# 交互窗口
来源:互联网 发布:西安软件新城招聘信息 编辑:程序博客网 时间:2024/06/05 02:35
Ubuntu 10.10 操作系统中自带的是 mono 2.6.7:
目前最新版本是 mono 2.8.1。因此,在 Ubuntu 10.10 操作系统中安装 mono 2.8.1 :
然后看看安装后的效果:
然后把 Ubuntu 10.10 操作系统中的 /opt/mono-2.8.1/lib/mono/4.0/csharp.exe 文件拷贝到安装了 Microsoft .NET Framework 4 的 Microsoft Windows Server 2003 R2 Enterprise Edition Service Pack2 操作系统中,运行 csharp.exe:
哎呀,运行出错了。还需要一个 Mono.CSharp.dll 才能运行。让我们来找出这个 Mono.CSharp.dll 吧:
因此,把 Ubuntu 操作系统中上述 gac 目录中的 Mono.CSharp.dll 拷贝到 Windows 操作系统中,再次运行 csharp.exe :
这次运行没有出错,而是直接退出了。这更糟糕了。只好找到 csharp.exe 的 C# 源程序看看发生了什么。
上面的 repl.cs 就是 csharp.exe 的 C# 源程序之一,其中包含 Main 方法。下面是 repl.cs 的开头部分:
//
// repl.cs: Support for using the compiler in interactive mode (read-eval-print loop)
//
// Authors:
// Miguel de Icaza (miguel@gnome.org)
//
// Dual licensed under the terms of the MIT X11 or GNU GPL
//
// Copyright 2001, 2002, 2003 Ximian, Inc (http://www.ximian.com)
// Copyright 2004, 2005, 2006, 2007, 2008 Novell, Inc
//
//
// TODO:
// Do not print results in Evaluate, do that elsewhere in preparation for Eval refactoring.
// Driver.PartialReset should not reset the coretypes, nor the optional types, to avoid
// computing that on every call.
//
using
System;
using
System.IO;
using
System.Text;
using
System.Globalization;
using
System.Collections;
using
System.Reflection;
using
System.Reflection.Emit;
using
System.Threading;
using
System.Net;
using
System.Net.Sockets;
using
System.Collections.Generic;
using
Mono.CSharp;
namespace
Mono {
public
class
Driver {
static
int
Main (
string
[] args)
{
#if !ON_DOTNET
if
(args.Length > 0 && args [0] ==
"--attach"
) {
new
ClientCSharpShell (Int32.Parse (args [1])).Run (
null
);
return
0;
}
if
(args.Length > 0 && args [0].StartsWith (
"--agent:"
)) {
new
CSharpAgent (args [0]);
return
0;
}
#endif
return
Startup(args);
}
static
int
Startup (
string
[] args)
{
string
[] startup_files;
try
{
startup_files = Evaluator.InitAndGetStartupFiles (args);
Evaluator.DescribeTypeExpressions =
true
;
Evaluator.SetInteractiveBaseClass (
typeof
(InteractiveBaseShell));
}
catch
{
return
1;
}
return
new
CSharpShell ().Run (startup_files);
}
}
}
问题就出在第 52 行到第 65 行的 Startup 方法中。因此在该方法中增加一些 Debug 语句:
static int Startup (string[] args) { string[] startup_files; try { startup_files = Evaluator.InitAndGetStartupFiles (args); Evaluator.DescribeTypeExpressions = true; Evaluator.SetInteractiveBaseClass (typeof (InteractiveBaseShell)); } catch (Exception ex) { // Begin Add by Ben (http://www.cnblogs.com/skyivben) Console.WriteLine(ex); // End Add by Ben (Wed 2010-12-01) return 1; } return new CSharpShell ().Run (startup_files); }
然后重新编译:
再将重新编译后的 csharp.exe 拷贝到 Windows 操作系统中运行:
运行时出错信息如上所示。经查,Mono.CSharp 命名空间中的 StreamReportPrinter 类继承自同一命名空间中的 ReportPrinter 类,这两个类的源程序代码均在 src/mono-2.8.1/mcs/mcs/report.cs 文件中,该文件中的相关内容如下所示:
namespace
Mono.CSharp {
//
// Generic base for any message writer
//
public
abstract
class
ReportPrinter {
/// <summary>
/// Whether to dump a stack trace on errors.
/// </summary>
public
bool
Stacktrace;
int
warnings, errors;
public
int
WarningsCount {
get
{
return
warnings; }
}
public
int
ErrorsCount {
get
{
return
errors; }
}
protected
virtual
string
FormatText (
string
txt)
{
return
txt;
}
//
// When (symbols related to previous ...) can be used
//
public
virtual
bool
HasRelatedSymbolSupport {
get
{
return
true
; }
}
public
virtual
void
Print (AbstractMessage msg)
{
if
(msg.IsWarning)
++warnings;
else
++errors;
}
protected
void
Print (AbstractMessage msg, TextWriter output)
{
StringBuilder txt =
new
StringBuilder ();
if
(!msg.Location.IsNull) {
txt.Append (msg.Location.ToString ());
txt.Append (
" "
);
}
txt.AppendFormat (
"{0} CS{1:0000}: {2}"
, msg.MessageType, msg.Code, msg.Text);
if
(!msg.IsWarning)
output.WriteLine (FormatText (txt.ToString ()));
else
output.WriteLine (txt.ToString ());
if
(msg.RelatedSymbols !=
null
) {
foreach
(
string
s
in
msg.RelatedSymbols)
output.WriteLine (s + msg.MessageType +
")"
);
}
}
}
class
StreamReportPrinter : ReportPrinter
{
readonly
TextWriter writer;
public
StreamReportPrinter (TextWriter writer)
{
this
.writer = writer;
}
public
override
void
Print (AbstractMessage msg)
{
Print (msg, writer);
base
.Print (msg);
}
}
}
从上面的源程序代码中,我看不出为什么在 Windows 操作系统中运行时会出现“重写成员 ... 时违反了继承安全性规则。重写方法的安全可访问性必须与所重写方法的安全可访问性匹配。”的错误。这个 csharp.exe 程序在 Linux 操作系统中运行是很正常的。
园子中的各位大侠有什么建议吗?请在评论中告诉我。谢谢!
- 再谈 C# 交互窗口
- 三谈 C# 交互窗口
- 关于Vs2015中C#交互(C# Interactive)窗口的应用。
- C#子窗口与父窗口交互(使用委托和事件)
- C#子窗口与父窗口交互(使用委托和事件)
- C#子窗口与父窗口交互(使用委托和事件)
- javascript 窗口交互
- js窗口交互
- C#实现Winform窗口间数据交互的三种方法介绍
- 【C#】30. VS 2015 的 C# 交互窗口(interactive window)
- C#窗口
- html 弹出窗口与父窗口交互
- 父窗口与子窗口交互
- 弹出窗口与父窗口交互
- 子窗口与父窗口交互
- GridView 子父窗口 交互
- 全屏与窗口,全屏交互
- 【交互】MFC窗口位置分析
- 浅谈 .NET 程序的编译时间
- 关于差分约束系统的建图方法
- 三谈 C# 交互窗口
- 短信
- Oracle业务表和视图在SuperMap中的应用
- 再谈 C# 交互窗口
- ios cell 重用问题--图片remove
- 利用JAVA中的反射机制获得某个类的信息
- 浮点数在内存中的存储格式
- @Resource和@Autowired对比
- Android快速开发框架:ThinkAndroid(附下载地址)
- Spring MVC详解(七) 注解式控制器的数据验证、类型转换及格式化(2)
- Intrepid climber (dfs+树)
- Android应用开发之使用Socket进行大文件断点上传续传