Dinaup Coding Standards & Extension Methods

Required Import

using static Dinaup.extensions;

Code Style Guidelines

Nullable Types

  • Do NOT use nullable types (e.g., DateTime?, decimal?) unless absolutely necessary

  • Use default values to represent "empty":

    • Empty DateTimeDateTime.MinValue

    • Empty decimal0

    • Empty GuidGuid.Empty

Example: "Maximum 0" means no maximum limit


Preferred Practices

Collections

DO: _items.IsNotEmpty()DON'T: _items?.Count > 0

Component Properties (Blazor)

DO: [email protected]DON'T: Vigente="x.Data" 💡 Only use quotes for string literals

Guid Comparison

DO: f.NextRowId.IsEmpty()DON'T: f.NextRowId== Guid.Empty

DO: prevId.IsNotEmpty()DON'T: prevId != Guid.Empty

Boolean Comparison

DO: f.Enabled == FalseDON'T: !f.Enabled 💡 False is more readable and visible than !


Extension Methods

.STR() - String Conversion

Replaces .ToString() with better defaults:

Input
Output

null

"" (empty string)

Guid.Empty

"" (not "0000-0000...")

Numbers

US format (. as decimal separator)

bool

"1" or "0"


.INT(optional [default]) - Integer Conversion

Converts value to integer. Returns default value if conversion fails.

Example:

"123".INT()      // 123
"abc".INT()      // Exception
"abc".INT(99)    // 99

.DEC(optional [default]) - Decimal Conversion

Converts value to decimal. Returns default value if conversion fails.

Example:

"12.5".DEC()     // 12.5
"abc".DEC()      // Exception
"abc".DEC(9.9)   // 9.9

.BOOL() - Boolean Conversion

Converts value to boolean.

"1".BOOL()         // True
"si".BOOL()        // True
"sí".BOOL()        // True
"on".BOOL()        // True
"yes".BOOL()       // True
"true".BOOL()      // True

"0".BOOL()         // False
"false".BOOL()     // False

/// Any other value = false


Validation Extensions

.IsNotNull

Checks if reference is not null.

.IsNull

Checks if reference is null.

.IsEmpty

Checks if value is empty:

  • Guid.Empty

  • "" (empty string)

  • DateTime.MinValue

  • 0 for numeric types

  • Arrays, dictionaries, lists, or any collection with zero elements

.IsNotEmpty

Opposite of .IsEmpty. For collections: returns true if at least one element exists.

💡 Note: These methods already include null checks and have syntax highlighting.


String Comparison

.EqualsIgnoreCase()

Case-insensitive string comparison.

.LikeM()

LIKE-style wildcard pattern matching (case-sensitive).

.LikeMIgnoreCase()

LIKE-style wildcard pattern matching (case-insensitive).


Dictionary Extensions

.GetM(key [, defaultValue])

Safe dictionary getter:

  • Returns null if key not found (when no default provided)

  • Returns defaultValue if key not found (when default provided)

Example:

MyDictionary.GetM("key")              // null if not found
MyDictionary.GetM("key", "default")   // "default" if not found

💡 Use .GetM() whenever it reduces lines of code

Última actualización