private bool AreCompatible(GenericParameterDescriptor oldParameter, GenericParameterDescriptor newParameter) { return(((newParameter.New && oldParameter.New) || !newParameter.New) && ((newParameter.Class && oldParameter.Class) || !newParameter.Class) && ((newParameter.Struct && oldParameter.Struct) || !newParameter.Struct) && newParameter.BaseTypeOrInterfaces.Count == oldParameter.BaseTypeOrInterfaces.Count && newParameter.BaseTypeOrInterfaces.All(btoi => oldParameter.BaseTypeOrInterfaces.Contains(btoi))); }
private static IEnumerable <GenericParameterDescriptor> GetGenericConstraintsFor(TypeInfo[] genericArguments) { foreach (var typeArgument in genericArguments) { var constraintDescriptor = new GenericParameterDescriptor { Source = typeArgument }; if (typeArgument.IsGenericParameter) { if (typeArgument.BaseType != null && typeArgument.BaseType != typeof(object) && typeArgument.BaseType != typeof(ValueType)) { constraintDescriptor.BaseTypeOrInterfaces.Add(TypeDescriptor.GetTypeNameFor(typeArgument.BaseType.GetTypeInfo())); } foreach (var interfaceType in TypeDescriptor.GetImplementedInterfacesFor(typeArgument)) { constraintDescriptor.BaseTypeOrInterfaces.Add(TypeDescriptor.GetTypeNameFor(interfaceType)); } constraintDescriptor.ParameterName = typeArgument.Name; constraintDescriptor.ParameterPosition = typeArgument.GenericParameterPosition; constraintDescriptor.New = (typeArgument.GenericParameterAttributes & GenericParameterAttributes.DefaultConstructorConstraint) == GenericParameterAttributes.DefaultConstructorConstraint; constraintDescriptor.Class = (typeArgument.GenericParameterAttributes & GenericParameterAttributes.ReferenceTypeConstraint) == GenericParameterAttributes.ReferenceTypeConstraint; constraintDescriptor.Struct = (typeArgument.GenericParameterAttributes & GenericParameterAttributes.NotNullableValueTypeConstraint) == GenericParameterAttributes.NotNullableValueTypeConstraint; } else { constraintDescriptor.ParameterName = TypeDescriptor.GetTypeNameFor(typeArgument); } yield return(constraintDescriptor); } }