public static GetGenericParameters ( IEntity definition ) : IGenericParameter[] | ||
definition | IEntity | |
리턴 | IGenericParameter[] |
/// <summary> /// Maps a type involving generic parameters to the corresponding type after substituting concrete /// arguments for generic parameters. /// </summary> /// <remarks> /// If the source type is a generic parameter, it is mapped to the corresponding argument. /// If the source type is an open generic type using any of the specified generic parameters, it /// is mapped to a closed constructed type based on the specified arguments. /// </remarks> override public IType MapType(IType sourceType) { if (sourceType == _genericSource) { return(_constructedOwner as IType); } IGenericParameter gp = sourceType as IGenericParameter; if (gp != null) { // Map type parameters declared on our source if (_map.ContainsKey(gp)) { return(_map[gp]); } // Map type parameters declared on members of our source (methods / nested types) return(GenericsServices.GetGenericParameters(Map(gp.DeclaringEntity))[gp.GenericParameterPosition]); } // TODO: Map nested types // GenericType[of T].NestedType => GenericType[of int].NestedType return(base.MapType(sourceType)); }
private bool HasCorrectGenerity(IEntity definition) { IGenericParameter[] typeParameters = GenericsServices.GetGenericParameters(definition); if (typeParameters.Length != TypeArguments.Length) { Errors.Add(CompilerErrorFactory.GenericDefinitionArgumentCount(ConstructionNode, definition, typeParameters.Length)); return(false); } return(true); }
private bool MaintainsParameterConstraints(IEntity definition) { IGenericParameter[] parameters = GenericsServices.GetGenericParameters(definition); _definition = definition as IType; bool valid = true; for (int i = 0; i < parameters.Length; i++) { valid &= MaintainsParameterConstraints(parameters[i], TypeArguments[i]); } return(valid); }
private bool HasCorrectGenerity(IEntity definition) { IGenericParameter[] typeParameters = GenericsServices.GetGenericParameters(definition); if (typeParameters.Length != TypeArguments.Length) { var error = CompilerErrorFactory.GenericDefinitionArgumentCount(ConstructionNode, definition, typeParameters.Length); var internalType = definition as IInternalEntity; if (internalType != null) { var node = internalType.Node; var replacementNode = node["TypeRefReplacement"] as GenericReferenceExpression; if (replacementNode != null && replacementNode.GenericArguments.Count == typeParameters.Length) { error.Data["TypeRefReplacement"] = replacementNode.CloneNode(); throw error; } } Errors.Add(error); return(false); } return(true); }