/// <summary> /// Retrieve/build typed copies of generic types /// </summary> private ClassModel ResolveGenericType(string baseType, string indexType, FileModel inFile) { ClassModel originalClass = base.ResolveType(baseType, inFile); if (originalClass.IsVoid()) { return(originalClass); } ClassModel indexClass = ResolveType(indexType, inFile); if (indexClass.IsVoid()) { return(originalClass); } indexType = indexClass.QualifiedName; FileModel aFile = originalClass.InFile; // is the type already cloned? foreach (ClassModel otherClass in aFile.Classes) { if (otherClass.IndexType == indexType) { return(otherClass); } } // clone the type ClassModel aClass = originalClass.Clone() as ClassModel; aClass.Name = baseType + ".<" + indexType + ">"; aClass.IndexType = indexType; string typed = "<" + indexType + ">"; foreach (MemberModel member in aClass.Members) { if (member.Name == baseType) { member.Name = baseType.Replace("<T>", typed); } if (member.Type != null && member.Type.IndexOf('T') >= 0) { if (member.Type == "T") { member.Type = indexType; } else { member.Type = member.Type.Replace("<T>", typed); } } if (member.Parameters != null) { foreach (MemberModel param in member.Parameters) { if (param.Type != null && param.Type.IndexOf('T') >= 0) { if (param.Type == "T") { param.Type = indexType; } else { param.Type = param.Type.Replace("<T>", typed); } } } } } aFile.Classes.Add(aClass); return(aClass); }
/// <summary> /// Retrieve/build typed copies of generic types /// </summary> private ClassModel ResolveGenericType(string baseType, string indexType, FileModel inFile) { ClassModel aClass = base.ResolveType(baseType, inFile); if (aClass.IsVoid()) { return(aClass); } FileModel aFile = aClass.InFile; // is the type already cloned? foreach (ClassModel otherClass in aFile.Classes) { if (otherClass.IndexType == indexType) { return(otherClass); } } // clone the type aClass = aClass.Clone() as ClassModel; aClass.Name = baseType.Substring(baseType.LastIndexOf('.') + 1) + "#" + indexType; aClass.IndexType = indexType; string typed = "<" + indexType + ">"; foreach (MemberModel member in aClass.Members) { if (member.Name == baseType) { member.Name = baseType.Replace("<T>", typed); } if (member.Type != null && member.Type.IndexOf('T') >= 0) { if (member.Type == "T") { member.Type = indexType; } else { member.Type = member.Type.Replace("<T>", typed); } } if (member.Parameters != null) { foreach (MemberModel param in member.Parameters) { if (param.Type != null && param.Type.IndexOf('T') >= 0) { if (param.Type == "T") { param.Type = indexType; } else { param.Type = param.Type.Replace("<T>", typed); if (param.Type.IndexOf('-') > 0) { param.Type = Regex.Replace(param.Type, "T\\s?->", indexType + " ->"); param.Type = Regex.Replace(param.Type, "->\\s?T", "-> " + indexType); } } } } } } aFile.Classes.Add(aClass); return(aClass); }