Skip to content
← Back

src/semantic/dotnet/scalar_conversion_sources.ghul

1
@@IF.dotnet()
2
3
namespace Semantic.DotNet is
4
use TYPE = System.Type
5
6
// Which scalar sources a scalar type needs a conversion constructor for:
7
// every one it does not already have a public constructor from. decimal
8
// and BigInteger bring their own from the wider numeric types, and those
9
// stay rather than being shadowed by a second overload of the same shape.
10
class SCALAR_CONVERSION_SOURCES is
11
needing_constructor(target: TYPE, scalars: Collections.Iterable[TYPE]) -> Collections.List[TYPE] static is
12
let result = Collections.LIST[TYPE]()
13
14
for source in scalars do
15
if !_has_constructor_from(target, source) then
16
result.add(source)
17
fi
18
od
19
20
return result
21
si
22
23
_has_constructor_from(target: TYPE, source: TYPE) -> bool static is
24
for constructor in target.get_constructors() do
25
let parameters = constructor.get_parameters()
26
27
if constructor.is_public /\ parameters.count == 1 /\ parameters[0].parameter_type == source then
28
return true
29
fi
30
od
31
32
return false
33
si
34
si
35
si