public CapnpType ResolveGenericParameter(CapnpGenericParameter parameter) { var genericOpenType = OpenType as CapnpGenericType; var index = genericOpenType == null ? -2 : Array.IndexOf(genericOpenType.TypeParameters, parameter); if (index < 0) { return(ParentScope == null ? null : ParentScope.ResolveGenericParameter(parameter)); } var result = TypeParameters[index]; if (result is CapnpGenericParameter && ParentScope != null) { return(ParentScope.ResolveGenericParameter((CapnpGenericParameter)result)); } return(result); }
/// <summary> /// Given the generic and its generic parameter bindings, bind for as much as possible any generic parameters in the current /// partially open type. /// </summary> public CapnpBoundGenericType CloseWith(CapnpBoundGenericType generic) { Debug.Assert(!IsFullyClosed); var typeParams = this.TypeParameters.Select(param => param is CapnpGenericParameter ? generic.ResolveGenericParameter((CapnpGenericParameter)param) ?? param : param).ToArray(); return(new CapnpBoundGenericType { OpenType = this.OpenType, ParentScope = this.ParentScope == null ? null : this.ParentScope.CloseWith(generic), TypeParameters = typeParams }); }