public int MyInt { get; }
}
+ public interface IGeolocation
+ {
+ public double Latitude { get; set; }
+ public double Longitude { get; set; }
+ }
+
[TypeConverter(typeof(GeolocationTypeConverter))]
- public struct Geolocation
+ public struct Geolocation : IGeolocation
{
public static readonly Geolocation Zero = new(0, 0);
}
}
+ public sealed class GeolocationClass : IGeolocation
+ {
+ public double Latitude { get; set; }
+ public double Longitude { get; set; }
+ }
+
+ public sealed record GeolocationRecord : IGeolocation
+ {
+ public double Latitude { get; set; }
+ public double Longitude { get; set; }
+ }
+
public class GeolocationWrapper
{
public Geolocation Location { get; set; }
Geolocation obj = configuration.Get<IDictionary<string, Geolocation>>()["First"];
ValidateGeolocation(obj);
-
obj = configuration.Get<IReadOnlyDictionary<string, Geolocation>>()["First"];
ValidateGeolocation(obj);
+
+ GeolocationClass obj1 = configuration.Get<IDictionary<string, GeolocationClass>>()["First"];
+ ValidateGeolocation(obj1);
+ obj1 = configuration.Get<IReadOnlyDictionary<string, GeolocationClass>>()["First"];
+ ValidateGeolocation(obj1);
+
+ GeolocationRecord obj2 = configuration.Get<IDictionary<string, GeolocationRecord>>()["First"];
+ ValidateGeolocation(obj2);
+ obj1 = configuration.Get<IReadOnlyDictionary<string, GeolocationClass>>()["First"];
+ ValidateGeolocation(obj2);
}
[Fact]
ValidateGeolocation(obj);
}
- private void ValidateGeolocation(Geolocation location)
+ private void ValidateGeolocation(IGeolocation location)
{
Assert.Equal(3, location.Latitude);
Assert.Equal(4, location.Longitude);