Reflection/List properties: Difference between revisions

Added Factor
(Added C# implementation)
(Added Factor)
Line 81:
o.X=2
o.Y=String
</pre>
 
=={{header|Factor}}==
Mirrors present an object's slots and slot values as an associate structure.
<lang factor>USING: assocs kernel math math.ranges mirrors prettyprint
strings ;
 
TUPLE: foo
{ bar string }
{ baz string initial: "hi" }
{ baxx integer initial: 50 read-only } ;
C: <foo> foo
 
"apple" "banana" 200 <foo> <mirror>
[ >alist ] [ object-slots ] bi [ . ] bi@</lang>
{{out}}
<pre>
{ { "bar" "apple" } { "baz" "banana" } { "baxx" 200 } }
{
T{ slot-spec
{ name "bar" }
{ offset 2 }
{ class string }
{ initial "" }
}
T{ slot-spec
{ name "baz" }
{ offset 3 }
{ class string }
{ initial "hi" }
}
T{ slot-spec
{ name "baxx" }
{ offset 4 }
{ class integer }
{ initial 50 }
{ read-only t }
}
}
</pre>
 
1,827

edits