Skip to content

Default(Temperature).Degreescelcius thows NotImplemented exception. Its not clear accessing a default value instance #1615

@brianro

Description

@brianro

Describe the bug

.NetNano, accessing DegreesCelcuis of a Default(Temperature) throws NotImplemented Exception.

An unhandled exception of type 'System.NotImplementedException' occurred in UnitsNet.Temperature.dll
Additional information: Can not convert 0 to base units.

To Reproduce
Steps to reproduce the behavior (just an example):

  1. Create .NetNano project and add UnitsNet.

Execute this code

var x = default(Temperature);
Debug.WriteLine($"{x.DegreesCelsius}");

Behavior

Throws

An unhandled exception of type 'System.NotImplementedException' occurred in UnitsNet.Temperature.dll
Additional information: Can not convert 0 to base units.

Expected behavior

I understand this is a design decision: It wasn't clear that the value is actually a default(Temperature)

If you look at the additional context below, you can see how I bumped into it and the problem that created it.

Maybe a clearer message that the value is a default or unassigned. Does it need an "IsValid" or "IsAssigned" member? Something about "No value assigned to Temperature". Should there be a Temperature.Default member?

Additional context

I found this because another clause assigned its property to default(Temperature) which I stored and tried to access later, resulting in this error.

It just not easy to see or detect that the class is a default(Temperature) and not an actually assigned valid value)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions