public static DynMethod GetByID(Guid ID) { Init(); DynMethod expressionMethod = null; if (methodsByIds.TryGetValue(ID, out expressionMethod)) { return(expressionMethod); } return(null); }
internal Delegate InnerCreateDelegate(Type delegateType, out string instructions, OptimizationOptions optimizationOptions) { Seal(optimizationOptions); var il = DynMethod.GetILGenerator(); instructions = IL.UnBuffer(il); AutoNamer.Release(this); return(DynMethod.CreateDelegate(delegateType)); }
//////////////////////////////////////////////////////////////////// public static ExpressionMethodInfo FindByName(String Name) { Init(); DynMethod expressionMethod = null; if (methodsByNames.TryGetValue(Name, out expressionMethod)) { return new ExpressionMethodInfo() { ID = expressionMethod.ID } } ; return(null); }
public static void Add(DynMethod Method) { Init(); lock (lck) { if (!methodsByIds.ContainsKey(Method.ID)) { foreach (String name in Method.Names) #if CASE_INSENSITIVE { methodsByNames[name.ToUpper()] = Method; } #else { methodsByNames[name] = Method; } #endif methodsByIds[Method.ID] = Method; } } }
private static DynMethodResult EvaluateInlineMethod( Object Object, Object Method, IList <Object> MethodParameters, DynContext DynLanContext) { if (Method is OnpMethodInfo) { OnpMethodInfo methodInfo = Method as OnpMethodInfo; DynamicCallResult callResult = MyReflectionHelper.CallMethod( methodInfo.Obj, methodInfo.MethodName, CorrectParameters(MethodParameters)); if (callResult != null) { return(new DynMethodResult(callResult.Value)); } } else if (Method is OnpActionMethodInfo) { OnpActionMethodInfo methodInfo = Method as OnpActionMethodInfo; if (methodInfo != null && methodInfo.Action != null) { return(new DynMethodResult(methodInfo.Action(CorrectParameters(MethodParameters)))); } } else if (Method is DynMethod) { DynMethod onpMethod = Method as DynMethod; DynMethodResult result = null; if (Object is EmptyObject) { result = onpMethod. Body( DynLanContext, CorrectParameters(MethodParameters)); } else { #if !NET20 var tmp = new[] { Object }.Union(MethodParameters); #else var tmp = Linq2.From(new[] { Object }).Union(MethodParameters).ToArray(); #endif result = onpMethod. Body( DynLanContext, CorrectParameters(tmp)); } return(result == null ? new DynMethodResult(null) : result); } else if (Method is ExpressionMethodInfo) { ExpressionMethodInfo onpMethodInfo = Method as ExpressionMethodInfo; DynMethod onpMethod = BuildinMethods.GetByID(onpMethodInfo.ID); DynMethodResult result = null; if (onpMethod == null) { return(new DynMethodResult(result)); } if (Object is EmptyObject) { result = onpMethod. Body( DynLanContext, CorrectParameters(MethodParameters)); } else { #if !NET20 var tmp = new[] { Object }.Union(MethodParameters); #else var tmp = Linq2.From(new[] { Object }).Union(MethodParameters).ToArray(); #endif result = onpMethod. Body( DynLanContext, CorrectParameters(tmp)); } if (result != null) { result.Value = InternalTypeConverter.ToInner(result.Value); } return(result == null ? new DynMethodResult(null) : result); } else if (Method is ExpressionExtender) { ExpressionExtender onpExtender = Method as ExpressionExtender; return(new DynMethodResult( onpExtender. CalculateValueDelegate( DynLanContext, Object, MethodParameters))); } else if (Method is ExpressionExtenderInfo) { ExpressionExtenderInfo onpExtenderInfo = Method as ExpressionExtenderInfo; ExpressionExtender onpExtender = BuildinExtenders.GetByID(onpExtenderInfo.ID); if (onpExtender == null) { return(new DynMethodResult(null)); } return(new DynMethodResult( onpExtender. CalculateValueDelegate( DynLanContext, Object, MethodParameters))); } else if (Method is Delegate) { #if NETCE throw new NotSupportedException("Calling delegates is forbidden on wince2.0!"); #else Delegate m = Method as Delegate; DynamicCallResult callResult = MyReflectionHelper.CallMethod( m.Target, m.Method, CorrectParameters(MethodParameters)); if (callResult != null) { return(new DynMethodResult(callResult.Value)); } #endif } if (Method == null) { if (Object == null) { throw new DynLanMethodNotFoundException("Cannot find a method to call"); } else { throw new DynLanMethodNotFoundException("Cannot find a method to call in object " + Object.GetType().Name + ""); } } throw new DynLanUnsupportedMethodTypeException("Unsupported method type " + Method.GetType() + "!"); }