Reflection/List properties: Difference between revisions
PascalABC.NET
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(PascalABC.NET) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 96:
Properties of C:
b</pre>
=={{header|Ecstasy}}==
For any object, the type of that object provides access to its properties:
<syntaxhighlight lang="ecstasy">
module test {
void run() {
@Inject Console console;
Property[] properties = &this.actualType.properties;
console.print($"The properties of {this}: {properties}");
}
}
</syntaxhighlight>
{{out}}
<pre>
x$ xec test
The properties of test: [immutable Array<Class<Object, Object, Object, Struct>> classes, immutable Map<String, Class<Object, Object, Object, Struct>> classByName, String simpleName, String qualifiedName, Version version, immutable Map<String, Module> modulesByPath]
</pre>
=={{header|Elena}}==
ELENA
<syntaxhighlight lang="elena">import system'routines;
import system'dynamic;
Line 105 ⟶ 124:
class MyClass
{
}
public program()
{
Line 117 ⟶ 136:
this Y := "String";
};
MyClass.__getProperties().forEach::(p)
{
console.printLine("o.",p,"=",
}
}</syntaxhighlight>
Line 690 ⟶ 709:
123 1 0 1 0 0 1 0 1 0 0 1 1 1 NUM
A B I L M N O S U V W X 9 datatype(v)</pre>
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
uses System, System.Reflection;
type
MyClass = class
private
auto property NumberPrivate: integer := 666;
public
auto property Number: integer := 3;
end;
begin
var flags := BindingFlags.Instance or BindingFlags.Static
or BindingFlags.Public or BindingFlags.NonPublic
or BindingFlags.DeclaredOnly;
var obj := new MyClass;
typeof(MyClass).GetProperties(flags).Select(p -> (p.Name,p.GetValue(obj))).PrintLines;
end.
</syntaxhighlight>
{{out}}
<pre>
(NumberPrivate,666)
(Number,3)
</pre>
=={{header|Perl}}==
Line 1,168 ⟶ 1,215:
Note that, since attributes are stored internally as a map, the order in which the property names appear is undefined.
<syntaxhighlight lang="
#! instance_properties(p, q, r)
class C {
|