通过反射比较两个窗体的区别

2015-10-26 09:33:49  访问(1512) 赞(0) 踩(0)

try
            {
                eKing.GpsApp.DockContents.XLY.UpdateManage.MainFrm
                        frmOne
                        =
                        UpdateManageMainFrmFind();

                eKing.GpsApp.DockContents.XLY.VehicleAdmin.MainFrm
                                    frmTwo
                                    =
                                    VehicleAdminMainFrmFind();


                if (frmOne == null || frmTwo == null)
                {
                    MsgForm.MsgError("NULL");
                    return;
                }

                Type tOne = frmOne.GetType();
                Type tTwo = frmTwo.GetType();

                PropertyInfo[] pAOne = tOne.GetProperties();
                PropertyInfo[] pATwo = tTwo.GetProperties();
                
                PropertyInfo infoTwo = null;

                StringBuilder sb = new StringBuilder();
                object oOne = null;
                object oTwo = null;
                string strOne = null;
                string strTwo = null;

                foreach (PropertyInfo infoOne in pAOne)
                {
                    infoTwo = null;
                    foreach (PropertyInfo p in pATwo)
                    {
                        if (p.Name == infoOne.Name)
                        {
                            infoTwo = p;
                            break;
                        }
                    }

                    if (infoTwo == null)
                    {
                        sb.AppendLine(infoOne.Name + " ~~~~ ");
                        continue;
                    }

                    oOne = infoOne.GetValue(frmOne, null);
                    oTwo = infoTwo.GetValue(frmTwo, null);

                    if (oOne == null || oTwo == null)
                        continue;

                    if (oOne == null)
                    {
                        strOne = "[null]";
                    }
                    else
                    {
                        strOne = oOne.ToString();
                    }

                    if (oTwo == null)
                    {
                        strTwo = "[null]";
                    }
                    else
                    {
                        strTwo = oTwo.ToString();
                    }

                    if (oOne != null && oTwo != null)
                    {
                        if (oOne.Equals(oTwo))
                            continue;
                    }

                    sb.AppendLine(infoOne.Name + "=" + strOne + " ~~~~ " + infoTwo.Name + "=" + strTwo);
                }

                MessageBox.Show(sb.ToString());
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }


标签:通过反射比较两个窗体的区别 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)