Aslında daha önceden bu konu ile ilgili yazı yazmıştım, burada sadece yeni farkettiğim bir olayı sizlerle paylaşmak istiyorum. Etiketler kısmından önceden Partial ile alakalı yazmış olduğum yazıya ulaşabilirsiniz. İyi okumalar dilerim...
Partial anahtar kelimesi ile classlarımız içerisindeki yapıları, ayrı dosyalarda yazabildiğimizi böylece daha düzgün bir proje çıkartabileceğimizi zaten biliyoruz. Aslında Visual Studio bunu bizim için çok fazla yapmaktadır. Sistemin arka planda bizim için üretmiş olduğu kodları biz bozmayalım diye partial classlarla farklı yerlerde göstermektedir. Mesela bir windows form applicaion projesinde form ile alakalı 2 adet class vardır. Bunlar örnek olarak Form1.cs ve Form1.Designer.cs dosyasıdır. İşte bunlar partial classlardır.
Form1.Designer.cs:
namespace WindowsFormsApp1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
}
}
Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
İlk Yorumu Siz Yapın