Last active
December 28, 2015 15:29
-
-
Save JayBazuzi/7521986 to your computer and use it in GitHub Desktop.
Base class for MSBuild tasks which logs all properties marked `[Required]`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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