Esempio n. 1
0
        //private static HashSet<MethodInfo> s_objectMethods;

        //protected HashSet<MethodInfo> ObjectMethods
        //{
        //  get
        //  {
        //    if (s_objectMethods == null)
        //    {
        //      s_objectMethods = new HashSet<MethodInfo> (typeof (Object).GetMethods (), MethodInfoEqualityComparer.Get);
        //    }
        //    return s_objectMethods;
        //  }
        //}


        // Create proxy ctor which takes proxied instance and stores it in field in class
        private void CreateProxyCtor(Type proxiedType)
        {
            var arg  = new ArgumentReference(proxiedType);
            var ctor = _classEmitter.CreateConstructor(new[] { arg });

            ctor.CodeBuilder.AddStatement(new ConstructorInvocationStatement(typeof(object).GetConstructor(Type.EmptyTypes)));
            ctor.CodeBuilder.AddStatement(new AssignStatement(_proxied, arg.ToExpression()));
            ctor.CodeBuilder.AddStatement(new ReturnStatement());
        }
Esempio n. 2
0
        public void CreateConstructorCreateField()
        {
            var                classEmitter = new CustomClassEmitter(Scope, "CreateConstructorCreateField", typeof(object));
            FieldReference     field        = classEmitter.CreateField("_test", typeof(string));
            ConstructorEmitter constructor  = classEmitter.CreateConstructor(new[] { typeof(string), typeof(int) });

            constructor.CodeBuilder.InvokeBaseConstructor();
            constructor.CodeBuilder
            .AddStatement(new AssignStatement(field, new ArgumentReference(typeof(string), 1).ToExpression()))
            .AddStatement(new ReturnStatement());

            object instance = Activator.CreateInstance(classEmitter.BuildType(), "bla", 0);

            Assert.That(instance.GetType().GetField("_test").GetValue(instance), Is.EqualTo("bla"));
        }