Nan*_*ada 3 c# designer visual-studio-designer visual-studio-2008
这个问题有点轶事,但对我来说仍然很有趣; 我想知道为什么Visual Studio 2008不喜欢以下常量使用:
public class Service101 : ServiceBase
{
/// <remarks>
/// Shown at Start -> Settings -> Control Panel -> Administrative Tools -> Services
/// </remarks>
internal const string SERVICE_NAME = "WinSvc101";
/// <remarks>
/// Shown at Start -> Settings -> Control Panel -> Administrative Tools -> Services
/// </remarks>
internal const string DISPLAY_NAME = "Windows Service 101";
/// <summary>
/// Public constructor for Service101.
/// </summary>
public Service101()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.ServiceName = Service101.SERVICE_NAME;
this.EventLog.Source = Service101.DISPLAY_NAME;
this.EventLog.Log = "Application";
if (!EventLog.SourceExists(Service101.DISPLAY_NAME))
{
EventLog.CreateEventSource(Service101.DISPLAY_NAME, "Application");
}
}
#region Events
/// <summary>
/// Dispose of objects that need it here.
/// </summary>
/// <param name="disposing">Whether or not disposing is going on.</param>
protected override void Dispose(bool disposing)
{
// TODO: Add cleanup code here (if required)
base.Dispose(disposing);
}
Run Code Online (Sandbox Code Playgroud)
因为它在设计时显示以下警告:
Warning 1 The designer cannot process the code at line 68:
if (!EventLog.SourceExists(DISPLAY_NAME))
{
EventLog.CreateEventSource(DISPLAY_NAME, "Application");
}
The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. E:\Proyectos\beanstalk\dotnetfx\trunk\WinSvc101\WinSvc101\Service101.cs 69 0
Run Code Online (Sandbox Code Playgroud)
任何评论都会非常感激.非常感谢提前.
它实际上告诉过你.该代码由设计者生成.设计师需要它离开它的方式.不要更改该代码,除非您希望设计人员使用它做一些不愉快的事情.
在视觉设计器中看到的与它生成的代码之间存在某种平衡.
现在,假设您对生成的代码进行了一些修改.除非您以与设计师完全相同的方式进行更改,否则它将无法识别更改.您的更改不会显示在设计图面上.下次更改或保存时,设计人员将在不进行更改的情况下重新生成代码.
因此,如果您不想丢失对生成代码的更改,则不要对生成的代码进行任何更改.
| 归档时间: |
|
| 查看次数: |
4121 次 |
| 最近记录: |