public static CustomMethodInfo Create(
            CustomType declaringType = null,
            string name = "CustomMethod",
            MethodAttributes attributes            = (MethodAttributes)7,
            ParameterInfo returnParameter          = null,
            IEnumerable <ParameterInfo> parameters = null,
            MethodInfo baseDefinition = null,
            IEnumerable <ICustomAttributeData> customAttributes = null,
            MethodInfo genericMethodDefintion = null,
            IEnumerable <Type> typeArguments  = null)
        {
            declaringType   = declaringType ?? CustomTypeObjectMother.Create();
            returnParameter = returnParameter ?? CustomParameterInfoObjectMother.Create(position: -1, type: typeof(void));
            parameters      = parameters ?? new ParameterInfo[0];
            // Base definition stays null.
            customAttributes = customAttributes ?? new ICustomAttributeData[0];
            // Generic method definition stays null.
            var typeArgs = (typeArguments ?? Type.EmptyTypes).ToList();

            return(new TestableCustomMethodInfo(declaringType, name, attributes, genericMethodDefintion, typeArgs)
            {
                ReturnParameter_ = returnParameter,
                Parameters = parameters.ToArray(),
                BaseDefinition = baseDefinition,
                CustomAttributeDatas = customAttributes.ToArray()
            });
        }
Ejemplo n.º 2
0
        public static CustomPropertyInfo Create(
            CustomType declaringType = null,
            string name = "UnspecifiedProperty",
            PropertyAttributes attributes = (PropertyAttributes)7,
            IEnumerable <ICustomAttributeData> customAttributes = null,
            CustomMethodInfo getMethod      = null,
            CustomMethodInfo setMethod      = null,
            ParameterInfo[] indexParameters = null)
        {
            declaringType    = declaringType ?? CustomTypeObjectMother.Create();
            customAttributes = customAttributes ?? new ICustomAttributeData[0];
            // Getter stays null.
            // Setters stays null, but if both are null then create a getter.
            if (getMethod == null && setMethod == null)
            {
                getMethod = CustomMethodInfoObjectMother.Create(returnParameter: CustomParameterInfoObjectMother.Create(position: -1, type: typeof(int)));
            }
            indexParameters = indexParameters ?? new ParameterInfo[0];

            return(new TestableCustomPropertyInfo(declaringType, name, attributes, getMethod, setMethod)
            {
                CustomAttributeDatas = customAttributes,
                IndexParameters = indexParameters
            });
        }