Skip to content

Gendarme.Rules.Design.ImplementICloneableCorrectlyRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

ImplementICloneableCorrectlyRule

Assembly: Gendarme.Rules.Design
Version: 2.10

Description

This rule fires if you implement a object Clone() method without implementing the System.ICloneable interface. Either change the method so that it returns a better type than System.Object or implement ICloneable.

Examples

Bad example:

public class MyClass {
    public object Clone ()
    {
        MyClass myClass = new MyClass ();
        return myClass;
    }
}

Good example (ICloneable):

public class MyClass : ICloneable {
    public object Clone ()
    {
        MyClass myClass = new MyClass ();
        return myClass;
    }
}

Good example (not returning System.Object):

public class MyClass {
    public MyClass Clone ()
    {
        MyClass myClass = new MyClass ();
        return myClass;
    }
}

Notes

  • Prior to Gendarme 2.2 this rule was named UsingCloneWithoutImplementingICloneableRule
Clone this wiki locally