예제 #1
0
        [Test] public void InvokeChokesOnNonExistentMethod()
        {
            IClass c = _emmiter.Class("Nonexistent").In(_namespace);
            {
                var f = c.Field(_interface, _wrappedFieldName);

                var m = c.Method(typeof(string), _methodName, _emmiter.Arg <int>("i")).Public;
                using (var code = m.Code())
                {
                    var e = Assert.Throws <ArgumentException>(() => f.Invoke("NonExistentMethod", m.Args[0]));
                    System.Diagnostics.Debug.WriteLine(e.Message);
                }
            }
        }
        private void CreateClassMembers(IClass c)
        {
            var wrapped = c.Field(_interface, _wrappedFieldName);

            var ctor = c.Constructor(_emmiter.Arg <IWriteOnlyProperty>("wrapped")).Public;

            using (var code = ctor.Code())
            {
                code.Assign(wrapped, ctor.Args[0]);
            }

            var writeOnlyProperty = c.Property(typeof(int), _propertyName).Public;
            var m = writeOnlyProperty.Setter();

            using (var code = m.Code())
            {
                code.Assign(wrapped.Property(_propertyName), m.Value);
            }
        }
        private void CreateClassMembers(IClass c)
        {
            var wrapped = c.Field(_interface, _wrappedFieldName);

            var ctor = c.Constructor(_emmiter.Arg <IRefParamMethod>("wrapped")).Public;

            using (var code = ctor.Code())
            {
                code.Assign(wrapped, ctor.Args[0]);
                code.Return();
            }

            var simpleMethod = c.Method(_methodName, _emmiter.ArgRef <long>("y")).Public;

            using (var code = simpleMethod.Code())
            {
                var result = wrapped.Invoke(_methodName, simpleMethod.Args[0]);
                code.Return(result);
            }
        }