Skip to content

Gendarme.Rules.Performance.AvoidLargeStructureRule(2.10)

Sebastien Pouliot edited this page Jan 22, 2011 · 2 revisions

AvoidLargeStructureRule

Assembly: Gendarme.Rules.Performance
Version: 2.10

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.

Clone this wiki locally