Skip to content

Gendarme.Rules.Performance.AvoidLargeStructureRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

AvoidLargeStructureRule

Assembly: Gendarme.Rules.Performance
Version: git

Description

This rule will fire if a value type (struct in C#) is larger than a maximum value (16 bytes by default). This is a problem because, unlike reference types, value types are bitwise-copied whenever they are assigned to a variable or passed to a method. If the type cannot be reduced in size then it should be turned into a reference type (class in C#).

Examples

Bad example:

public struct BigArgb {
    long a, r, g, b;
}

Good example:

public sealed class BigArgb {
    long a, r, g, b;
}

Notes

  • This rule is available since Gendarme 2.0

Configuration

Some elements of this rule can be customized to better fit your needs.

MaxSize

The maximum size structs may be without a defect.

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally