|
| 1 | +using FastCloner.SourceGenerator.Shared; |
| 2 | +using IDeepCloneable; |
| 3 | +using Riok.Mapperly.Abstractions; |
| 4 | + |
| 5 | +namespace FastCloner.Benchmark; |
| 6 | + |
| 7 | +/// <summary> |
| 8 | +/// Complex model for benchmarking deep cloning operations. |
| 9 | +/// </summary> |
| 10 | +[DeepCloneable] |
| 11 | +[FastClonerClonable] |
| 12 | +[FastClonerTrustNullability] |
| 13 | +public partial class ComplexModel |
| 14 | +{ |
| 15 | + public string Id { get; set; } = string.Empty; |
| 16 | + public string Name { get; set; } = string.Empty; |
| 17 | + public int Version { get; set; } |
| 18 | + public DateTime CreatedAt { get; set; } |
| 19 | + public DateTime? UpdatedAt { get; set; } |
| 20 | + public UserInfo? Owner { get; set; } |
| 21 | + public List<UserInfo>? Contributors { get; set; } |
| 22 | + public Dictionary<string, string>? Metadata { get; set; } |
| 23 | + public List<DataItem>? Items { get; set; } |
| 24 | + public Settings? Settings { get; set; } |
| 25 | +} |
| 26 | + |
| 27 | +public class UserInfo |
| 28 | +{ |
| 29 | + public string UserId { get; set; } = string.Empty; |
| 30 | + public string UserName { get; set; } = string.Empty; |
| 31 | + public string Email { get; set; } = string.Empty; |
| 32 | + public UserRole Role { get; set; } |
| 33 | + public ContactInfo? Contact { get; set; } |
| 34 | +} |
| 35 | + |
| 36 | +public class ContactInfo |
| 37 | +{ |
| 38 | + public string Phone { get; set; } = string.Empty; |
| 39 | + public string Address { get; set; } = string.Empty; |
| 40 | + public string City { get; set; } = string.Empty; |
| 41 | + public string Country { get; set; } = string.Empty; |
| 42 | +} |
| 43 | + |
| 44 | +public class DataItem |
| 45 | +{ |
| 46 | + public string ItemId { get; set; } = string.Empty; |
| 47 | + public string Title { get; set; } = string.Empty; |
| 48 | + public string Description { get; set; } = string.Empty; |
| 49 | + public double Value { get; set; } |
| 50 | + public List<string>? Tags { get; set; } |
| 51 | + public List<SubItem>? SubItems { get; set; } |
| 52 | + public Dictionary<string, string>? Properties { get; set; } |
| 53 | +} |
| 54 | + |
| 55 | +public class SubItem |
| 56 | +{ |
| 57 | + public string SubId { get; set; } = string.Empty; |
| 58 | + public string Label { get; set; } = string.Empty; |
| 59 | + public int Quantity { get; set; } |
| 60 | + public decimal Price { get; set; } |
| 61 | +} |
| 62 | + |
| 63 | +public class Settings |
| 64 | +{ |
| 65 | + public bool IsEnabled { get; set; } |
| 66 | + public int MaxItems { get; set; } |
| 67 | + public TimeSpan Timeout { get; set; } |
| 68 | + public List<string>? AllowedDomains { get; set; } |
| 69 | + public Dictionary<string, int>? Limits { get; set; } |
| 70 | + public AdvancedSettings? Advanced { get; set; } |
| 71 | +} |
| 72 | + |
| 73 | +public class AdvancedSettings |
| 74 | +{ |
| 75 | + public int CacheSize { get; set; } |
| 76 | + public bool UseCompression { get; set; } |
| 77 | + public string CompressionLevel { get; set; } = string.Empty; |
| 78 | + public List<string>? Features { get; set; } |
| 79 | +} |
| 80 | + |
| 81 | +public enum UserRole |
| 82 | +{ |
| 83 | + Guest = 0, |
| 84 | + User = 1, |
| 85 | + Admin = 2, |
| 86 | + Owner = 3, |
| 87 | +} |
| 88 | + |
| 89 | +/// <summary> |
| 90 | +/// Mapperly mapper for ComplexModel (compile-time code generation). |
| 91 | +/// </summary> |
| 92 | +[Mapper(UseDeepCloning = true)] |
| 93 | +public static partial class MapperlyCloner |
| 94 | +{ |
| 95 | + public static partial ComplexModel Clone(ComplexModel source); |
| 96 | +} |
0 commit comments