private static void DemoDebugAttribute() { var a = new ProductA { Name = "Sarah", Count = 15, }; var b = new ProductB { Name = "Sarah", Count = 16, }; Console.WriteLine("Done"); }
private void WriteFirstName() { PropertyInfo firstNameProperty = typeof(ProductB).GetProperty(nameof(ProductB.Name)); DisplayAttribute firstNameDisplayAttribute = (DisplayAttribute) Attribute.GetCustomAttribute(firstNameProperty, typeof(DisplayAttribute)); IndentAttribute[] indentAttributes = (IndentAttribute[]) Attribute.GetCustomAttributes(firstNameProperty, typeof(IndentAttribute)); StringBuilder sb = new StringBuilder(); if (indentAttributes != null) { foreach (IndentAttribute a in indentAttributes) { sb.Append(new string(' ', 4)); } } if (firstNameDisplayAttribute != null) { Console.ForegroundColor = firstNameDisplayAttribute.Color; sb.Append(firstNameDisplayAttribute.Label); } var b = new ProductB { Name = "Sarah", Count = 16, }; if (b.Name != null) { sb.Append(b.Name); } Console.WriteLine(sb); }
public ProductDebugDisplay(ProductB contact) { _contact = contact; }