-
Notifications
You must be signed in to change notification settings - Fork 404
Coding Style and Conventions
In general, the project follows the C# Coding Convention and Framework Design Guidelines. We use tools like StyleCop to help enforce some of the rules mentioned below.
- Always use
Unknown
at index 0 for return types that may have a value that is not known - Always use
Default
at index 0 for option types that can use the system default option - Follow naming guidelines for tense...
SensorSpeed
notSensorSpeeds
- Assign values (0,1,2,3) for all enums
- Include units only if one of the platforms includes it in their implementation. For instance HeadingMagneticNorth implies degrees on all platforms, but PressureInHectopascals is needed since platforms don't provide a consistent API for this.
- Use the standard units and most well accepted units when possible. For instance Hectopascals are used on UWP/Android and iOS uses Kilopascals so we have chosen Hectopascals.
- Prefer using
is
when checking for null instead of==
.
e.g.
// null
if (something is null)
{
}
// or not null
if (something is not null)
{
}
- Avoid using the
!
null forgiving operator to avoid the unintended introduction of bugs.
- Prefer
is
when checking for types instead of casting.
e.g.
if (something is Bucket bucket)
{
bucket.Empty();
}
- Use file scoped namespaces to help reduce code verbosity.
e.g.
namespace CommunityToolkit.Maui.Converters;
using System;
class BoolToObjectConverter
{
}
Please use { }
after if
, for
, foreach
, do
, while
, etc.
e.g.
if (something is not null)
{
ActOnIt();
}
Please avoid adding new code that throws a NotImplementedException
. According to the Microsoft Docs, we should only "throw a NotImplementedException
exception in properties or methods in your own types when that member is still in development and will only later be implemented in production code. In other words, a NotImplementedException exception should be synonymous with 'still in development.'"
In other words, NotImplementedException
implies that a feature is still in development, indicating that the Pull Request is incomplete.