Table of Contents

Class StatisticalRegionExtensions

Namespace
Cuemon.Extensions.Globalization
Assembly
Cuemon.Extensions.Core.dll

Provides extension methods for StatisticalRegionInfo.

public static class StatisticalRegionExtensions
Inheritance
StatisticalRegionExtensions

Examples

StatisticalRegionExtensions provides extension methods for classifying geographic regions using the UN M.49 standard via the World class. This example retrieves StatisticalRegion instances for the world ("001"), Europe ("150"), Western Europe ("155"), Denmark ("208"), and the United States ("840"), then calls classification methods like IsWorld, IsRegion, IsSubregion, IsCountryOrTerritory, IsArea, and HasIsoCodes. It also traverses Denmark's hierarchy using GetAncestors() to show parent regions, finds the US by RegionInfo, and counts all countries via world.Countries.Count(). Console output confirms each classification, such as True for denmark.IsCountryOrTerritory() and the ancestor chain Northern Europe → Europe → World.

using System;
using System.Globalization;
using System.Linq;
using Cuemon.Extensions.Globalization;
using Cuemon.Globalization;

namespace MyApp.Examples;

public class Example
{
    public void Run()
    {

        // Access regions via the World class
        var world = World.GetStatisticalRegion("001");
        var europe = World.GetStatisticalRegion("150");
        var westernEurope = World.GetStatisticalRegion("155");
        var denmark = World.GetCountry("208");     // Denmark M.49 code
        var usa = World.GetCountry("840");         // United States M.49 code

        // Classify by kind using the extension methods
        bool isWorld = world.IsWorld();                       // true
        bool isRegion = europe.IsRegion();                    // true (continent)
        bool isSubregion = westernEurope.IsSubregion();       // true
        bool isCountry = denmark.IsCountryOrTerritory();      // true
        bool isArea = europe.IsArea();                        // true (not a country)
        bool isCountryArea = denmark.IsArea();                // false (is a country)

        // Check intermediate regions (sub-Saharan Africa, Latin America)
        var subSaharanAfrica = World.GetStatisticalRegion("202");
        bool isIntermediate = subSaharanAfrica.IsIntermediateRegion(); // true

        // Verify hierarchy
        bool denmarkIsInEurope = denmark.Parent.IsSubregion(); // true (Northern Europe, M.49: 154)

        // Check if a country has associated .NET RegionInfo
        bool hasRegionInfo = usa.HasRegionInfo();  // true (US has RegionInfo)
        bool noRegionInfo = world.HasRegionInfo(); // false (World is not a country)

        // Check if a region has ISO codes
        bool hasIso = denmark.HasIsoCodes(); // true

        // Iterate all countries
        int countryCount = world.Countries.Count();
        Console.WriteLine($"Total countries/territories: {countryCount}");

        // Find a country by RegionInfo
        var regionInfo = new RegionInfo("US");
        var usaByRegion = World.GetCountry(regionInfo);
        Console.WriteLine(usaByRegion.IsCountryOrTerritory()); // True

        // Traverse the hierarchy
        foreach (var ancestor in denmark.GetAncestors())
        {
            Console.WriteLine($"{ancestor.Name} ({ancestor.Kind})");
        // "Northern Europe (Subregion)"
        // "Europe (Region)"
        // "World (World)"

}}
}

Methods

HasIsoCodes(StatisticalRegionInfo)

Determines whether the specified country has ISO code information available.

public static bool HasIsoCodes(this StatisticalRegionInfo region)

Parameters

region StatisticalRegionInfo

The region to check.

Returns

bool

true if the region is a country and has ISO codes; otherwise, false.

Exceptions

ArgumentNullException

region is null.

HasRegionInfo(StatisticalRegionInfo)

Determines whether the specified country has a .NET RegionInfo available.

public static bool HasRegionInfo(this StatisticalRegionInfo region)

Parameters

region StatisticalRegionInfo

The region to check.

Returns

bool

true if the region is a country and has OS-level RegionInfo support; otherwise, false.

Exceptions

ArgumentNullException

region is null.

IsArea(StatisticalRegionInfo)

Determines whether the specified region is a geographic area (not a country).

public static bool IsArea(this StatisticalRegionInfo region)

Parameters

region StatisticalRegionInfo

The region to check.

Returns

bool

true if the region is not a CountryOrTerritory; otherwise, false.

Exceptions

ArgumentNullException

region is null.

IsCountryOrTerritory(StatisticalRegionInfo)

Determines whether the specified region is a country or territory.

public static bool IsCountryOrTerritory(this StatisticalRegionInfo region)

Parameters

region StatisticalRegionInfo

The region to check.

Returns

bool

true if the region is a CountryOrTerritory; otherwise, false.

Exceptions

ArgumentNullException

region is null.

IsIntermediateRegion(StatisticalRegionInfo)

Determines whether the specified region is an intermediate region.

public static bool IsIntermediateRegion(this StatisticalRegionInfo region)

Parameters

region StatisticalRegionInfo

The region to check.

Returns

bool

true if the region is an IntermediateRegion; otherwise, false.

Exceptions

ArgumentNullException

region is null.

IsRegion(StatisticalRegionInfo)

Determines whether the specified region is a geographic region (continent or major area).

public static bool IsRegion(this StatisticalRegionInfo region)

Parameters

region StatisticalRegionInfo

The region to check.

Returns

bool

true if the region is a Region; otherwise, false.

Exceptions

ArgumentNullException

region is null.

IsSubregion(StatisticalRegionInfo)

Determines whether the specified region is a subregion.

public static bool IsSubregion(this StatisticalRegionInfo region)

Parameters

region StatisticalRegionInfo

The region to check.

Returns

bool

true if the region is a Subregion; otherwise, false.

Exceptions

ArgumentNullException

region is null.

IsWorld(StatisticalRegionInfo)

Determines whether the specified region is the World region.

public static bool IsWorld(this StatisticalRegionInfo region)

Parameters

region StatisticalRegionInfo

The region to check.

Returns

bool

true if the region is the World region; otherwise, false.

Exceptions

ArgumentNullException

region is null.