You can lookup the fieldtype in MyType and parse it as that
mutable struct MyType
a::Int
b::Float64
end
function foo!(B::MyType)
vars = ["a = 10"
"b = 2.0"] # from data file
for line in vars
var, val = strip.(split(line, "="))
sym = Symbol(var)
T = fieldtype(MyType, sym)
setproperty!(B, sym, parse(T, val))
end
end
julia> B = MyType(1, 2.0)
MyType(1, 2.0)
julia> foo!(B)
julia> B
MyType(10, 2.0)
The question here is, what subset of the full Julia language do you want to support. If it is the full Julia language then obviously you are going to need a Julia parser at some point, but if you just want to set some numbers and strings, invoking the Julia parser is overkill and can lead to security problems.