-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Smells.AvoidCodeDuplicatedInSiblingClassesRule(2.10)
Sebastien Pouliot edited this page Jan 22, 2011
·
2 revisions
Assembly: Gendarme.Rules.Smells
Version: 2.10
This rule looks for code duplicated in sibling subclasses.
Bad example:
public class BaseClassWithCodeDuplicated {
protected IList list;
}
public class OverriderClassWithCodeDuplicated : BaseClassWithCodeDuplicated {
public void CodeDuplicated ()
{
foreach (int i in list) {
Console.WriteLine (i);
}
list.Add (1);
}
}
public class OtherOverriderWithCodeDuplicated : BaseClassWithCodeDuplicated {
public void OtherMethod ()
{
foreach (int i in list) {
Console.WriteLine (i);
}
list.Remove (1);
}
}
Good example:
public class BaseClassWithoutCodeDuplicated {
protected IList list;
protected void PrintValuesInList ()
{
foreach (int i in list) {
Console.WriteLine (i);
}
}
}
public class OverriderClassWithoutCodeDuplicated : BaseClassWithoutCodeDuplicated {
public void SomeCode ()
{
PrintValuesInList ();
list.Add (1);
}
}
public class OtherOverriderWithoutCodeDuplicated : BaseClassWithoutCodeDuplicated {
public void MoreCode ()
{
PrintValuesInList ();
list.Remove (1);
}
}
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!