public BoundTypeDefinitionMask_I Resolve(RuntimicSystemModel model, SemanticTypeDefinitionMask_I declaringType, GenericParameter parameter) { if (!declaringType.IsGeneric()) { throw new Exception("Expected the resolved semantic type to be a generic type."); } SemanticGenericTypeDefinitionMask_I generic = (SemanticGenericTypeDefinitionMask_I)declaringType; if (!generic.TypeParameters.ByName.TryGetValue(parameter.Name, out SemanticGenericParameterTypeDefinitionMask_I semanticTypeParameter)) { throw new Exception($"Expected the generic type to have a type parameter named {parameter.Name}."); } if (!semanticTypeParameter.IsBound()) { throw new Exception("Expected the generic parameter type to be a bound type."); } return((BoundTypeDefinitionMask_I)semanticTypeParameter); }
public SemanticTypeDefinitionMask_I Ensure(ILConversion conversion, GenericParameter parameter) { if (parameter.DeclaringType != null) { var resolutionName = Types.Naming.GetResolutionName(parameter.DeclaringType); var semanticType = Models.Types.GetOrThrow(conversion.RuntimicSystem, resolutionName); if (!semanticType.IsGeneric()) { throw new Exception("Expected the resolved semantic type to be a generic type."); } SemanticGenericTypeDefinitionMask_I generic = (SemanticGenericTypeDefinitionMask_I)semanticType; if (!generic.TypeParameters.ByName.TryGetValue(parameter.Name, out SemanticGenericParameterTypeDefinitionMask_I semanticTypeParameter)) { throw new Exception($"Expected the generic type to have a type parameter named {parameter.Name}."); } if (!semanticTypeParameter.IsBound()) { throw new Exception("Expected the generic parameter type to be a bound type."); } return((BoundTypeDefinitionMask_I)semanticTypeParameter); } else { if (!(parameter.DeclaringMethod is MethodDefinition methodDefinition)) { throw new Exception("Expected a method definition"); } var declaringType = methodDefinition.DeclaringType; var resolutionName = Types.Naming.GetResolutionName(declaringType); var semanticType = Models.Types.GetOrThrow(conversion.RuntimicSystem, resolutionName); if (!(semanticType is BoundTypeDefinitionWithMethodsMask_I convertedTypeWithMethods)) { throw new Exception("Trying to add a method to a type that does not support methods."); } var method = Bound.Metadata.Members.Methods.Getting.FindMethodByDefinition(conversion.RuntimicSystem, convertedTypeWithMethods, methodDefinition); if (!method.TypeParameters.ByName.TryGetValue(parameter.Name, out SemanticGenericParameterTypeDefinitionMask_I semanticTypeParameter)) { throw new Exception($"Expected the generic method to have a type parameter named {parameter.Name}."); } if (!semanticTypeParameter.IsBound()) { throw new Exception("Expected the generic parameter type to be a bound type."); } return((BoundTypeDefinitionMask_I)semanticTypeParameter); } }