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 necessaryUse default values to represent "empty":
Empty
DateTime→DateTime.MinValueEmpty
decimal→0Empty
Guid→Guid.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 == False
❌ DON'T: !f.Enabled
💡 False is more readable and visible than !
Extension Methods
.STR() - String Conversion
.STR() - String ConversionReplaces .ToString() with better defaults:
null
"" (empty string)
Guid.Empty
"" (not "0000-0000...")
Numbers
US format (. as decimal separator)
bool
"1" or "0"
.INT(optional [default]) - Integer Conversion
.INT(optional [default]) - Integer ConversionConverts 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
.DEC(optional [default]) - Decimal ConversionConverts 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
.BOOL() - Boolean ConversionConverts 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
.IsNotNullChecks if reference is not null.
.IsNull
.IsNullChecks if reference is null.
.IsEmpty
.IsEmptyChecks if value is empty:
Guid.Empty""(empty string)DateTime.MinValue0for numeric typesArrays, dictionaries, lists, or any collection with zero elements
.IsNotEmpty
.IsNotEmptyOpposite 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()
.EqualsIgnoreCase()Case-insensitive string comparison.
.LikeM()
.LikeM()LIKE-style wildcard pattern matching (case-sensitive).
.LikeMIgnoreCase()
.LikeMIgnoreCase()LIKE-style wildcard pattern matching (case-insensitive).
Dictionary Extensions
.GetM(key [, defaultValue])
.GetM(key [, defaultValue])Safe dictionary getter:
Returns
nullif key not found (when no default provided)Returns
defaultValueif 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