< Dice‎ | PbP‎ | RollPost
Revision as of 19:42, 28 April 2017 by Skizzerz (talk | contribs) (Created page with "{{APIdoc|RollPost.Validate Method ()}} Checks if Current has diverged from Pristine. {{ns}} == Syntax == <syntaxhighlight lang="C#"> public virtual bool Validate() </syntaxh...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

RollPost.Validate Method ()

From DiceRoller Documentation

Checks if Current has diverged from Pristine.

  • Namespace: Dice.PbP
  • Assembly: DiceRoller (in DiceRoller.dll)

Syntax

public virtual bool Validate()

Return Value

Type: System.Boolean

Returns true if Current begins with or is equal to Pristine, and false otherwise.

Remarks

Checks if Current has diverged from Pristine. If it has, this returns false and indicates that there was some tampering of the dice expressions (cheating). If it hasn't, this returns true to indicate that everything is good.

Additionally, if this succeeds, Pristine is set to Current.

If you wish to add your own checks, extend RollPost in your own class and override Validate. Call the base Validate() only if your own checks all succeed. Otherwise, you may accidentally overwrite Pristine on validation failure.

You should always call Validate() before serializing a RollPost and before displaying any results obtained from it. An obvious warning should be displayed to the user if the validation fails. Validation can fail for any of the following reasons:

  • There are less Current rolls than Pristine rolls (indicates rolls were removed since the last valid post).
  • A Current roll doesn't match a Pristine roll at the same point (indicates rolls were altered or rearranged since the last valid post).

On the flip side, Validate will succeed if either of the following are true:

  • There are exactly as many Current rolls as there are Pristine rolls, and all rolls match each other (indicates the post was not modified).
  • There are more Current rolls than Pristine rolls, but the beginning of Current exactly matches Pristine (indicates new rolls were added at the end, but existing rolls were not removed, modified, or rearranged). In this second case, Pristine is updated to the new state of Current after calling Validate so that future Validate calls must take all of the new rolls into account as well.