Uri fields or properties should be of type System.Uri

Rule ND2209 .NET Framework Usage / System

Fields and properties named ending with 'Uri' or 'Url' represent a Uniform Resource Identifier or Locator and should be typed System.Uri. Matches those that are not.

How to fix

Rename the field/property, or type it System.Uri. Severity is Low: more an advice than a problem.

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>Uri fields or properties should be of type System.Uri</Name>
// <Id>ND2209:UriFieldsShouldBeOfTypeSystemUri</Id>

warnif count > 0 from m in JustMyCode.Members where 
   
  (m.IsField &&
   m.AsField.Name.EndsWithAny("Uri", "Url") && 
   m.AsField.FieldType != null &&
   m.AsField.FieldType.FullName != "System.Uri") ||

  (m.IsProperty &&
   m.AsProperty.Name.EndsWithAny("Uri", "Url") && 
   m.AsProperty.PropertyType != null &&
   m.AsProperty.PropertyType.FullName != "System.Uri") 

select new { 
   m, 
   type = m.IsField ? m.AsField.FieldType : m.AsProperty.PropertyType,
   Debt = 5.ToMinutes().ToDebt(),
   Severity = Severity.Low
}

//<Expl>
// The *{0}* should be typed with *System.Uri*.
//</Expl>

//<Desc>
// Fields and properties named ending with *'Uri'* or *'Url'* represent a
// *Uniform Resource Identifier or Locator* and should be typed
// **System.Uri**. Matches those that are not.
//</Desc>

//<HowToFix>
// Rename the field/property, or type it *System.Uri*. Severity is **Low**:
// more an advice than a problem.
//</HowToFix>

.NET Framework Usage / System: all 12 items