January 2020
Intermediate to advanced
532 pages
13h 31m
English
In order to manage write access to the fields of an object, we can extend the setproperty! function, in a similar way to how we did for read access.
Let's recall how the FileContent data type was designed:
mutable struct FileContent path loaded contentsend
Suppose that we want to allow the user to switch to a different file by mutating the path field with a new file location. In addition to this, we want to prevent the loaded and contents fields from being changed directly using dot notation. To achieve that, we can extend the setproperty! function as follows:
function Base.setproperty!(fc::FileContent, s::Symbol, value) if s === :path ss = lstat(value) setfield!(fc, :path, value) setfield!(fc, :loaded, ...
Read now
Unlock full access