Example #1
0
 /*
  * Override properly the ToString, Equals, GetHashCode method in C#
  */
 private String replaceMethodName(Meth meth, String name) {
   if (meth.getModifiers().contains(Modifier.PUBLIC) && meth.isInherited()) {
     if (name.equals("toString") && meth.getParams().isEmpty()) {
       return "ToString";
     } else if (name.equals("equals")
         && meth.getParams().size() == 1
         && meth.getParams().get(0).getType().equals(TypeObject.INSTANCE)) {
       return "Equals";
     } else if (name.equals("hashCode") && meth.getParams().isEmpty()) {
       return "GetHashCode";
     }
   }
   return name;
 }
Example #2
0
  @Override
  public String getCode(Meth meth) {

    // #join ( $method.Modifiers " ") #if($method.isInherited())override#end
    // $method.Type $method.Name ( #params( $method.getParams() ) )

    String name = replaceMethodName(meth, meth.getName());

    customizeModifiers(meth);

    return String.format(
        "%s %s %s(%s)",
        getCode(meth.getModifiers()),
        meth.getType(),
        name,
        GeneratorHelper.joinParams(meth.getParams()));
  }