Beispiel #1
0
        public void AddProperty(CodeGenerationContext context, MutablePropertyInfo property)
        {
            ArgumentUtility.CheckNotNull("context", context);
            ArgumentUtility.CheckNotNull("property", property);

            var getMethod = property.MutableGetMethod;
            var setMethod = property.MutableSetMethod;

            Assertion.IsTrue(getMethod == null || setMethod == null || getMethod.CallingConvention == setMethod.CallingConvention);

            var callingConvention   = (getMethod ?? setMethod).CallingConvention;
            var indexParameterTypes = property.GetIndexParameters().Select(p => p.ParameterType).ToArray();
            var propertyBuilder     = context.TypeBuilder.DefineProperty(
                property.Name, property.Attributes, callingConvention, property.PropertyType, indexParameterTypes);

            DefineCustomAttributes(propertyBuilder, property);

            if (getMethod != null)
            {
                propertyBuilder.SetGetMethod(context.MethodBuilders[getMethod]);
            }
            if (setMethod != null)
            {
                propertyBuilder.SetSetMethod(context.MethodBuilders[setMethod]);
            }
        }
Beispiel #2
0
        public void Initialization_WriteOnly()
        {
            var property = new MutablePropertyInfo(_declaringType, _name, _attributes, getMethod: null, setMethod: _setMethod);

            Assert.That(property.MutableGetMethod, Is.Null);
            var actualIndexParameters = property.GetIndexParameters();

            Assert.That(actualIndexParameters, Has.Length.EqualTo(2));
            CheckParameter(actualIndexParameters[0], property, 0, _indexParameters[0].Name, _indexParameters[0].Type, _indexParameters[0].Attributes);
            CheckParameter(actualIndexParameters[1], property, 1, _indexParameters[1].Name, _indexParameters[1].Type, _indexParameters[1].Attributes);
        }
Beispiel #3
0
        public void SetUp()
        {
            _declaringType   = MutableTypeObjectMother.Create();
            _name            = "Property";
            _attributes      = (PropertyAttributes)7;
            _type            = ReflectionObjectMother.GetSomeType();
            _indexParameters = ParameterDeclarationObjectMother.CreateMultiple(2);
            _getMethod       = MutableMethodInfoObjectMother.Create(returnType: _type, parameters: _indexParameters);
            _setMethod       =
                MutableMethodInfoObjectMother.Create(parameters: _indexParameters.Concat(new[] { ParameterDeclarationObjectMother.Create(_type) }));

            _property = new MutablePropertyInfo(_declaringType, _name, _attributes, _getMethod, _setMethod);
        }
Beispiel #4
0
        public void Initialization_ReadOnly()
        {
            var property = new MutablePropertyInfo(_declaringType, _name, _attributes, getMethod: _getMethod, setMethod: null);

            Assert.That(property.MutableSetMethod, Is.Null);
        }
 public PropertyInfo GetGeneratedProperty(MutablePropertyInfo mutableProperty)
 {
     return((PropertyInfo)GetGeneratedMember(mutableProperty));
 }