コード例 #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
        }
コード例 #2
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="statement">the statement.</param>
 /// <param name="subscriber">is the receiver to method invocations</param>
 /// <param name="method">is the method to deliver to</param>
 /// <param name="componentType">Type of the component.</param>
 /// <param name="engineImportService">The engine import service.</param>
 public ResultDeliveryStrategyTypeArr(EPStatement statement, Object subscriber, MethodInfo method, Type componentType, EngineImportService engineImportService)
 {
     _statement     = statement;
     _subscriber    = subscriber;
     _fastMethod    = FastClass.CreateMethod(method);
     _componentType = componentType;
 }
コード例 #3
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);
                    }
                }
            }
        }
コード例 #4
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, SupportEventAdapterService.Service));
        }
コード例 #5
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));
        }
コード例 #6
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, _container.Resolve <EventAdapterService>()));
        }
コード例 #7
0
        /// <summary>
        /// Constructs a wrapper around the target constructor.
        /// </summary>
        /// <param name="_fastClass">The _fast class.</param>
        /// <param name="constructor">The constructor.</param>

        internal FastConstructor(FastClass _fastClass, ConstructorInfo constructor)
        {
            // Store the class that spawned us
            this._fastClass = _fastClass;

            _targetConstructor = constructor;

            int uid = System.Threading.Interlocked.Increment(ref _constructorIdCounter);

            // Create a unique name for the method
            String dynamicMethodName = "_CGLibC_" + this._fastClass.Id + "_" + uid;

            // Generate the method
            _dynamicMethod = new DynamicMethod(
                dynamicMethodName,
                MethodAttributes.Public | MethodAttributes.Static,
                CallingConventions.Standard,
                typeof(Object),
                new Type[] { typeof(Object), typeof(Object[]) },
                _targetConstructor.Module,
                true);

            EmitInvoker(_targetConstructor, _dynamicMethod.GetILGenerator());
            _invoker = (Invoker)_dynamicMethod.CreateDelegate(typeof(Invoker));
        }
コード例 #8
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);
        }
コード例 #9
0
        public void MissingConstructorShouldReturnNull()
        {
            var clazzType = FastClass.Create(typeof(ClassA));

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

            Assert.That(constructor, Is.Null);
        }
コード例 #10
0
        public SignalHandlerDefaultWInvoke(Object target, MethodInfo method)
        {
            Target = target;

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

            FastMethod = fastClass.GetMethod(method);
        }
コード例 #11
0
        public SignalHandlerDefaultWInvoke(Object target, MethodInfo method, EngineImportService engineImportService)
        {
            Target = target;

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

            Method = fastClass.GetMethod(method);
        }
コード例 #12
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;
        }
コード例 #13
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);
            }
        }
コード例 #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, _container.Resolve <EventAdapterService>());

            return(getter);
        }
コード例 #15
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));
        }
コード例 #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, SupportEventAdapterService.Service);

            return(getter);
        }
コード例 #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);
        }
コード例 #18
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();
        }
コード例 #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));
        }
コード例 #20
0
        /// <summary>
        /// Constructs a wrapper around the target field.
        /// </summary>
        /// <param name="_fastClass">The _fast class.</param>
        /// <param name="field">The field.</param>

        internal FastField(FastClass _fastClass, FieldInfo field)
        {
            // Store the class that spawned us
            fastClass = _fastClass;
            // Field we will be get/setting
            targetField = field;

            CreateDynamicGetMethod(field);
            CreateDynamicSetMethod(field);
        }
コード例 #21
0
        /// <summary>
        /// Constructs a wrapper around the target property.
        /// </summary>
        /// <param name="_fastClass">The _fast class.</param>
        /// <param name="property">The property.</param>

        internal FastProperty(FastClass _fastClass, PropertyInfo property)
        {
            // Store the class that spawned us
            fastClass = _fastClass;
            // Property we will be get/setting
            targetProperty = property;

            CreateDynamicGetMethod(property);
            CreateDynamicSetMethod(property);
        }
コード例 #22
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);
        }
コード例 #23
0
        /// <summary>
        /// Return a writer for writing a single property value.
        /// </summary>
        /// <param name="propertyName">to write to</param>
        /// <returns>
        /// null or writer if writable
        /// </returns>
        public EventPropertyWriter GetWriter(String propertyName)
        {
            if (_writeablePropertyDescriptors == null)
            {
                InitializeWriters();
            }

            var pair = _writerMap.Get(propertyName);

            if (pair != null)
            {
                return(pair.Second);
            }

            var property = PropertyParser.ParseAndWalk(propertyName, false);

            if (property is MappedProperty)
            {
                var mapProp    = (MappedProperty)property;
                var methodName = string.Format("Set{0}", mapProp.PropertyNameAtomic);
                var methodInfo = UnderlyingType.GetMethod(
                    methodName, BindingFlags.Public | BindingFlags.Instance, null,
                    new Type[] { typeof(string), typeof(object) }, null);
                if (methodInfo == null)
                {
                    Log.Info("Failed to find mapped property '" + mapProp.PropertyNameAtomic +
                             "' for writing to property '" + propertyName + "'");
                    return(null);
                }

                var fastMethod = FastClass.GetMethod(methodInfo);
                return(new BeanEventPropertyWriterMapProp(UnderlyingType, fastMethod, mapProp.Key));
            }

            if (property is IndexedProperty)
            {
                var indexedProp = (IndexedProperty)property;
                var methodName  = string.Format("Set{0}", indexedProp.PropertyNameAtomic);
                var methodInfo  = UnderlyingType.GetMethod(
                    methodName, BindingFlags.Public | BindingFlags.Instance, null,
                    new Type[] { typeof(int), typeof(object) }, null);
                if (methodInfo == null)
                {
                    Log.Info("Failed to find mapped property '" + indexedProp.PropertyNameAtomic +
                             "' for writing to property '" + propertyName + "'");
                    return(null);
                }

                var fastMethod = FastClass.GetMethod(methodInfo);
                return(new BeanEventPropertyWriterIndexedProp(UnderlyingType, fastMethod, indexedProp.Index));
            }

            return(null);
        }
コード例 #24
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));
        }
コード例 #25
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;
        }
コード例 #26
0
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="statement">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>
 /// <param name="importService">The engine import service.</param>
 public ResultDeliveryStrategyMap(
     EPStatement statement,
     object subscriber,
     MethodInfo method,
     string[] columnNames,
     ImportService importService)
 {
     _statement   = statement;
     _subscriber  = subscriber;
     _fastMethod  = FastClass.CreateMethod(method);
     _columnNames = columnNames;
 }
コード例 #27
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>());
        }
コード例 #28
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);
 }
コード例 #29
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));
        }
コード例 #30
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));
        }