Exemplo n.º 1
0
        /// <summary>
        /// Creates the capsule.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="fields">The fields.</param>
        /// <returns></returns>
        public static FastClass CreateCapsule(String name, params CapsuleField[] fields)
        {
            ModuleBuilder moduleBuilder = GetModuleBuilder();
            TypeBuilder   typeBuilder   = moduleBuilder.DefineType(
                name,
                TypeAttributes.Public |
                TypeAttributes.Class |
                TypeAttributes.AutoClass |
                TypeAttributes.AnsiClass |
                TypeAttributes.BeforeFieldInit |
                TypeAttributes.AutoLayout,
                typeof(object));

            foreach (CapsuleField field in fields)
            {
                typeBuilder.DefineField(
                    field.Name,
                    field.Type,
                    FieldAttributes.Public);
            }

#if NETFULL
            return(FastClass.Create(typeBuilder.CreateType()));
#elif NETSTANDARD
            return(FastClass.Create(typeBuilder.CreateTypeInfo().AsType()));
#else
#error "building unknown version of codebase"
#endif
        }
Exemplo n.º 2
0
        public void ResolveNamespaceClass()
        {
            var sampleClassB = FastClass.Create(typeof(ClassB));

            Assert.That(sampleClassB, Is.Not.Null);
            Assert.That(sampleClassB.TargetType, Is.EqualTo(typeof(ClassB)));
        }
Exemplo n.º 3
0
        private KeyedFastPropertyGetter MakeGetterTwo(String key)
        {
            FastClass  fastClassTwo = FastClass.Create(typeof(SupportBeanCombinedProps.NestedLevOne));
            FastMethod methodTwo    = fastClassTwo.GetMethod("GetMapped", new[] { typeof(string) });

            return(new KeyedFastPropertyGetter(methodTwo, key, SupportEventAdapterService.Service));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Static constructor
        /// </summary>
        static AssertProxy()
        {
            AssertFail = message => System.Diagnostics.Debug.Assert(true, message);

            // See if NUnit is loaded into the domain.  If it is, then by default, we will switch to using it.
            // Remember, you can change whatever you'd like about how the AssertProxy class works by simply
            // changing the AssertFail property.

            var appDomain  = AppDomain.CurrentDomain;
            var assemblies = appDomain.GetAssemblies();
            var appTypes   = assemblies.SelectMany(assembly => assembly.GetTypes()).ToArray();

            var nunitAssertionType = TypeHelper.ResolveType("NUnit.Framework.Assert", false);

            if (nunitAssertionType != null)
            {
                var asFastClass = FastClass.Create(nunitAssertionType);
                if (asFastClass != null)
                {
                    var asFastMethod = asFastClass.GetMethod("Fail", new Type[] { typeof(string) });
                    if (asFastMethod != null)
                    {
                        AssertFail = message => asFastMethod.InvokeStatic(message);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void CallInstanceMethod <T>(string methodName, T value)
        {
            var instanceA = new ClassA();
            var clazzType = FastClass.Create(typeof(ClassA));

            Assert.That(clazzType.GetMethod(methodName).Invoke(instanceA, value), Is.EqualTo(value));
        }
Exemplo n.º 6
0
        private ArrayFastPropertyGetter MakeGetter(int index)
        {
            FastClass  fastClass = FastClass.Create(typeof(SupportBeanComplexProps));
            FastMethod method    = fastClass.GetMethod("GetArrayProperty", new Type[0]);

            return(new ArrayFastPropertyGetter(method, index, _container.Resolve <EventAdapterService>()));
        }
Exemplo n.º 7
0
        public void ResolvePublicClass()
        {
            var sampleClassA = FastClass.Create(typeof(ClassA));

            Assert.That(sampleClassA, Is.Not.Null);
            Assert.That(sampleClassA.TargetType, Is.EqualTo(typeof(ClassA)));
        }
Exemplo n.º 8
0
        private KeyedFastPropertyGetter MakeGetterOne(int index)
        {
            FastClass  fastClassOne = FastClass.Create(typeof(SupportBeanCombinedProps));
            FastMethod methodOne    = fastClassOne.GetMethod("GetIndexed", new[] { typeof(int) });

            return(new KeyedFastPropertyGetter(methodOne, index, SupportEventAdapterService.Service));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="subscriber">is the subscriber to deliver to</param>
        /// <param name="method">the method to invoke</param>
        public ResultDeliveryStrategyObjectArr(String statementName, Object subscriber, MethodInfo method)
        {
            _statementName = statementName;
            _subscriber    = subscriber;
            FastClass fastClass = FastClass.Create(subscriber.GetType());

            _fastMethod = fastClass.GetMethod(method);
        }
Exemplo n.º 10
0
        public void MissingConstructorShouldReturnNull()
        {
            var clazzType = FastClass.Create(typeof(ClassA));

            var constructor = clazzType.GetConstructor(typeof(double));

            Assert.That(constructor, Is.Null);
        }
Exemplo n.º 11
0
        public SignalHandlerDefaultWInvoke(Object target, MethodInfo method, EngineImportService engineImportService)
        {
            Target = target;

            FastClass fastClass = FastClass.Create(target.GetType());

            Method = fastClass.GetMethod(method);
        }
Exemplo n.º 12
0
        public SignalHandlerDefaultWInvoke(Object target, MethodInfo method)
        {
            Target = target;

            FastClass fastClass = FastClass.Create(target.GetType());

            FastMethod = fastClass.GetMethod(method);
        }
Exemplo n.º 13
0
        public void CacheShouldReturnSameClass()
        {
            var sampleClassA = FastClass.Create(typeof(ClassA));
            var sampleClassB = FastClass.Create(typeof(ClassA));

            Assert.That(sampleClassA, Is.Not.Null);
            Assert.That(sampleClassB, Is.Not.Null);
            Assert.That(sampleClassA, Is.SameAs(sampleClassB));
        }
Exemplo n.º 14
0
        private CGLibPropertyGetter MakeGetter(Type clazz, string propertyName)
        {
            var fastClass    = FastClass.Create(clazz);
            var baseProperty = clazz.GetProperty(propertyName);
            var fastProperty = fastClass.GetProperty(baseProperty);
            var getter       = new CGLibPropertyGetter(baseProperty, fastProperty, SupportEventAdapterService.Service);

            return(getter);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="subscriber">is the receiver to method invocations</param>
        /// <param name="method">is the method to deliver to</param>
        public ResultDeliveryStrategyTypeArr(String statementName, Object subscriber, MethodInfo method)
        {
            _statementName = statementName;
            _subscriber    = subscriber;
            FastClass fastClass = FastClass.Create(subscriber.GetType());

            _fastMethod    = fastClass.GetMethod(method);
            _componentType = method.GetParameters()[0].ParameterType.GetElementType();
        }
Exemplo n.º 16
0
        private CGLibPropertyGetter MakeGetter(Type clazz, string propertyName)
        {
            var fastClass    = FastClass.Create(clazz);
            var baseProperty = clazz.GetProperty(propertyName);
            var fastProperty = fastClass.GetProperty(baseProperty);
            var getter       = new CGLibPropertyGetter(baseProperty, fastProperty, _container.Resolve <EventAdapterService>());

            return(getter);
        }
Exemplo n.º 17
0
        public void SetUp()
        {
            _bean     = SupportBeanComplexProps.MakeDefaultBean();
            _theEvent = SupportEventBeanFactory.CreateObject(_bean);
            FastClass  fastClass = FastClass.Create(typeof(SupportBeanComplexProps));
            FastMethod method    = fastClass.GetMethod("GetIndexed", new Type[] { typeof(int) });

            _getter = new KeyedFastPropertyGetter(method, 1, SupportEventAdapterService.Service);
        }
Exemplo n.º 18
0
        private static BeanInstantiator ResolveFactoryMethod(BeanEventType beanEventType,
                                                             EngineImportService engineImportService)
        {
            string factoryMethodName = beanEventType.FactoryMethodName;

            int lastDotIndex = factoryMethodName.LastIndexOf('.');

            if (lastDotIndex == -1)
            {
                try
                {
                    MethodInfo method = engineImportService.ResolveMethod(
                        beanEventType.UnderlyingType, factoryMethodName, new Type[0], new bool[0], new bool[0]);
                    if (beanEventType.FastClass != null)
                    {
                        return(new BeanInstantiatorByFactoryFastClass(beanEventType.FastClass.GetMethod(method)));
                    }
                    else
                    {
                        return(new BeanInstantiatorByFactoryReflection(method));
                    }
                }
                catch (EngineImportException e)
                {
                    string message =
                        string.Format(
                            "Failed to resolve configured factory method '{0}' expected to exist for class '{1}'",
                            factoryMethodName, beanEventType.UnderlyingType);
                    Log.Info(message, e);
                    throw new EventBeanManufactureException(message, e);
                }
            }

            string className  = factoryMethodName.Substring(0, lastDotIndex);
            string methodName = factoryMethodName.Substring(lastDotIndex + 1);

            try
            {
                MethodInfo method = engineImportService.ResolveMethod(className, methodName, new Type[0], new bool[0], new bool[0]);
                if (beanEventType.FastClass != null)
                {
                    FastClass fastClassFactory = FastClass.Create(method.DeclaringType);
                    return(new BeanInstantiatorByFactoryFastClass(fastClassFactory.GetMethod(method)));
                }
                else
                {
                    return(new BeanInstantiatorByFactoryReflection(method));
                }
            }
            catch (EngineImportException e)
            {
                String message = "Failed to resolve configured factory method '" + methodName +
                                 "' expected to exist for class '" + className + "'";
                Log.Info(message, e);
                throw new EventBeanManufactureException(message, e);
            }
        }
Exemplo n.º 19
0
        public void TestGetGetter()
        {
            FastClass           fastClass = FastClass.Create(typeof(SupportBeanPropertyNames));
            EventBean           bean      = SupportEventBeanFactory.CreateObject(new SupportBeanPropertyNames());
            MethodInfo          method    = typeof(SupportBeanPropertyNames).GetProperty("A").GetGetMethod();
            EventPropertyGetter getter    = PropertyHelper.GetGetter("A", method, fastClass, _container.Resolve <EventAdapterService>());

            Assert.AreEqual("", getter.Get(bean));
        }
Exemplo n.º 20
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="subscriber">the object to deliver to</param>
        /// <param name="method">the delivery method</param>
        /// <param name="columnNames">the column names for the map</param>
        public ResultDeliveryStrategyMap(String statementName, Object subscriber, MethodInfo method, String[] columnNames)
        {
            _statementName = statementName;
            _subscriber    = subscriber;
            FastClass fastClass = FastClass.Create(subscriber.GetType());

            _fastMethod  = fastClass.GetMethod(method);
            _columnNames = columnNames;
        }
Exemplo n.º 21
0
        private CGLibPropertyGetter MakeCGIGetter(Type clazz, String propertyName)
        {
            FastClass    fastClass    = FastClass.Create(clazz);
            PropertyInfo propertyInfo = clazz.GetProperty(propertyName);
            FastProperty fastProp     = fastClass.GetProperty(propertyInfo);

            CGLibPropertyGetter getter = new CGLibPropertyGetter(propertyInfo, fastProp, SupportEventAdapterService.Service);

            return(getter);
        }
Exemplo n.º 22
0
        protected EPDataFlowEmitter1Stream1TargetBase(int operatorNum, DataFlowSignalManager signalManager, SignalHandler signalHandler, EPDataFlowEmitterExceptionHandler exceptionHandler, ObjectBindingPair target)
        {
            OperatorNum      = operatorNum;
            SignalManager    = signalManager;
            SignalHandler    = signalHandler;
            ExceptionHandler = exceptionHandler;

            var fastClass = FastClass.Create(target.Target.GetType());

            _fastMethod  = fastClass.GetMethod(target.Binding.ConsumingBindingDesc.Method);
            TargetObject = target.Target;
        }
Exemplo n.º 23
0
        public void CanSetPrivateFields()
        {
            var constValue = 10000;
            var instance   = new ClassA();

            var clazzType  = FastClass.Create(typeof(ClassA));
            var clazzField = clazzType.GetField("privateIntValue");

            Assert.That(clazzField, Is.Not.Null);
            clazzField.Set(instance, constValue);
            Assert.That(instance.PrivateIntValue, Is.EqualTo(constValue));
        }
Exemplo n.º 24
0
        public void CanCallDefaultConstructor()
        {
            var clazzType   = FastClass.Create(typeof(ClassA));
            var constructor = clazzType.GetDefaultConstructor();

            Assert.That(constructor, Is.Not.Null);

            var instance = constructor.New();

            Assert.That(instance, Is.Not.Null);
            Assert.That(instance, Is.InstanceOf <ClassA>());
        }
Exemplo n.º 25
0
 private FastMethod GetFastMethod(Type clazz)
 {
     try
     {
         MethodInfo method         = _engineImportService.ResolveMethod(clazz, _methodName, _parameterTypes, new bool[_parameterTypes.Length], new bool[_parameterTypes.Length]);
         FastClass  declaringClass = FastClass.Create(method.DeclaringType);
         return(declaringClass.GetMethod(method));
     }
     catch (Exception)
     {
         Log.Debug("Not resolved for class '" + clazz.Name + "' method '" + _methodName + "'");
     }
     return(null);
 }
Exemplo n.º 26
0
        public void CanGetPublicFields()
        {
            var constValue = 2000;
            var instance   = new ClassA();

            instance.publicIntValue = constValue;

            var clazzType  = FastClass.Create(typeof(ClassA));
            var clazzField = clazzType.GetField("publicIntValue");

            Assert.That(clazzField, Is.Not.Null);
            Assert.That(clazzField.Get(instance), Is.EqualTo(constValue));
            Assert.That(instance.publicIntValue, Is.EqualTo(constValue));
        }
Exemplo n.º 27
0
        public void CanUseMoreThanOneArgument()
        {
            var instanceA = new ClassA();
            var clazzType = FastClass.Create(typeof(ClassA));

            Assert.That(
                clazzType.GetMethod("InstanceMethod2").Invoke(instanceA, 1, 2),
                Is.EqualTo(3));
            Assert.That(
                clazzType.GetMethod("InstanceMethod3").Invoke(instanceA, 3, 4, 5),
                Is.EqualTo(12));
            Assert.That(
                clazzType.GetMethod("InstanceMethod4").Invoke(instanceA, 6, 7, 8, 9),
                Is.EqualTo(30));
        }
Exemplo n.º 28
0
        private DynamicPropertyDescriptor GetPopulateCache(Object obj)
        {
            // Check if the method is already there
            Type target = obj.GetType();

            foreach (DynamicPropertyDescriptor desc in _cache)
            {
                if (desc.GetClazz() == target)
                {
                    return(desc);
                }
            }

            // need to add it
            using (_iLock.Acquire())
            {
                foreach (DynamicPropertyDescriptor desc in _cache)
                {
                    if (desc.GetClazz() == target)
                    {
                        return(desc);
                    }
                }

                // Lookup method to use
                MethodInfo method = DetermineMethod(target);

                // Cache descriptor and create fast method
                DynamicPropertyDescriptor propertyDescriptor;
                if (method == null)
                {
                    propertyDescriptor = new DynamicPropertyDescriptor(target, null, false);
                }
                else
                {
                    FastClass  fastClass  = FastClass.Create(target);
                    FastMethod fastMethod = fastClass.GetMethod(method);
                    propertyDescriptor = new DynamicPropertyDescriptor(target, fastMethod, fastMethod.ParameterCount > 0);
                }
                _cache.Add(propertyDescriptor);
                return(propertyDescriptor);
            }
        }
Exemplo n.º 29
0
        private static DynamicPropertyDescriptor GetPopulateCache(CopyOnWriteList <DynamicPropertyDescriptor> cache, DynamicPropertyGetterBase dynamicPropertyGetterBase, Object obj, EventAdapterService eventAdapterService)
        {
            // Check if the method is already there
            var target = obj.GetType();

            foreach (DynamicPropertyDescriptor desc in cache)
            {
                if (desc.Clazz == target)
                {
                    return(desc);
                }
            }

            // need to add it
            lock (dynamicPropertyGetterBase)
            {
                foreach (DynamicPropertyDescriptor desc in cache)
                {
                    if (desc.Clazz == target)
                    {
                        return(desc);
                    }
                }

                // Lookup method to use
                var method = dynamicPropertyGetterBase.DetermineMethod(target);

                // Cache descriptor and create fast method
                DynamicPropertyDescriptor propertyDescriptor;
                if (method == null)
                {
                    propertyDescriptor = new DynamicPropertyDescriptor(target, null, false);
                }
                else
                {
                    var fastClass  = FastClass.Create(target);
                    var fastMethod = fastClass.GetMethod(method);
                    propertyDescriptor = new DynamicPropertyDescriptor(target, fastMethod, fastMethod.ParameterCount > 0);
                }
                cache.Add(propertyDescriptor);
                return(propertyDescriptor);
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="subscriber">is the subscriber receiving method invocations</param>
        /// <param name="deliveryConvertor">for converting individual rows</param>
        /// <param name="method">to deliver the insert stream to</param>
        /// <param name="startMethod">to call to indicate when delivery starts, or null if no such indication is required</param>
        /// <param name="endMethod">to call to indicate when delivery ends, or null if no such indication is required</param>
        /// <param name="rStreamMethod">to deliver the remove stream to, or null if no such indication is required</param>
        public ResultDeliveryStrategyImpl(String statementName,
                                          Object subscriber,
                                          DeliveryConvertor deliveryConvertor,
                                          MethodInfo method,
                                          MethodInfo startMethod,
                                          MethodInfo endMethod,
                                          MethodInfo rStreamMethod)
        {
            _statementName     = statementName;
            _subscriber        = subscriber;
            _deliveryConvertor = deliveryConvertor;
            FastClass fastClass = FastClass.Create(subscriber.GetType());

            _updateFastMethod = fastClass.GetMethod(method);

            _startFastMethod = startMethod != null?fastClass.GetMethod(startMethod) : null;

            _endFastMethod = endMethod != null?fastClass.GetMethod(endMethod) : null;

            _updateRStreamFastMethod = rStreamMethod != null?fastClass.GetMethod(rStreamMethod) : null;
        }