Retrieving all attributes from a Type
Suppose you have a Type T.
To see all methods that accept an object of type T as an argument, you can do:
methodswith(T)
To see all fields (i.e.: type's "properties"):
fieldnames(T)
If you want to combine all info into a function, you can do one yourself, like this:
function allinfo(type)
display(fieldnames(type))
methodswith(type)
end
Retrieving all attributes from an object
If instead of having a Type, you have an object a, the procedure is the same, but substituting T and type above by typeof(a):
# See all methods
methodswith(typeof(a))
# See all fields
methodswith(typeof(a))
# Function combining both
function allinfo(a)
type = typeof(a)
display(fieldnames(type))
methodswith(type)
end
Retrieving all attributes regardless of its nature
Using multiple dispatch, you can define a function with three methods that gets you all info regardless of what you pass as argument.
The third case is needed in case you want to inspect methods that accept Type objects as arguments.
# Gets all info when argument is a Type
function allinfo(type::Type)
display(fieldnames(type))
methodswith(type)
end
# Gets all info when the argument is an object
function allinfo(a)
type = typeof(a)
display(fieldnames(type))
methodswith(type)
end
# Gets all info when the argument is a parametric type of Type
function allinfo(a::Type{T}) where T <: Type
methodswith(a)
end