Skip to content

Instantly share code, notes, and snippets.

@JayBazuzi
Last active December 28, 2015 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayBazuzi/7521986 to your computer and use it in GitHub Desktop.
Save JayBazuzi/7521986 to your computer and use it in GitHub Desktop.
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