mapxtreme2004经典代码之二:TableInfo
The example code below convers the concept of System.Reflection.
Also it is a Window application, but I have write Console.WriteLine() method in it, so u should run it in the command line like this
eg: application.exe >info.txt
Also it is a Window application, but I have write Console.WriteLine() method in it, so u should run it in the command line like this
eg: application.exe >info.txt
1 private void button2_Click(object sender, System.EventArgs e)
2 {
3 Table table = MapInfo.Engine.Session.Current.Catalog[this.mapControl1.Map.Layers[0].Alias];
4
5 TableInfo ti = table.TableInfo;
6 Type type = ti.GetType();
7
8 PropertyInfo[] api = type.GetProperties();
9 string s1="";
10 foreach(PropertyInfo pi in api)
11 {
12 s1 += pi.Name +"="+ pi.GetValue(ti,null)+"\r\n";
13 }
14
15 Console.WriteLine(s1);
16 Console.WriteLine();
17
18 s1="";
19 foreach(PropertyInfo pi in api)
20 {
21 s1 += pi.Name +"="+ pi.GetValue(ti,null)+"\r\n";
22 }
23
24
25 s1+="\r\n";
26
27 FieldInfo[] afi = type.GetFields();
28 foreach(FieldInfo fi in afi)
29 {
30 s1 += fi.Name+"="+fi.GetValue(ti);
31 }
32
33
34 s1 += "\r\n";
35 foreach(Column c in ti.Columns)
36 {
37
38 s1 += "Alias="+c.Alias+"\r\n"+"DataType="+c.DataType+"\r\n"+"Width="+c.Width+"\r\n";
39 if(c.DataType == MIDbType.FeatureGeometry)
40 {
41 GeometryColumn gc = (GeometryColumn)c;
42 MapInfo.Geometry.CoordSys cs = gc.CoordSys;
43 s1 += "MapBasicString="+cs.MapBasicString+"\r\n";
44 MapInfo.Geometry.DRect dr = gc.Bounds;
45 s1 += "Bounds="+dr+"\r\n";
46 }
47
48 }
49
50 Console.WriteLine(s1);
51
52 }
2 {
3 Table table = MapInfo.Engine.Session.Current.Catalog[this.mapControl1.Map.Layers[0].Alias];
4
5 TableInfo ti = table.TableInfo;
6 Type type = ti.GetType();
7
8 PropertyInfo[] api = type.GetProperties();
9 string s1="";
10 foreach(PropertyInfo pi in api)
11 {
12 s1 += pi.Name +"="+ pi.GetValue(ti,null)+"\r\n";
13 }
14
15 Console.WriteLine(s1);
16 Console.WriteLine();
17
18 s1="";
19 foreach(PropertyInfo pi in api)
20 {
21 s1 += pi.Name +"="+ pi.GetValue(ti,null)+"\r\n";
22 }
23
24
25 s1+="\r\n";
26
27 FieldInfo[] afi = type.GetFields();
28 foreach(FieldInfo fi in afi)
29 {
30 s1 += fi.Name+"="+fi.GetValue(ti);
31 }
32
33
34 s1 += "\r\n";
35 foreach(Column c in ti.Columns)
36 {
37
38 s1 += "Alias="+c.Alias+"\r\n"+"DataType="+c.DataType+"\r\n"+"Width="+c.Width+"\r\n";
39 if(c.DataType == MIDbType.FeatureGeometry)
40 {
41 GeometryColumn gc = (GeometryColumn)c;
42 MapInfo.Geometry.CoordSys cs = gc.CoordSys;
43 s1 += "MapBasicString="+cs.MapBasicString+"\r\n";
44 MapInfo.Geometry.DRect dr = gc.Bounds;
45 s1 += "Bounds="+dr+"\r\n";
46 }
47
48 }
49
50 Console.WriteLine(s1);
51
52 }