public IEntity ConstructEntity(Node constructionNode, IEntity definition, IType[] typeArguments)
{
// Ensure definition is a valid entity
if (definition == null || TypeSystemServices.IsError(definition))
{
return TypeSystemServices.ErrorEntity;
}
// Ambiguous generic constructions are handled separately
if (definition.EntityType == EntityType.Ambiguous)
{
return ConstructAmbiguousEntity(constructionNode, (Ambiguous)definition, typeArguments);
}
// Check that the construction is valid
if (!CheckGenericConstruction(constructionNode, definition, typeArguments, Errors))
{
return TypeSystemServices.ErrorEntity;
}
// Construct a type or a method according to the definition
if (IsGenericType(definition))
{
return ((IType)definition).GenericInfo.ConstructType(typeArguments);
}
if (IsGenericMethod(definition))
{
return ((IMethod)definition).GenericInfo.ConstructMethod(typeArguments);
}
// Should never be reached - if definition is neither a generic type nor a generic method,
// CheckGenericConstruction would've indicated this
return TypeSystemServices.ErrorEntity;
}