‘Buddy class’ is not necessarily C# specific but I believe it is more commonly seen in .Net as its sort of a pattern, or technique (hack), used to extend auto generated classes and add attributes to them.
They are also referred to as associated classes sometimes, or meta data classes. The naming convention is to append MD (for meta data) to the buddy class so it can be identified as one. As for why, well- auto generated code will overwrite any changes you make. Associated classes could be a way to circumvent that, and you could keep your custom meta data (for example validation attributes).
You have one class that is auto generated, handily marked as partial (I believe that is actually why the partial modifier was introduced- to extend auto generated classes).
You want to apply an attribute so you create a separate class that contains that, and you buddy it up with the other class.
If VS generates this for one of your entitites:
public partial class AutoGeneratedClass
{
public string SomeData { get; set; }
}
And you want to extend that and add custom meta data you could create this:
[MetadataType(typeof(NotAutoGeneratedClassMD))]
public partial class AutoGeneratedClass
{
}
public class NotAutoGeneratedClassMD
{
[DisplayName("This is some data")]
public string SomeData { get; set; }
}
Short version:
What: Way to associate classes to extend an auto generated class with custom meta data
Why: Avoid having your changes to an auto generated class be overwritten when generated again.
Personally I'm not a fan, but that is a different story :)