From aa2421dc99544542c816b7c8e8add727673767d3 Mon Sep 17 00:00:00 2001 From: "Viral B. Shah" Date: Tue, 22 Feb 2022 22:36:20 -0500 Subject: [PATCH] Documentation: added example to the function hasfield. (From #41782) (#44274) Co-authored-by: Johnny Chen (cherry picked from commit 9c0e5b0d186ea95a06d5b0bdc4bc19d1a17b444d) --- base/reflection.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/base/reflection.jl b/base/reflection.jl index bf8ceabe1f39b..5490cae9511c8 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -194,8 +194,23 @@ fieldnames(t::Type{<:Tuple}) = ntuple(identity, fieldcount(t)) Return a boolean indicating whether `T` has `name` as one of its own fields. +See also [`fieldnames`](@ref), [`fieldcount`](@ref), [`hasproperty`](@ref). + !!! compat "Julia 1.2" This function requires at least Julia 1.2. + +# Examples +```jldoctest +julia> struct Foo + bar::Int + end + +julia> hasfield(Foo, :bar) +true + +julia> hasfield(Foo, :x) +false +``` """ function hasfield(T::Type, name::Symbol) @_pure_meta