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

 1 None.gif          private   void  button2_Click( object  sender, System.EventArgs e)
 2 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 3InBlock.gif            Table table = MapInfo.Engine.Session.Current.Catalog[this.mapControl1.Map.Layers[0].Alias];
 4InBlock.gif            
 5InBlock.gif            TableInfo ti = table.TableInfo;
 6InBlock.gif            Type type = ti.GetType();
 7InBlock.gif
 8InBlock.gif            PropertyInfo[] api = type.GetProperties();
 9InBlock.gif            string s1="";
10InBlock.gif            foreach(PropertyInfo pi in api)
11ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
12InBlock.gif                s1 += pi.Name +"="+ pi.GetValue(ti,null)+"\r\n";
13ExpandedSubBlockEnd.gif            }
            
14InBlock.gif
15InBlock.gif            Console.WriteLine(s1);
16InBlock.gif            Console.WriteLine();
17InBlock.gif             
18InBlock.gif            s1="";
19InBlock.gif            foreach(PropertyInfo pi in api)
20ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
21InBlock.gif                s1 += pi.Name +"="+ pi.GetValue(ti,null)+"\r\n";
22ExpandedSubBlockEnd.gif            }

23InBlock.gif            
24InBlock.gif
25InBlock.gif            s1+="\r\n";
26InBlock.gif
27InBlock.gif            FieldInfo[] afi = type.GetFields();
28InBlock.gif            foreach(FieldInfo fi in afi)
29ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
30InBlock.gif                s1 += fi.Name+"="+fi.GetValue(ti);
31ExpandedSubBlockEnd.gif            }

32InBlock.gif
33InBlock.gif
34InBlock.gif            s1 += "\r\n";
35InBlock.gif            foreach(Column c in ti.Columns)
36ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
37InBlock.gif                
38InBlock.gif                s1 += "Alias="+c.Alias+"\r\n"+"DataType="+c.DataType+"\r\n"+"Width="+c.Width+"\r\n";                
39InBlock.gif                if(c.DataType == MIDbType.FeatureGeometry)
40ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
41InBlock.gif                    GeometryColumn gc = (GeometryColumn)c;
42InBlock.gif                    MapInfo.Geometry.CoordSys cs = gc.CoordSys;
43InBlock.gif                    s1 += "MapBasicString="+cs.MapBasicString+"\r\n";
44InBlock.gif                    MapInfo.Geometry.DRect dr = gc.Bounds;
45InBlock.gif                    s1 += "Bounds="+dr+"\r\n";
46ExpandedSubBlockEnd.gif                }

47InBlock.gif
48ExpandedSubBlockEnd.gif            }

49InBlock.gif            
50InBlock.gif            Console.WriteLine(s1);
51InBlock.gif
52ExpandedBlockEnd.gif        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值