1 open FILE, "data-classes.txt";
5 while ($line = <FILE>) {
9 if (index($line, ":") == -1) {
11 if (index($line, ";") != -1) {
12 $class = substr($line, 0, index($line, ";"));
13 $magicprops = substr($line, index($line, ";") + 2);
14 print "$class: $magicprops\n";
17 $class = substr($line, 0, index($line, ":"));
18 $properties = substr($line, index($line, ":") + 2);
19 if (index($properties, ";") != -1) {
20 $magicprops = substr($properties, index($properties, ";") + 2);
21 $properties = substr($properties, 0, index($properties, ";"));
24 if ($line =~ m/Xaml[^(]+\(/) {
26 $parent =~ s/(Xaml[^(]+)\(([^)]+)\).*/\2/;
28 $clname =~ s/(Xaml[^(]+)\(([^)]+)\).*/\1/;
33 $classes{$class} = { parent => $parent,
34 properties => $properties,
35 magicprops => $magicprops };
40 return $classes{$x}->{"parent"};
44 return $classes{$x}->{"properties"};
46 sub get_magic_properties {
48 return $classes{$x}->{"magicprops"};
52 sub get_extended_params_list {
55 while ($x ne "XamlNode") {
57 $params = &get_properties($x) . ", " . $params;
60 $params =~ s/^XamlNodeType tokenType, //;
67 while ($x ne "object") {
76 for $class (keys %classes) {
79 print X "// THIS FILE AUTOMATICALLY GENERATED BY data-classes-builder.pl\n";
80 print X "// EDITING IS PROBABLY UNWISE\n";
81 print X "namespace System.Windows.Serialization {\n";
82 print X "using System;\n";
83 print X "using System.Reflection;\n";
84 print X "using System.Windows;\n";
85 $parent = &get_parent($class);
87 $props = &get_properties($class);
88 @propl = split /, /, $props;
90 $eprops = &get_extended_params_list($class);
91 @epropl = split /, /, $eprops;
94 $allprops .= ", $props" unless ($props eq "");
95 @allpropl = split /, /, $allprops;
96 my @allpropl2 = @allpropl;
97 for $prop (@allpropl2) {
100 $allprops = join ", ", @allpropl2;
102 $mprops = &get_magic_properties($class);
103 @mpropl = split /, /, $mprops;
105 $xamlnodetype = "$class";
106 $xamlnodetype =~ s/^Xaml(.+)Node$/\1/;
107 $xamlnodetype = "XamlNodeType.$xamlnodetype";
109 print X "public class $class : " . $parent . " { \n";
113 next if $prop =~ m/^\+/;
114 print X "\tprivate $prop;\n";
116 for $prop (@mpropl) {
117 next if $prop =~ m/^\+/;
120 print X "\tprivate $x;\n";
125 if ($class eq "XamlNode") {
126 print X "\tpublic $class($props)\n";
129 $propname = substr($prop, index($prop, " ") + 1);
130 print X "\t\tthis.$propname = $propname;\n";
134 print X "\tpublic $class($allprops)\n";
135 print X "\t\t: this(";
137 push @allpropnames, $xamlnodetype;
138 for $prop (@allpropl) {
139 push @allpropnames, substr($prop, index($prop, " ") + 1);
141 print X (join ", ", @allpropnames);
142 print X ")\n\t{}\n\n\n";
144 print X "\tinternal $class(XamlNodeType type, $allprops)\n";
147 for $prop (@epropl) {
148 push @epropnamel, substr($prop, index($prop, " ") + 1);
150 $epropnames = join ", ", @epropnamel;
151 print X "\t\t: base(type, $epropnames)\n";
154 $propname = substr($prop, index($prop, " ") + 1);
155 if ($prop =~ m/^\+/) {
156 $func = substr($propname, 0, 1);
157 $func =~ tr/a-z/A-Z/;
158 $func = "set$func" . substr($propname, 1);
159 print X "\t\tthis.$func($propname);\n";
161 print X "\t\tthis.$propname = $propname;\n";
169 $proptype = substr($prop, 0, index($prop, " "));
170 $fieldname = substr($prop, index($prop, " ") + 1);
172 $propname = substr($fieldname, 0, 1);
173 $propname =~ tr/a-z/A-Z/;
174 $propname .= substr($fieldname, 1);
176 if ($proptype =~ m/^\+/) {
180 print X "\n\tpublic $proptype $propname {\n";
181 print X "\t\tget { return $fieldname; }\n";
184 for $prop (@mpropl) {
185 $proptype = substr($prop, 0, index($prop, " "));
186 $propname = substr($prop, index($prop, " ") + 1);
187 $fieldname = "_$propname";
190 print X "\n\tpublic $proptype $propname {\n";
191 print X "\t\tget { return $fieldname; }\n";
193 print X "\n\tinternal void set$propname($proptype v) {\n";
194 print X "\t\t$fieldname = v;\n";