-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an options dialog and a new "Default" setting for the "Run on build" property, so settings can be set at a global level.
- Loading branch information
Showing
8 changed files
with
142 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.ComponentModel; | ||
|
||
namespace BennorMcCarthy.AutoT4 | ||
{ | ||
public enum DefaultRunOnBuild | ||
{ | ||
Disabled, | ||
[Description("Before build")] | ||
BeforeBuild, | ||
[Description("After build")] | ||
AfterBuild | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
using System.Linq; | ||
|
||
namespace BennorMcCarthy.AutoT4 | ||
{ | ||
public class EnumDescriptionConverter : EnumConverter | ||
{ | ||
private readonly Type _enumType; | ||
|
||
public EnumDescriptionConverter(Type type) | ||
: base(type) | ||
{ | ||
_enumType = type; | ||
} | ||
|
||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) | ||
{ | ||
return destinationType == typeof(string); | ||
} | ||
|
||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType) | ||
{ | ||
if (value == null) | ||
return null; | ||
|
||
var field = _enumType.GetField(Enum.GetName(_enumType, value)); | ||
var attribute = field.GetCustomAttributes(typeof(DescriptionAttribute), true).Cast<DescriptionAttribute>().FirstOrDefault(); | ||
return attribute != null | ||
? attribute.Description | ||
: value.ToString(); | ||
} | ||
|
||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) | ||
{ | ||
return sourceType == typeof(string); | ||
} | ||
|
||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) | ||
{ | ||
var stringValue = value as string; | ||
if (stringValue == null) | ||
return Activator.CreateInstance(_enumType); | ||
|
||
var field = _enumType.GetFields() | ||
.FirstOrDefault(f => f.GetCustomAttributes(typeof(DescriptionAttribute), true).Cast<DescriptionAttribute>() | ||
.Any(a => stringValue.Equals(a.Description, StringComparison.OrdinalIgnoreCase))); | ||
return field != null | ||
? field.GetValue(null) | ||
: Enum.Parse(_enumType, stringValue); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.ComponentModel; | ||
using Microsoft.VisualStudio.Shell; | ||
|
||
namespace BennorMcCarthy.AutoT4 | ||
{ | ||
public class Options : DialogPage | ||
{ | ||
private DefaultRunOnBuild _buildAction = DefaultRunOnBuild.BeforeBuild; | ||
|
||
public const string CategoryName = "AutoT4"; | ||
public const string PageName = "General"; | ||
|
||
[Category("General")] | ||
[DisplayName("Run on build")] | ||
[Description("Run T4 templates when building.")] | ||
[DefaultValue(DefaultRunOnBuild.BeforeBuild)] | ||
[TypeConverter(typeof(EnumDescriptionConverter))] | ||
public DefaultRunOnBuild RunOnBuild | ||
{ | ||
get { return _buildAction; } | ||
set { _buildAction = value; } | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.ComponentModel; | ||
|
||
namespace BennorMcCarthy.AutoT4 | ||
{ | ||
public enum RunOnBuild | ||
{ | ||
[Description("Default")] | ||
Default = -1, | ||
Disabled = 0, | ||
[Description("Before build")] | ||
BeforeBuild, | ||
[Description("After build")] | ||
AfterBuild | ||
} | ||
} |