Replies: 1 comment 6 replies
-
I'm not sure I understand this bit:
Both of there are valid at the module level (modules are just a special cases of classes after all!) and they function identically. That said, I think your proposal is actually something you may be able to implement in-language! The only change you'd need is adding the user-assignable type to the property: class Test {
@Transform { from = Uri; using = (it) -> new UriObject { protocol = "example:" host = it } }
uri: Uri|UriObject
} Then you could use an output converter applied all One note, because I haven't actually tried to implement this: you may only be able to use classes (not any type like typealiases) for |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I'm dealing with a project that requires a lot of data that needs to be processed or converted. To make the user-side configuration easier, I'm transforming user-supplied input into corrisponding classes or the correct string/enum/uint representation. My code looks like this:
I like doing things this way to avoid requiring the user-side configs from having to convert every "uri" into a UriObject or transform the input themselves. However, this results in having duplicated and similarly-named properties that only make sense on the user-side (i.e:
name
) or the processing side (i.e:uri
).This isn't too bad with classes since you can use
hidden
orlocal
, however this is a pain point for top-level properties. I have quite a few files that have bothvalues
(user-side) andvalueobjs
(processing side).Ideally, I'd like some way of attaching a setter to a single property that would automatically convert the user input into the corrisponding object. Maybe something like this?
Any feedback or alternate solutions are welcome
Beta Was this translation helpful? Give feedback.
All reactions