Это может быть достигнуто путем создания пользовательских атрибутов себя, что-то вроде:
[AttributeUsage(AttributeTargets.Property)]
public class TextSampleAttribute : Attribute
{
public string Value { get; set; }
public TextSampleAttribute(string value)
{
Value = value;
}
}
А затем модифицируя SetPublicProperties
метод ObjectGenerator
так:
private static void SetPublicProperties(Type type, object obj, Dictionary<Type, object> createdObjectReferences)
{
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
ObjectGenerator objectGenerator = new ObjectGenerator();
foreach (PropertyInfo property in properties)
{
if (property.IsDefined(typeof (TextSampleAttribute), false))
{
object propertyValue = property.GetCustomAttribute<TextSampleAttribute>().Value;
property.SetValue(obj, propertyValue, null);
}
else if (property.CanWrite)
{
object propertyValue = objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences);
property.SetValue(obj, propertyValue, null);
}
}
}
Я добавил чек, чтобы увидеть i f Определен атрибут TextSampleAttribute, и если это так, используйте его вместо автоматического сгенерированного.