private static MethodInfo GetMethod( Type clazz, string methodName, Type[] paramTypes, bool[] allFalse) { try { return MethodResolver.ResolveMethod(clazz, methodName, paramTypes, true, allFalse, allFalse); } catch (MethodResolverNoSuchMethodException) { var method = MethodResolver.ResolveExtensionMethod( clazz, methodName, paramTypes, true, allFalse, allFalse); if (method != null) { return method; } Log.Debug("Not resolved for class '" + clazz.Name + "' method '" + methodName + "'"); } catch (Exception) { Log.Debug("Not resolved for class '" + clazz.Name + "' method '" + methodName + "'"); } return null; }
public MethodInfo ResolveMethod( Type clazz, String methodName, Type[] paramTypes, bool[] allowEventBeanType, bool[] allowEventBeanCollType) { try { return(MethodResolver.ResolveMethod( clazz, methodName, paramTypes, true, allowEventBeanType, allowEventBeanType)); } catch (EngineNoSuchMethodException e) { // Lets go looking for an extension method before throwing an exception var method = MethodResolver.ResolveExtensionMethod( clazz, methodName, paramTypes, true, allowEventBeanType, allowEventBeanType); if (method == null) { throw Convert(clazz, methodName, paramTypes, e, true); } return(method); } }
public MethodInfo ResolveMethod( String typeName, String methodName, Type[] paramTypes, bool[] allowEventBeanType, bool[] allowEventBeanCollType) { Type clazz; try { clazz = ResolveTypeInternal(typeName, false); } catch (TypeLoadException e) { throw new EngineImportException( "Could not load class by name '" + typeName + "', please check imports", e); } try { return(MethodResolver.ResolveMethod( clazz, methodName, paramTypes, false, allowEventBeanType, allowEventBeanCollType)); } catch (EngineNoSuchMethodException e) { throw Convert(clazz, methodName, paramTypes, e, false); } }
public MethodInfo ResolveMethod( Type clazz, string methodName, Type[] paramTypes, bool[] allowEventBeanType) { try { return(MethodResolver.ResolveMethod( clazz, methodName, paramTypes, true, allowEventBeanType, allowEventBeanType)); } catch (MethodResolverNoSuchMethodException e) { var method = MethodResolver.ResolveExtensionMethod( clazz, methodName, paramTypes, true, allowEventBeanType, allowEventBeanType); if (method != null) { return(method); } throw Convert(clazz, methodName, paramTypes, e, true); } }
public void ResolveMethod_BaseMethodWithSameName() { var method = MethodResolver.ResolveMethod(typeof(DateTime), "ToString", "System.String ToString()"); Assert.That(method, Is.EqualTo(typeof(DateTime).GetMethod("ToString", Type.EmptyTypes))); Assert.That(method, Is.Not.EqualTo(typeof(object).GetMethod("ToString"))); }
/// <summary> /// Given a field and a set of annotations, determines if we should use a custom parse adapter. /// </summary> /// <param name="services"></param> /// <param name="type"></param> /// <param name="fieldAnnotation"></param> /// <returns></returns> /// <exception cref="ExprValidationException"></exception> private JsonSerializationForgePair GetCustomSchemaAdapter( StatementCompileTimeServices services, Type type, JsonSchemaFieldAttribute fieldAnnotation) { Type clazz; try { clazz = services.ImportServiceCompileTime.ResolveClass(fieldAnnotation.Adapter, true, ExtensionClassEmpty.INSTANCE); } catch (ImportException e) { throw new ExprValidationException($"Failed to resolve Json schema field adapter class: {e.Message}", e); } if (clazz.FindGenericInterface(typeof(JsonFieldAdapterString <>)) == null) { throw new ExprValidationException( $"Json schema field adapter class does not implement interface '{typeof(JsonFieldAdapterString<>).CleanName()}"); } if (!clazz.HasDefaultConstructor()) { throw new ExprValidationException( $"Json schema field adapter class '{clazz.CleanName()}' does not have a default constructor"); } MethodInfo writeMethod; try { writeMethod = MethodResolver.ResolveMethod(clazz, "Parse", new Type[] { typeof(string) }, true, new bool[1], new bool[1]); } catch (MethodResolverNoSuchMethodException e) { throw new ExprValidationException( $"Failed to resolve write method of Json schema field adapter class: {e.Message}", e); } if (!TypeHelper.IsSubclassOrImplementsInterface(type, writeMethod.ReturnType)) { throw new ExprValidationException( $"Json schema field adapter class '{clazz.CleanName()}' mismatches the return type of the parse method, " + $"expected '{type.CleanName()}' but found '{writeMethod.ReturnType.CleanName()}'"); } return(new JsonSerializationForgePair( new JsonSerializerForgeProvidedStringAdapter(clazz), new JsonDeserializerForgeProvidedAdapter(clazz))); }
private HashSet <MethodInfo> DeserializeMethods(string collectionKey) { var methods = new HashSet <MethodInfo> (); var count = _serializationInfo.GetInt32(collectionKey + ".Count"); for (int i = 0; i < count; ++i) { var methodDeclaringType = Type.GetType(_serializationInfo.GetString(collectionKey + "[" + i + "].DeclaringType")); var name = _serializationInfo.GetString(collectionKey + "[" + i + "].Name"); var signature = _serializationInfo.GetString(collectionKey + "[" + i + "].Signature"); var method = MethodResolver.ResolveMethod(methodDeclaringType, name, signature); methods.Add(method); } return(methods); }
public static void ValidateDTMStaticMethodAllowNull( Type inputType, DateTimeMethodMode mode, Type firstParameter, IList <ExprNode> paramExpressions) { if (mode == null) { if (inputType == firstParameter) { throw new ExprValidationException("Plugin datetime method does not provide a forge for input type " + inputType.CleanName()); } return; } if (!(mode is DateTimeMethodModeStaticMethod)) { throw new ExprValidationException("Unexpected plug-in datetime method mode implementation " + mode.GetType()); } var staticMethod = (DateTimeMethodModeStaticMethod)mode; var @params = new Type[paramExpressions.Count + 1]; @params[0] = firstParameter; for (var i = 0; i < paramExpressions.Count; i++) { @params[i + 1] = paramExpressions[i].Forge.EvaluationType; } try { MethodResolver.ResolveMethod( staticMethod.Clazz, staticMethod.MethodName, @params, false, new bool[@params.Length], new bool[@params.Length]); } catch (MethodResolverNoSuchMethodException ex) { throw new ExprValidationException("Failed to find static method for date-time method extension: " + ex.Message, ex); } }
public MethodInfo ResolveMethodOverloadChecked( string className, string methodName, Type[] paramTypes, bool[] allowEventBeanType, bool[] allowEventBeanCollType, ExtensionClass extension) { Type clazz; try { clazz = ResolveClassInternal(className, false, false, extension); } catch (TypeLoadException e) { throw new ImportException( "Could not load class by name '" + className + "', please check imports", e); } try { return MethodResolver.ResolveMethod( clazz, methodName, paramTypes, false, allowEventBeanType, allowEventBeanCollType); } catch (MethodResolverNoSuchMethodException e) { var method = MethodResolver.ResolveExtensionMethod( clazz, methodName, paramTypes, true, allowEventBeanType, allowEventBeanType); if (method == null) { throw Convert(clazz, methodName, paramTypes, e, false); } return method; } }
public EventPropertyWriter GetWriter(string propertyName) { if (_writeablePropertyDescriptors == null) { InitializeWriters(); } Pair<EventPropertyDescriptor, BeanEventPropertyWriter> pair = _writerMap.Get(propertyName); if (pair != null) { return pair.Second; } Property property = PropertyParser.ParseAndWalkLaxToSimple(propertyName); if (property is MappedProperty) { var mapProp = (MappedProperty) property; var methodName = PropertyHelper.GetSetterMethodName(mapProp.PropertyNameAtomic); MethodInfo setterMethod; try { setterMethod = MethodResolver.ResolveMethod( _clazz, methodName, new Type[] { typeof (string), typeof (object) }, true, new bool[2], new bool[2]); } catch (EngineNoSuchMethodException e) { Log.Info( "Failed to find mapped property setter method '" + methodName + "' for writing to property '" + propertyName + "' taking {string, Object} as parameters"); return null; } if (setterMethod == null) { return null; } FastMethod fastMethod = _fastClass.GetMethod(setterMethod); return new BeanEventPropertyWriterMapProp(_clazz, fastMethod, mapProp.Key); } if (property is IndexedProperty) { var indexedProp = (IndexedProperty) property; var methodName = PropertyHelper.GetSetterMethodName(indexedProp.PropertyNameAtomic); MethodInfo setterMethod; try { // setterMethod = UnderlyingType.GetMethod( // methodName, BindingFlags.Public | BindingFlags.Instance, null, // new Type[] { typeof(int), typeof(object) }, null); setterMethod = MethodResolver.ResolveMethod( _clazz, methodName, new Type[] { typeof (int), typeof (object) }, true, new bool[2], new bool[2]); } catch (EngineNoSuchMethodException) { Log.Info( "Failed to find indexed property setter method '" + methodName + "' for writing to property '" + propertyName + "' taking {int, Object} as parameters"); return null; } if (setterMethod == null) { return null; } FastMethod fastMethod = _fastClass.GetMethod(setterMethod); return new BeanEventPropertyWriterIndexedProp(_clazz, fastMethod, indexedProp.Index); } return null; }
public EnumForgeDesc MakeEnumForgeDesc( IList<ExprDotEvalParam> bodiesAndParameters, int streamCountIncoming, StatementCompileTimeServices services) { // determine static method IList<Type> parametersNext = new List<Type>(); // first parameter is always the state parametersNext.Add(_mode.StateClass); // second parameter is the value: EventBean for event collection or the collection component type if (_inputEventType != null) { parametersNext.Add(typeof(EventBean)); } else { parametersNext.Add(_collectionComponentType); } // remaining parameters are the result of each DotMethodFPParam that returns a lambda (non-lambda is passed to state), always Object typed foreach (var param in bodiesAndParameters) { if (param is ExprDotEvalParamLambda) { parametersNext.Add(param.Body.Forge.EvaluationType.GetBoxedType()); } } // obtain service method var noFlags = new bool[parametersNext.Count]; MethodInfo serviceMethod; try { serviceMethod = MethodResolver.ResolveMethod(_mode.ServiceClass, _mode.MethodName, parametersNext.ToArray(), false, noFlags, noFlags); } catch (MethodResolverNoSuchMethodException ex) { throw new ExprValidationException("Failed to find service method for enumeration-method '" + _mode.MethodName + "': " + ex.Message, ex); } if (serviceMethod.ReturnType != typeof(void)) { throw new ExprValidationException( "Failed to validate service method for enumeration-method '" + _mode.MethodName + "', expected void return type"); } // obtain expected return type var returnType = _mode.ReturnType; Type expectedStateReturnType; if (returnType is ClassEPType) { expectedStateReturnType = ((ClassEPType) returnType).Clazz; } else if (returnType is EventEPType) { expectedStateReturnType = typeof(EventBean); } else if (returnType is EventMultiValuedEPType) { expectedStateReturnType = typeof(FlexCollection); } else if (returnType is ClassMultiValuedEPType) { expectedStateReturnType = ((ClassMultiValuedEPType) returnType).Component; } else { throw new ExprValidationException("Unrecognized return type " + returnType); } // check state-class if (!TypeHelper.IsSubclassOrImplementsInterface(_mode.StateClass, typeof(EnumMethodState))) { throw new ExprValidationException( "State class " + _mode.StateClass.Name + " does implement the " + typeof(EnumMethodState).FullName + " interface"); } var forge = new EnumForgePlugin(bodiesAndParameters, _mode, expectedStateReturnType, streamCountIncoming, _inputEventType); return new EnumForgeDesc(returnType, forge); }
private HashSet <MethodInfo> DeserializeTriplets(object[] overriderArray) { return(new HashSet <MethodInfo> (from object[] triplet in overriderArray let declaringType = (Type)triplet[0] let name = (string)triplet[1] let signature = (string)triplet[2] select MethodResolver.ResolveMethod(declaringType, name, signature))); }
public void ResolveMethod_ProtectedMethod() { var method = MethodResolver.ResolveMethod(typeof(object), "Finalize", "Void Finalize()"); Assert.That(method, Is.EqualTo(typeof(object).GetMethod("Finalize", BindingFlags.NonPublic | BindingFlags.Instance))); }
public void ResolveMethod_NonMatchingSignature() { MethodResolver.ResolveMethod(typeof(Console), "WriteLine", "Void Foo()"); }
public void ResolveMethod_NonMatchingName() { MethodResolver.ResolveMethod(typeof(object), "Foo", "Void Foo()"); }
protected CandidateMethod ResolveExtension(IEnumerable <MethodInfo> candidates) { var resolver = new MethodResolver(GetExtensionArgumentTypes()); return(resolver.ResolveMethod(candidates)); }
public void ResolveMethod_StaticMethod() { var method = MethodResolver.ResolveMethod(typeof(object), "ReferenceEquals", "Boolean ReferenceEquals(System.Object, System.Object)"); Assert.That(method, Is.EqualTo(typeof(object).GetMethod("ReferenceEquals"))); }
public MethodInfo ResolveReferencedMethod() { return(MethodResolver.ResolveMethod(DeclaringType, MethodName, MethodSignature)); }
public void ResolveMethod_MethodWithOverloads() { var method = MethodResolver.ResolveMethod(typeof(Console), "WriteLine", "Void WriteLine(System.String)"); Assert.That(method, Is.EqualTo(typeof(Console).GetMethod("WriteLine", new[] { typeof(string) }))); }
public EventPropertyWriterSPI GetWriter(string propertyName) { if (_writeablePropertyDescriptors == null) { InitializeWriters(); } var pair = _writerMap.Get(propertyName); if (pair != null) { return pair.Second; } var property = PropertyParser.ParseAndWalkLaxToSimple(propertyName); if (property is MappedProperty) { var mapProp = (MappedProperty) property; var methodName = PropertyHelper.GetSetterMethodName(mapProp.PropertyNameAtomic); MethodInfo setterMethod; try { setterMethod = MethodResolver.ResolveMethod( Stem.Clazz, methodName, new[] {typeof(string), typeof(object)}, true, new bool[2], new bool[2]); } catch (MethodResolverNoSuchMethodException) { Log.Info( "Failed to find mapped property setter method '" + methodName + "' for writing to property '" + propertyName + "' taking {String, Object} as parameters"); return null; } if (setterMethod == null) { return null; } return new BeanEventPropertyWriterMapProp(Stem.Clazz, setterMethod, mapProp.Key); } if (property is IndexedProperty) { var indexedProp = (IndexedProperty) property; var methodName = PropertyHelper.GetSetterMethodName(indexedProp.PropertyNameAtomic); MethodInfo setterMethod; try { setterMethod = MethodResolver.ResolveMethod( Stem.Clazz, methodName, new[] {typeof(int), typeof(object)}, true, new bool[2], new bool[2]); } catch (MethodResolverNoSuchMethodException) { Log.Info( "Failed to find indexed property setter method '" + methodName + "' for writing to property '" + propertyName + "' taking {int, Object} as parameters"); return null; } if (setterMethod == null) { return null; } return new BeanEventPropertyWriterIndexedProp(Stem.Clazz, setterMethod, indexedProp.Index); } return null; }
public void ResolveMethod_InstanceMethod() { var method = MethodResolver.ResolveMethod(typeof(MethodResolverTest), "ResolveMethod_InstanceMethod", "Void ResolveMethod_InstanceMethod()"); Assert.That(method, Is.EqualTo(MethodInfo.GetCurrentMethod())); }