public IGcl SearchGCL(Type type) { foreach (var igcl in GenericCreatedTypes) { if (igcl.ForType == type) { return(igcl); } } /* 实现和包装在同一个项目里导致找不到正确的GCL */ List <IGcl> gcls = new List <IGcl>(); foreach (var igcls in importPackages.Values.ToList()) { foreach (var igcl in igcls) { if (igcl.ForType == type) { //return igcl; gcls.Add(igcl); } } if (gcls.Count > 0) { break; } } if (gcls.Count > 0) { foreach (var gcl in gcls) { if (!(gcl is ExternalGcl)) { return(gcl); } } foreach (var gcl in gcls) { return(gcl); } } if (type.IsGenericType) { Type baseGenericType = type.GetGenericTypeDefinition(); IGcl baseGCL = SearchGCL(baseGenericType); if (baseGCL == null) { return(null); } IGcl newGCL = baseGCL.CreateNewFor(type); this.GenericCreatedTypes.Add(newGCL); return(newGCL); } return(null); }
public IGcl Analy(string name) { var array = context.SearchGCL(name); if (array.Length == 1) { IGcl gcl0 = array[0]; int genericArgCount = GenericUtil.GetGenericTypeArgCount(gcl0.ForType); if (genericArgCount == 0) { return(gcl0); } else if (genericArgCount == 1) { Type newType = gcl0.ForType.MakeGenericType(new Type[] { typeof(object) }); IGcl result = gcl0.CreateNewFor(newType); return(result); } else if (genericArgCount == 2) { Type newType = gcl0.ForType.MakeGenericType(new Type[] { typeof(object), typeof(object) }); IGcl result = gcl0.CreateNewFor(newType); return(result); } else { return(null); } } else if (array.Length > 1) { return(null); } List <IGcl> glist = FindGenericEndwith(name); if (glist.Count == 0) { return(null); } foreach (IGcl mpClass in glist) { int genericArgCount = GenericUtil.GetGenericTypeArgCount(mpClass.ForType); string typeName = mpClass.ShowName; string gtypeName = name.Substring(0, name.Length - typeName.Length); if (genericArgCount == 1) { var gcls = context.SearchGCLFromImport(gtypeName);//searchTypeSymbol(gtypeName); if (gcls.Length == 1) { Type newType = mpClass.ForType.MakeGenericType(new Type[] { gcls[0].ForType }); IGcl result = mpClass.CreateNewFor(newType); return(result); } } else if (genericArgCount == 2) { List <IGcl> nlist = FindImportEndwith(gtypeName); if (nlist.Count == 0) { return(null); } foreach (var nClass in nlist) { string ntypeName = nClass.ShowName; string ngtypeName = gtypeName.Substring(0, gtypeName.Length - ntypeName.Length); //string ngtypeName = gtypeName.Substring(0, name.Length - ntypeName.Length); //ITypeSymbol ntypeSymbol = searchTypeSymbol(ngtypeName); var gcls = context.SearchGCLFromImport(ngtypeName); //var gcls = context.SearchGCLFromImport(gtypeName); if (gcls.Length == 1) { var gcl0 = gcls[0]; Type newType = mpClass.ForType.MakeGenericType(new Type[] { gcl0.ForType, nClass.ForType }); IGcl result = mpClass.CreateNewFor(newType); //gcl0.CreateNewFor(newType); return(result); } } } } return(null); }