Create a gist now

Instantly share code, notes, and snippets.

Base class for MSBuild tasks which logs all properties marked `[Required]`
public abstract class LoggingTask : Task
{
protected void LogInputs()
{
Log.LogMessage(MessageImportance.High, "Inputs:");
foreach (var propertyInfo in GetInputProperties())
{
LogProperty(propertyInfo);
}
}
private IEnumerable<PropertyInfo> GetInputProperties()
{
var propertyInfos = from propertyInfo in this.GetType().GetProperties()
where propertyInfo.HasAttribute<RequiredAttribute>()
select propertyInfo;
return propertyInfos;
}
private void LogProperty(PropertyInfo propertyInfo)
{
string name = propertyInfo.Name;
var value = propertyInfo.GetValue(this);
Log.LogMessage(MessageImportance.High, " {0} = {1}", name, value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment