Basically what i would want is code operator which would take string and act like it is source code.
With the code operator would the below be valid code.
code("var") i = 5;
And it would be the same as
var i = 5;
why?
The usecase i showed earlyer would be useles but for example this would be useful to call methods or create classes.
Imagine this:
You have validate method that takes object as parameter
Than you have some methods like validateInt32, validateString, etc
And you want to call them from the validate method. Thanks to the code operator it could look like this:
func validate(value: object): bool {
var objType = typeof(value).ToString();
return code("validate$objType(value as $objType)");
}
Eh. Problem number 1: such syntax means we have to ship the compiler with the app. Problem number 2: your example doesn't justify it. There's myObject is SomeType and reflection's AssignableTo method.
So this is crazy feature, but hear me out.
what do i mean
Basically what i would want is
code
operator which would take string and act like it is source code. With the code operator would the below be valid code.And it would be the same as
why?
The usecase i showed earlyer would be useles but for example this would be useful to call methods or create classes. Imagine this: You have
validate
method that takes object as parameter Than you have some methods likevalidateInt32
,validateString
, etc And you want to call them from thevalidate
method. Thanks to the code operator it could look like this:possible problems
It won't be implementable