22using System . Collections . Generic ;
33using System . Linq ;
44using System . Management . Automation . Language ;
5+ using System . Reflection ;
56using System . Text ;
67using System . Threading . Tasks ;
78
@@ -17,10 +18,9 @@ internal abstract class ConfigurableScriptRule : IScriptRule
1718 public void ConfigureRule ( )
1819 {
1920 var arguments = Helper . Instance . GetRuleArguments ( this . GetName ( ) ) ;
20- //var configurableProps = GetConfigurableProperties();
2121 try
2222 {
23- var properties = this . GetType ( ) . GetProperties ( ) ;
23+ var properties = GetConfigurableProperties ( ) ;
2424 foreach ( var property in properties )
2525 {
2626 if ( arguments . ContainsKey ( property . Name ) )
@@ -35,16 +35,24 @@ public void ConfigureRule()
3535 }
3636 catch
3737 {
38- // return arguments with defaults
38+ // we do not know how to handle an exception yet in this case yet!
39+ // but we know that this should not crash the program hence we
40+ // have this empty catch block
3941 }
4042
4143 IsRuleConfigured = true ;
4244 }
4345
44- // private GetConfigurableProperties()
45- // {
46-
47- // }
46+ private IEnumerable < PropertyInfo > GetConfigurableProperties ( )
47+ {
48+ foreach ( var property in this . GetType ( ) . GetProperties ( ) )
49+ {
50+ if ( property . GetCustomAttribute ( typeof ( ConfigurableRulePropertyAttribute ) ) != null )
51+ {
52+ yield return property ;
53+ }
54+ }
55+ }
4856
4957 public abstract IEnumerable < DiagnosticRecord > AnalyzeScript ( Ast ast , string fileName ) ;
5058 public abstract string GetCommonName ( ) ;
@@ -56,7 +64,7 @@ public void ConfigureRule()
5664 }
5765
5866 [ AttributeUsage ( AttributeTargets . Property , AllowMultiple = false ) ]
59- public class ConfigurablePropertyAttribute : Attribute
67+ internal class ConfigurableRulePropertyAttribute : Attribute
6068 {
6169
6270 }
0 commit comments