Esempio n. 1
0
 private void comModals_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.comModals.SelectedIndex > 0)
     {
         this.m_Model = this.m_Models[this.comModals.SelectedIndex];
     }
     else
     {
         this.m_Model = null;
     }
 }
Esempio n. 2
0
 private void btnBindModal_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog dlg = new OpenFileDialog()
     {
         Title = "选择文件", Filter = "动态库|*.dll"
     })
     {
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 var ass = System.Reflection.Assembly.LoadFile(dlg.FileName);
                 var tf  = ass.GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), false);
                 if (tf.Length == 0)
                 {
                     MessageBox.Show("选中的动态库没有平台版本信息");
                 }
                 else
                 {
                     if ((tf[0] as System.Runtime.Versioning.TargetFrameworkAttribute).FrameworkDisplayName.Split(' ')[2] != "4")
                     {
                         MessageBox.Show("所选动态库的 Framework 版本不是4.0");
                     }
                     else
                     {
                         this.m_Model = null;
                         this.m_Models.Clear();
                         this.m_Models.Add(new Models.NullNetModal()
                         {
                             m_Panel = this
                         });
                         Type m  = typeof(Models.NetModal);
                         int  id = 1;
                         foreach (Type t in ass.GetExportedTypes())
                         {
                             if (t.IsSubclassOf(m))
                             {
                                 var con = t.GetConstructor(new Type[] { });
                                 if (con != null)
                                 {
                                     this.m_Models.Add(con.Invoke(null) as Models.NetModal);
                                     this.m_Models[id++].m_Panel = this;
                                 }
                             }
                         }
                     }
                 }
             }
             catch { MessageBox.Show("选中的动态库不是DotNet的程序集"); }
         }
     }
 }