/// <inheritdoc /> public bool Equals(TypeSignature x, TypeSignature y) { if (ReferenceEquals(x, y)) { return(true); } if (ReferenceEquals(x, null) || ReferenceEquals(y, null)) { return(false); } return(x switch { CorLibTypeSignature corLibType => Equals(corLibType, y as CorLibTypeSignature), TypeDefOrRefSignature typeDefOrRef => Equals(typeDefOrRef, y as TypeDefOrRefSignature), SzArrayTypeSignature szArrayType => Equals(szArrayType, y as SzArrayTypeSignature), ArrayTypeSignature arrayType => Equals(arrayType, y as ArrayTypeSignature), ByReferenceTypeSignature byRefType => Equals(byRefType, y as ByReferenceTypeSignature), BoxedTypeSignature boxedType => Equals(boxedType, y as BoxedTypeSignature), GenericInstanceTypeSignature genericInstanceType => Equals(genericInstanceType, y as GenericInstanceTypeSignature), GenericParameterSignature genericParameter => Equals(genericParameter, y as GenericParameterSignature), PointerTypeSignature pointerType => Equals(pointerType, y as PointerTypeSignature), PinnedTypeSignature pinnedType => Equals(pinnedType, y as PinnedTypeSignature), CustomModifierTypeSignature modifierType => Equals(modifierType, y as CustomModifierTypeSignature), _ => throw new NotSupportedException() });
public void ResolveGenericParameterWithEmptyTypeShouldThrow(GenericParameterType parameterType) { var context = new GenericContext(); var parameter = new GenericParameterSignature(parameterType, 0); Assert.Throws <ArgumentOutOfRangeException>(() => context.GetTypeArgument(parameter)); }
public void InstantiateMethodGenericParameter() { var signature = new GenericParameterSignature(GenericParameterType.Method, 0); var context = new GenericContext(null, GetProvider(_module.CorLibTypeFactory.String)); var newSignature = signature.InstantiateGenericTypes(context); Assert.Equal(_module.CorLibTypeFactory.String, newSignature, Comparer); }
public void ResolveTypeGenericParameterWithOnlyMethodShouldThrow() { var genericInstance = new GenericInstanceMethodSignature(); genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); var context = new GenericContext(null, genericInstance); var parameter = new GenericParameterSignature(GenericParameterType.Type, 0); Assert.Throws <ArgumentOutOfRangeException>(() => context.GetTypeArgument(parameter)); }
public void ResolveTypeGenericParameterWithType() { var genericInstance = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List <>)), false); genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); var context = new GenericContext(genericInstance, null); var parameter = new GenericParameterSignature(GenericParameterType.Type, 0); Assert.Equal("System.String", context.GetTypeArgument(parameter).FullName); }
public void ResolveMethodGenericParameterWithMethod() { var genericInstance = new GenericInstanceMethodSignature(); genericInstance.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); var context = new GenericContext(null, genericInstance); var parameter = new GenericParameterSignature(GenericParameterType.Method, 0); Assert.Equal("System.String", context.GetTypeArgument(parameter).FullName); }
/// <summary> /// Determines whether two types are considered equal according to their signature. /// </summary> /// <param name="signature1">The first type to compare.</param> /// <param name="signature2">The second type to compare.</param> /// <returns><c>True</c> if the types are considered equal, <c>False</c> otherwise.</returns> public bool Equals(GenericParameterSignature signature1, GenericParameterSignature signature2) { if (signature1 == null && signature2 == null) { return(true); } if (signature1 == null || signature2 == null) { return(false); } return(signature1.Index == signature2.Index && signature1.ElementType == signature2.ElementType); }
/// <inheritdoc /> public bool Equals(GenericParameterSignature x, GenericParameterSignature y) { if (ReferenceEquals(x, y)) { return(true); } if (x is null || y is null) { return(false); } return(x.Index == y.Index && x.ParameterType == y.ParameterType); }
public void ArrayType(GenericParameterType parameterType, int index) { // 0![0..10] var genericParameter = new GenericParameterSignature(parameterType, index); var signature = new ArrayTypeSignature(genericParameter) { Dimensions = { new ArrayDimension(10, 0) } }; Assert.Equal(new ArrayTypeSignature(GetTypeArguments(parameterType)[index]) { Dimensions = { new ArrayDimension(10, 0) } }, signature.InstantiateGenericTypes(_context), Comparer); }
public void ResolveMethodGenericParameterWithTypeAndMethod() { var genericType = new GenericInstanceTypeSignature(_importer.ImportType(typeof(List <>)), false); genericType.TypeArguments.Add(_importer.ImportTypeSignature(typeof(string))); var genericMethod = new GenericInstanceMethodSignature(); genericMethod.TypeArguments.Add(_importer.ImportTypeSignature(typeof(int))); var context = new GenericContext(genericType, genericMethod); var parameter = new GenericParameterSignature(GenericParameterType.Method, 0); Assert.Equal("System.Int32", context.GetTypeArgument(parameter).FullName); }
/// <summary> /// Resolves a type parameter to a type argument, based on the current generic context. /// </summary> /// <param name="parameter">The parameter to get the argument value for.</param> /// <returns>The argument type.</returns> public TypeSignature GetTypeArgument(GenericParameterSignature parameter) { var argumentProvider = parameter.ParameterType switch { GenericParameterType.Type => Type, GenericParameterType.Method => Method, _ => throw new ArgumentOutOfRangeException() }; if (argumentProvider is null) { throw new ArgumentOutOfRangeException(); } if (parameter.Index >= 0 && parameter.Index < argumentProvider.TypeArguments.Count) { return(argumentProvider.TypeArguments[parameter.Index]); } throw new ArgumentOutOfRangeException(); } }
private GenericParameterSignature ImportGenericParameterSignature(GenericParameterSignature genericParameter) { return(new GenericParameterSignature(genericParameter.ParameterType, genericParameter.Index)); }
/// <inheritdoc /> public int GetHashCode(GenericParameterSignature obj) => (int)obj.ElementType << ElementTypeOffset | obj.Index;
public void GenericParameterSignatureMethod(int index) { var genericParam = new GenericParameterSignature(GenericParameterType.Type, index); Assert.Equal(_typeArgs[index], genericParam.InstantiateGenericTypes(_context), Comparer); }
/// <inheritdoc /> public object VisitGenericParameter(GenericParameterSignature signature) => throw new NotSupportedException();
/// <inheritdoc /> public TypeMemoryLayout VisitGenericParameter(GenericParameterSignature signature) => _currentGenericContext.GetTypeArgument(signature).AcceptVisitor(this);