-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Prototype
The prototype pattern is genereted based on one attribute:
- [Prototype] - this attribute should be applied to the class that is about to become a prototype. The class must be a partial class.
using DesignPatternCodeGenerator.Attributes.Prototype;
namespace Samples.Prototype;
[Prototype]
public partial class Person
{
public string? Name { get; set; }
public string? LastName { get; set; }
public Address? PersonAddress { get; set; }
public Contacts? PersonContacts { get; set; }
}
public class Address
{
public string? HouseNumber { get; set; }
public string? Street { get; set; }
public string? City { get; set; }
}
public class Contacts
{
public string? PhoneNumber { get; set; }
public string? Email { get; set; }
}
Using the code above, the generator will generate a partial class with an implemented prototype with the ShallowCopy() and DeepCopy() methods.
// <auto-generated/>
using DesignPatternCodeGenerator.Attributes.Prototype;
namespace Samples.Prototype
{
public partial class Person
{
public Person ShallowCopy()
{
return (Person)this.MemberwiseClone();
}
public Person DeepCopy()
{
Person clone = (Person)this.MemberwiseClone();
clone.PersonAddress = new Address()
{
HouseNumber = PersonAddress.HouseNumber,
Street = PersonAddress.Street,
City = PersonAddress.City
};
clone.PersonContacts = new Contacts()
{
PhoneNumber = PersonContacts.PhoneNumber,
Email = PersonContacts.Email
};
return clone;
}
}
}
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request