Function request: create own rules for code checking

This request is because I keep making the same mistakes over and over again (stupid me!) - especially in quick hotfixes that are not really tested.

An example of those errors is that I want the value of a datagridviewcolumn as string, and then forget the .value, making the result Datagridview.TextBoxCell {ColumnIndex=7, RowIndex=0} instead of “abc”.

I know - it is stupid, but the error is quickly made as it is syntactical correct.

To prevent this I’d like to make a rule that DataGridViewColumn.ToString is smelling code that deserves a warning.

you could use a method aspect like this (put it in a separate dll, reference it from your project):

namespace ClassLibrary1;

interface
uses
  RemObjects.Elements.Cirrus;

type
  [MethodAspectAttribute(typeOf(DataGridViewColumn), false, 'ToString', 0, [])]
  ToStringWarning = public class(IMethodCallDecorator)
  private
  protected
  public
    method ProcessMethodCall(aContext: IContext; aMethod: IMethod; aValue: RemObjects.Elements.Cirrus.Values.ParameterizedValue): RemObjects.Elements.Cirrus.Values.Value;
    begin 
      aContext.Services.EmitWarning('Warning: This is probably wrong!');
      exit aValue;
    end;
  end;

implementation

end.

this warns on all calls to DataGridViewColumn.ToString

1 Like