public override TypeDeclaration ResolveGenerics(TypeDeclaration[] genericParameters) { var genArgs = GenericParameters; TypeDeclaration[] resolveTypeArgs = new TypeDeclaration[genArgs.Length]; bool changed = false; for (int i = 0; i < genArgs.Length; i++) { resolveTypeArgs[i] = genArgs[i].ResolveGenerics(genericParameters); if (resolveTypeArgs[i] != genArgs[1]) { changed = true; } } if (!changed) { return(this); } GenericPrimitiveType resolveType = new GenericPrimitiveType(Name) { GenericDefinition = GenericDefinition, GenericParameters = resolveTypeArgs }; if (Members != null) { var members = Members; MemberDeclaration[] genMembers = new MemberDeclaration[members.Length]; for (int i = 0; i < members.Length; i++) { genMembers[i] = members[i].ResolveGenerics(genericParameters); genMembers[i].DeclaringType = resolveType; } resolveType.Members = genMembers; } if (Methods != null) { var methods = Methods; FunctionDeclaration[] genMethods = new FunctionDeclaration[methods.Length]; for (int i = 0; i < genMethods.Length; i++) { genMethods[i] = methods[i].ResolveGenerics(genericParameters); genMethods[i].DeclaringType = resolveType; } resolveType.Methods = genMethods; } return(resolveType); }
public override TypeDeclaration ResolveGenerics(TypeDeclaration[] genericParameters) { var genArgs = GenericArguments; if (genArgs.Length != genericParameters.Length) { throw new ArgumentException(); } foreach (var item in GenericTypes) { if (item.Match(genericParameters)) { return(item); } } for (int i = 0; i < genArgs.Length; i++) { if (!genArgs[i].Match(genericParameters[i])) { throw new ArgumentException("genericParameters do not match the generic arguments of the type definition"); } } var genType = new GenericPrimitiveType(Name); if (Members != null) { var members = Members; MemberDeclaration[] genMembers = new MemberDeclaration[members.Length]; for (int i = 0; i < members.Length; i++) { genMembers[i] = members[i].ResolveGenerics(genericParameters); genMembers[i].DeclaringType = genType; } genType.Members = genMembers; } if (Methods != null) { var functions = Methods; FunctionDeclaration[] genFunctions = new FunctionDeclaration[functions.Length]; for (int i = 0; i < functions.Length; i++) { genFunctions[i] = functions[i].ResolveGenerics(genericParameters); } } GenericTypes.Add(genType); return(genType); }