public static MethodOnTypeInstantiation Create(TypeInstantiation declaringType = null, MethodInfo method = null) { declaringType = declaringType ?? TypeInstantiationObjectMother.Create(); method = method ?? ReflectionObjectMother.GetSomeMethod(); return(new MethodOnTypeInstantiation(declaringType, method)); }
public void SetUp() { _genericTypeDefinition = typeof(DeclaringType <> .GenericType <>); _outerCustomType = CustomTypeObjectMother.Create(); _customType = CustomTypeObjectMother.Create(); _typeArguments = new Type[] { _outerCustomType, _customType }; _instantiationInfo = new TypeInstantiationInfo(_genericTypeDefinition, _typeArguments); _instantiation = new TypeInstantiation(_instantiationInfo, new TypeInstantiationContext()); }
public void SetUp() { _declaringType = TypeInstantiationObjectMother.Create(); _originalEvent = GetType().GetEvent("Event"); _addMethod = MethodOnTypeInstantiationObjectMother.Create(_declaringType, GetType().GetMethod("add_Event")); _removeMethod = MethodOnTypeInstantiationObjectMother.Create(_declaringType, GetType().GetMethod("remove_Event")); _raiseMethod = MethodOnTypeInstantiationObjectMother.Create(_declaringType, GetType().GetMethod("RaiseMethod")); _event = new EventOnTypeInstantiation(_declaringType, _originalEvent, _addMethod, _removeMethod, _raiseMethod); }
private Type GetEmittableTypeInstantiation(TypeInstantiation typeInstantiation) { var genericTypeDefinition = typeInstantiation.GetGenericTypeDefinition(); var emittableTypeArguments = typeInstantiation.GetGenericArguments().Select(GetEmittableType).ToArray(); Assertion.IsNotNull(genericTypeDefinition); // Should *not* be MakeTypePipeGenericType. return(genericTypeDefinition.MakeGenericType(emittableTypeArguments)); }
public void Initialization_ReadOnlyAndWriteOnlyProperty() { var info1 = new TypeInstantiationInfo(typeof(GenericTypeWithProperties <>), new Type[] { _customType }); var instantiation = new TypeInstantiation(info1, new TypeInstantiationContext()); var property1 = instantiation.GetProperty("ReadOnlyProperty"); var property2 = instantiation.GetProperty("WriteOnlyProperty"); Assert.That(property1.GetSetMethod(true), Is.Null); Assert.That(property2.GetGetMethod(true), Is.Null); }
public void SetUp() { _indexParameter = CustomParameterInfoObjectMother.Create(); _declaringType = TypeInstantiationObjectMother.Create(); _getMethod = MethodOnTypeInstantiationObjectMother.Create(_declaringType, typeof(GenericType <>).GetMethod("get_Item")); _setMethod = MethodOnTypeInstantiationObjectMother.Create(_declaringType, typeof(GenericType <>).GetMethod("set_Item")); _originalProperty = CustomPropertyInfoObjectMother.Create( indexParameters: new[] { _indexParameter }, getMethod: _getMethod, setMethod: _setMethod); _property = new PropertyOnTypeInstantiation(_declaringType, _originalProperty, _getMethod, _setMethod); }
public void SetUp() { _typeArgument = ReflectionObjectMother.GetSomeType(); var genericTypeDefinition = typeof(GenericType <>); _genericTypeParameter = genericTypeDefinition.GetGenericArguments().Single(); _declaringType = TypeInstantiationObjectMother.Create(genericTypeDefinition, new[] { _typeArgument }); _memberOnTypeInstantiation = MethodOnTypeInstantiationObjectMother.Create(_declaringType); var genericMethodDefinition = NormalizingMemberInfoFromExpressionUtility.GetGenericMethodDefinition(() => GenericMethod <Dev.T>()); _genericMethodParameter = genericMethodDefinition.GetGenericArguments().Single(); _methodInstantiation = MethodInstantiationObjectMother.Create(genericMethodDefinition, typeArguments: new[] { _typeArgument }); }
public void IntegrationOfInitializationAndSubstitution_RecursiveGenericInBaseType() { var genericRuntimeType = typeof(RecursiveGenericType <int>); var genericBaseRuntimeType = typeof(BaseType <RecursiveGenericType <int> >); Assert.That(genericRuntimeType, Is.SameAs(genericBaseRuntimeType.GetGenericArguments().Single()), "Assert original reflection behavior."); var genericTypeDefinition = typeof(RecursiveGenericType <>); var typeArguments = new Type[] { _customType }; var info = new TypeInstantiationInfo(genericTypeDefinition, typeArguments); var instantiation = new TypeInstantiation(info, new TypeInstantiationContext()); Assertion.IsNotNull(instantiation.BaseType); Assert.That(instantiation, Is.SameAs(instantiation.BaseType.GetGenericArguments().Single())); }
public void Equals_Object() { var info1 = new TypeInstantiationInfo(_genericTypeDefinition, _typeArguments.Reverse()); var info2 = new TypeInstantiationInfo(_genericTypeDefinition, _typeArguments); Assert.That(info1, Is.Not.EqualTo(_instantiationInfo)); Assert.That(info2, Is.EqualTo(_instantiationInfo)); var instantiation1 = new TypeInstantiation(info1, new TypeInstantiationContext()); var instantiation2 = new TypeInstantiation(info2, new TypeInstantiationContext()); Assert.That(_instantiation.Equals((object)null), Is.False); Assert.That(_instantiation.Equals(new object()), Is.False); Assert.That(_instantiation.Equals((object)instantiation1), Is.False); Assert.That(_instantiation.Equals((object)instantiation2), Is.True); }
public void Initialization_MemberInitializationIsLazy_AndUsesAllBindingFlagsToRetrieveMembers() { var bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; var nestedTypes = _genericTypeDefinition.GetNestedTypes(bindingFlags); var fields = _genericTypeDefinition.GetFields(bindingFlags); var ctors = _genericTypeDefinition.GetConstructors(bindingFlags); var methods = _genericTypeDefinition.GetMethods(bindingFlags); var properties = _genericTypeDefinition.GetProperties(bindingFlags); var events = _genericTypeDefinition.GetEvents(bindingFlags); var memberSelectorMock = new Mock <IMemberSelector> (MockBehavior.Strict); var typeParameters = new[] { ReflectionObjectMother.GetSomeType() }; var genericTypeDefinition = CustomTypeObjectMother.Create(memberSelectorMock.Object, typeArguments: typeParameters, nestedTypes: nestedTypes, fields: fields, constructors: ctors, methods: methods, properties: properties, events: events); // TODO 5816 //memberSelectorMock.Setup (mock => mock.SelectTypes (nestedTypes, bindingFlags)).Returns (nestedTypes); memberSelectorMock.Setup(mock => mock.SelectFields(fields, bindingFlags, genericTypeDefinition)).Returns(fields).Verifiable(); memberSelectorMock.Setup(mock => mock.SelectMethods(ctors, bindingFlags, genericTypeDefinition)).Returns(ctors).Verifiable(); // Note: GetMethods is optimized for retrieving all the methods; so there is no memberSelectorMock call. memberSelectorMock.Setup(mock => mock.SelectProperties(properties, bindingFlags, genericTypeDefinition)).Returns(properties).Verifiable(); memberSelectorMock.Setup(mock => mock.SelectEvents(events, bindingFlags, genericTypeDefinition)).Returns(events).Verifiable(); var typeArguments = new[] { ReflectionObjectMother.GetSomeType() }; var info = new TypeInstantiationInfo(genericTypeDefinition, typeArguments); var typeInstantiation = new TypeInstantiation(info, new TypeInstantiationContext()); // Evaluation is lazy. memberSelectorMock.Verify(mock => mock.SelectTypes(nestedTypes, bindingFlags), Times.Never()); memberSelectorMock.Verify(mock => mock.SelectFields(fields, bindingFlags, genericTypeDefinition), Times.Never()); memberSelectorMock.Verify(mock => mock.SelectMethods(ctors, bindingFlags, genericTypeDefinition), Times.Never()); // Note: GetMethods is optimized for retrieving all the methods; so there is no memberSelectorMock call. memberSelectorMock.Verify(mock => mock.SelectProperties(properties, bindingFlags, genericTypeDefinition), Times.Never()); memberSelectorMock.Verify(mock => mock.SelectEvents(events, bindingFlags, genericTypeDefinition), Times.Never()); // Trigger instantiation. // TODO 5816 //Dev.Null = typeInstantiation.GetNestedTypes(); Dev.Null = typeInstantiation.GetFields(); Dev.Null = typeInstantiation.GetConstructors(); Dev.Null = typeInstantiation.GetMethods(); Dev.Null = typeInstantiation.GetProperties(); Dev.Null = typeInstantiation.GetEvents(); memberSelectorMock.Verify(); }
public void Equals_Type() { var info1 = new TypeInstantiationInfo(_genericTypeDefinition, _typeArguments.Reverse()); var info2 = new TypeInstantiationInfo(_genericTypeDefinition, _typeArguments); Assert.That(info1, Is.Not.EqualTo(_instantiationInfo)); Assert.That(info2, Is.EqualTo(_instantiationInfo)); var instantiation1 = new TypeInstantiation(info1, new TypeInstantiationContext()); var instantiation2 = new TypeInstantiation(info2, new TypeInstantiationContext()); // ReSharper disable CheckForReferenceEqualityInstead.1 Assert.That(_instantiation.Equals(null), Is.False); // ReSharper restore CheckForReferenceEqualityInstead.1 Assert.That(_instantiation.Equals(instantiation1), Is.False); Assert.That(_instantiation.Equals(instantiation2), Is.True); }
public static TypeInstantiation Create( Type genericTypeDefinition = null, IEnumerable <Type> typeArguments = null, TypeInstantiationContext instantiationContext = null, IMemberSelector memberSelector = null) { genericTypeDefinition = genericTypeDefinition ?? typeof(MyGenericType <>); typeArguments = typeArguments ?? genericTypeDefinition.GetGenericArguments().Select(a => ReflectionObjectMother.GetSomeType()); var instantiationInfo = new TypeInstantiationInfo(genericTypeDefinition, typeArguments); instantiationContext = instantiationContext ?? new TypeInstantiationContext(); memberSelector = memberSelector ?? new MemberSelector(new BindingFlagsEvaluator()); var typeInstantiation = new TypeInstantiation(instantiationInfo, instantiationContext); typeInstantiation.SetMemberSelector(memberSelector); return(typeInstantiation); }
public void SetUp() { _declaringType = TypeInstantiationObjectMother.Create(); }
public void SetUp() { _typeParameter = typeof(GenericType <>).GetGenericArguments().Single(); _typeArgument = ReflectionObjectMother.GetSomeType(); _declaringType = TypeInstantiationObjectMother.Create(typeof(GenericType <>), new[] { _typeArgument }); }