/// <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 }
public void ResolveNamespaceClass() { var sampleClassB = FastClass.Create(typeof(ClassB)); Assert.That(sampleClassB, Is.Not.Null); Assert.That(sampleClassB.TargetType, Is.EqualTo(typeof(ClassB))); }
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)); }
/// <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); } } } }
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)); }
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>())); }
public void ResolvePublicClass() { var sampleClassA = FastClass.Create(typeof(ClassA)); Assert.That(sampleClassA, Is.Not.Null); Assert.That(sampleClassA.TargetType, Is.EqualTo(typeof(ClassA))); }
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)); }
/// <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); }
public void MissingConstructorShouldReturnNull() { var clazzType = FastClass.Create(typeof(ClassA)); var constructor = clazzType.GetConstructor(typeof(double)); Assert.That(constructor, Is.Null); }
public SignalHandlerDefaultWInvoke(Object target, MethodInfo method, EngineImportService engineImportService) { Target = target; FastClass fastClass = FastClass.Create(target.GetType()); Method = fastClass.GetMethod(method); }
public SignalHandlerDefaultWInvoke(Object target, MethodInfo method) { Target = target; FastClass fastClass = FastClass.Create(target.GetType()); FastMethod = fastClass.GetMethod(method); }
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)); }
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); }
/// <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(); }
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); }
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); }
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); } }
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)); }
/// <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; }
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); }
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; }
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)); }
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>()); }
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); }
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)); }
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)); }
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); } }
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); } }
/// <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; }