public static MutableFieldInfo Create( MutableType declaringType = null, string name = "_newField", Type type = null, FieldAttributes attributes = (FieldAttributes)7) { declaringType = declaringType ?? MutableTypeObjectMother.Create(); type = type ?? ReflectionObjectMother.GetSomeType(); return(new MutableFieldInfo(declaringType, name, type, attributes)); }
public static MutablePropertyInfo CreateReadWrite( MutableType declaringType = null, string name = "UnspecifiedProperty", PropertyAttributes attributes = PropertyAttributes.None, Type type = null) { declaringType = declaringType ?? MutableTypeObjectMother.Create(); type = type ?? ReflectionObjectMother.GetSomeType(); var getMethod = MutableMethodInfoObjectMother.Create(returnType: type); var setMethod = MutableMethodInfoObjectMother.Create(parameters: new[] { ParameterDeclarationObjectMother.Create(type) }); return(new MutablePropertyInfo(declaringType, name, attributes, getMethod, setMethod)); }
public static MutableEventInfo Create( MutableType declaringType = null, string name = "UnspecifiedEvent", EventAttributes attributes = EventAttributes.None, MutableMethodInfo addMethod = null, MutableMethodInfo removeMethod = null, MutableMethodInfo raiseMethod = null) { Assertion.IsTrue(addMethod != null && removeMethod != null); declaringType = declaringType ?? MutableTypeObjectMother.Create(); return(new MutableEventInfo(declaringType, name, attributes, addMethod, removeMethod, raiseMethod)); }
public static MutableConstructorInfo Create( MutableType declaringType = null, MethodAttributes attributes = (MethodAttributes)7, IEnumerable <ParameterDeclaration> parameters = null, Expression body = null) { declaringType = declaringType ?? MutableTypeObjectMother.Create(); attributes |= MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; parameters = parameters ?? ParameterDeclaration.None; body = body ?? Expression.Empty(); return(new MutableConstructorInfo(declaringType, attributes, parameters, body)); }
public static MutablePropertyInfo Create( MutableType declaringType = null, string name = "UnspecifiedProperty", PropertyAttributes attributes = PropertyAttributes.None, MutableMethodInfo getMethod = null, MutableMethodInfo setMethod = null) { declaringType = declaringType ?? MutableTypeObjectMother.Create(); if (getMethod == null && setMethod == null) { getMethod = MutableMethodInfoObjectMother.Create(declaringType, "Getter", returnType: typeof(int)); } return(new MutablePropertyInfo(declaringType, name, attributes, getMethod, setMethod)); }
public static MutableEventInfo CreateWithAccessors( MutableType declaringType = null, string name = "UnspecifiedEvent", EventAttributes attributes = EventAttributes.None, Type handlerType = null, bool createRaiseMethod = false) { declaringType = declaringType ?? MutableTypeObjectMother.Create(); handlerType = handlerType ?? typeof(Func <,>).MakeGenericType(ReflectionObjectMother.GetSomeType(), ReflectionObjectMother.GetSomeOtherType()); Assertion.IsTrue(handlerType.IsSubclassOf(typeof(Delegate))); var invokeMethod = handlerType.GetMethod("Invoke", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var raiseParameterTypes = invokeMethod.GetParameters().Select(p => p.ParameterType).ToArray(); var addRemoveParameterTypes = new[] { handlerType }; var addMethod = CreateMethod(declaringType, "Adder", addRemoveParameterTypes); var removeMethod = CreateMethod(declaringType, "Remover", addRemoveParameterTypes); var raiseMethod = createRaiseMethod ? CreateMethod(declaringType, "Raiser", raiseParameterTypes, invokeMethod.ReturnType) : null; return(new MutableEventInfo(declaringType, name, attributes, addMethod, removeMethod, raiseMethod)); }
public static MutableMethodInfo Create( MutableType declaringType = null, string name = "UnspecifiedMethod", MethodAttributes attributes = (MethodAttributes)7, Type returnType = null, IEnumerable <ParameterDeclaration> parameters = null, MethodInfo baseMethod = null, Expression body = null, IEnumerable <MutableGenericParameter> genericParameters = null) { declaringType = declaringType ?? MutableTypeObjectMother.Create(); if (baseMethod != null) { attributes = attributes.Set(MethodAttributes.Virtual); } returnType = returnType ?? typeof(void); parameters = parameters ?? ParameterDeclaration.None; // baseMethod stays null. body = body == null && !attributes.IsSet(MethodAttributes.Abstract) ? ExpressionTreeObjectMother.GetSomeExpression(returnType) : body; var genericParas = (genericParameters ?? new MutableGenericParameter[0]).ToList(); return(new MutableMethodInfo(declaringType, name, attributes, genericParas, returnType, parameters, baseMethod, body)); }