I am working on debugging some code and noticed a bunch of auto generated methods and objects.
At the top of the code for these I find the following comment:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
How do you figure out what generated the code? My curiosity has gotten the better of me on this so that is why I ask. I have looked for parts of the comment in Google and found nothing concrete.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace FirstWeb
{
public partial class _Default
{
/// <summary>
/// form1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
}
}
You will not change this auto-generated C# file. As you keep adding ASP.NET controls to the page, this file grows with the additional declarations. In the older versions of C# (before version 2.0) and Visual Studio (before Version 2005), this code would be in the regular Default.aspx.cs file as well.
With the introduction of partial classes in C#, the code belonging to the same class can be split across multiple files. Here you see the “public partial class _Default’, which is used to hold the code generated by the Visual Studio designer. You will see the same class signature in the Default.aspx.cs file as well (you use this to write your own custom code).
So, the developer (you) and the designer (Visual Studio) can work independently without stepping over each other.
This is taken from First Web Program (Web Project) in C# Explained
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With