public static IUCView GetCustomView(string filePath) { IUCView result = null; if (!string.IsNullOrEmpty(filePath)) { string extName = FileHelper.GetFileExt(filePath); //ext = ext.ToLower(); if (ExtAssociation._ext2UC.ContainsKey(extName)) { result = ExtAssociation._ext2UC[extName]; } //foreach (KeyValuePair<string, IUCView> current in ExtAssociation._ext2UC) //{ // bool flag2 = ext.Contains(current.Key); // if (flag2) // { // result = current.Value; // return result; // } //} //result = null; } return(result); }
static ExtAssociation() { //ExtAssociation._ext2UC = new Dictionary<string, IUCView>(); //TODO 改目录,最后都输出到一起 string[] files = Directory.GetFiles(".", "DocScanner.View.dll"); if (files.Length == 0) { //TODO } else { string assemblyFile = files[0]; try { Assembly assembly = Assembly.LoadFrom(assemblyFile); Type[] exportedTypes = assembly.GetExportedTypes(); //TODO 名字定义好 List <Type> types = exportedTypes.Where <Type>(x => x.Name.EndsWith("View")).ToList(); //string fullName = exportedTypes.First(new Func<Type, bool>(o => o.Name.EndsWith("View"))).FullName; foreach (Type type in types) { IUCView iUCView = assembly.CreateInstance(type.FullName) as IUCView; bool flag = iUCView != null; if (flag) { string[] supportTypeExt = iUCView.GetSupportTypeExt(); string[] array2 = supportTypeExt; for (int j = 0; j < array2.Length; j++) { string key = array2[j]; //ExtAssociation._ext2UC[key] = iUCView; _ext2UC.Add(key, iUCView); } } } } catch (Exception ex) { LibCommon.AppContext.GetInstance().MS.LogError(ex.ToString()); } } UCPictureView uCPictureView = new UCPictureView(); string[] supportTypeExt2 = uCPictureView.GetSupportTypeExt(); for (int k = 0; k < supportTypeExt2.Length; k++) { string key2 = supportTypeExt2[k]; //ExtAssociation._ext2UC[key2] = uCPictureView; _ext2UC.Add(key2, uCPictureView); } }
private void SelectCustomView(IUCView uc) { base.SuspendLayout(); bool flag = this._curview != uc; if (flag) { bool flag2 = this._curview != null; if (flag2) { this.panel1.Controls.Remove(this._curview as UserControl); } bool flag3 = uc != null; if (flag3) { this.panel1.Controls.Add(uc as UserControl); (uc as UserControl).Dock = DockStyle.Fill; } this._curview = uc; } base.ResumeLayout(); }