private static void SetupEnd(IMethodBuilder method, VariableBase returnValue, IPropertyBuilder aspectusEnding) { VariableBase endingArgs = method.NewObj(typeof(Ending).GetConstructor(new Type[0])); endingArgs.Call(typeof(Ending).GetProperty("MethodName").GetSetMethod(), new object[] { method.Name }); if (method.ReturnType != typeof(void) && returnValue.DataType != null && returnValue.DataType.IsValueType) { endingArgs.Call(typeof(Ending).GetProperty("ReturnValue").GetSetMethod(), new object[] { method.Box(returnValue) }); } else if (method.ReturnType != typeof(void)) { endingArgs.Call(typeof(Ending).GetProperty("ReturnValue").GetSetMethod(), new object[] { returnValue }); } VariableBase parameterList = endingArgs.Call(typeof(Ending).GetProperty("Parameters").GetGetMethod()); for (int x = 1; x < method.Parameters.Count; ++x) { if (method.Parameters.ElementAt(x).DataType != null && method.Parameters.ElementAt(x).DataType.IsValueType) { parameterList.Call(typeof(List <object>).GetMethod("Add"), new object[] { method.Box(method.Parameters.ElementAt(x)) }); } else { parameterList.Call(typeof(List <object>).GetMethod("Add"), new object[] { method.Parameters.ElementAt(x) }); } } VariableBase eventsThis = method.Cast(method.This, typeof(IEvents)); Type eventHelperType = typeof(DelegateExtensions); MethodInfo[] methods = eventHelperType.GetMethods() .Where(x => x.GetParameters().Length == 3) .ToArray(); MethodInfo tempMethod = methods.Length > 0 ? methods[0] : null; tempMethod = tempMethod.MakeGenericMethod(new[] { typeof(Ending) }); method.Call(null, tempMethod, new object[] { aspectusEnding, eventsThis, endingArgs }); if (method.ReturnType != typeof(void)) { VariableBase tempReturnValue = endingArgs.Call(typeof(Ending).GetProperty("ReturnValue").GetGetMethod()); VariableBase tempNull = method.CreateLocal("TempNull", typeof(object)); If If = method.If(tempReturnValue, Comparison.NotEqual, tempNull); { returnValue.Assign(tempReturnValue); } method.SetCurrentMethod(); If.EndIf(); } }
private void SetupEnd(IMethodBuilder Method, VariableBase ReturnValue, IPropertyBuilder AspectusEnding) { VariableBase EndingArgs = Method.NewObj(typeof(Ending).GetConstructor(new Type[0])); EndingArgs.Call(typeof(Ending).GetProperty("MethodName").GetSetMethod(), new object[] { Method.Name }); if (Method.ReturnType != typeof(void) && ReturnValue.DataType != null && ReturnValue.DataType.IsValueType) { EndingArgs.Call(typeof(Ending).GetProperty("ReturnValue").GetSetMethod(), new object[] { Method.Box(ReturnValue) }); } else if (Method.ReturnType != typeof(void)) { EndingArgs.Call(typeof(Ending).GetProperty("ReturnValue").GetSetMethod(), new object[] { ReturnValue }); } VariableBase ParameterList = EndingArgs.Call(typeof(Ending).GetProperty("Parameters").GetGetMethod()); for (int x = 1; x < Method.Parameters.Count; ++x) { if (Method.Parameters[x].DataType != null && Method.Parameters[x].DataType.IsValueType) { ParameterList.Call(typeof(List <object>).GetMethod("Add"), new object[] { Method.Box(Method.Parameters[x]) }); } else { ParameterList.Call(typeof(List <object>).GetMethod("Add"), new object[] { Method.Parameters[x] }); } } VariableBase IEventsThis = Method.Cast(Method.This, typeof(IEvents)); Type EventHelperType = typeof(Utilities.Events.EventHelper); MethodInfo[] Methods = EventHelperType.GetMethods() .Where <MethodInfo>(x => x.GetParameters().Length == 3) .ToArray(); MethodInfo TempMethod = Methods.Length > 0 ? Methods[0] : null; TempMethod = TempMethod.MakeGenericMethod(new Type[] { typeof(Ending) }); Method.Call(null, TempMethod, new object[] { AspectusEnding, IEventsThis, EndingArgs }); if (Method.ReturnType != typeof(void)) { VariableBase TempReturnValue = EndingArgs.Call(typeof(Ending).GetProperty("ReturnValue").GetGetMethod()); VariableBase TempNull = Method.CreateLocal("TempNull", typeof(object)); Utilities.Reflection.Emit.Commands.If If = Method.If(TempReturnValue, Utilities.Reflection.Emit.Enums.Comparison.NotEqual, TempNull); { ReturnValue.Assign(TempReturnValue); } Method.SetCurrentMethod(); If.EndIf(); } }
private void SetupException(IMethodBuilder Method, Utilities.Reflection.Emit.Commands.Catch Catch, IPropertyBuilder AspectusException) { VariableBase ExceptionArgs = Method.NewObj(typeof(Utilities.Reflection.AOP.EventArgs.Exception).GetConstructor(new Type[0])); ExceptionArgs.Call(typeof(Utilities.Reflection.AOP.EventArgs.Exception).GetProperty("InternalException").GetSetMethod(), new object[] { Catch.Exception }); VariableBase IEventsThis = Method.Cast(Method.This, typeof(IEvents)); Type EventHelperType = typeof(Utilities.Events.EventHelper); MethodInfo[] Methods = EventHelperType.GetMethods() .Where <MethodInfo>(x => x.GetParameters().Length == 3) .ToArray(); MethodInfo TempMethod = Methods.Length > 0 ? Methods[0] : null; TempMethod = TempMethod.MakeGenericMethod(new Type[] { typeof(Utilities.Reflection.AOP.EventArgs.Exception) }); Method.Call(null, TempMethod, new object[] { AspectusException, IEventsThis, ExceptionArgs }); }
private static void SetupException(IMethodBuilder method, Catch Catch, IPropertyBuilder aspectusException) { VariableBase exceptionArgs = method.NewObj(typeof(Exception).GetConstructor(new Type[0])); exceptionArgs.Call(typeof(Exception).GetProperty("InternalException").GetSetMethod(), new object[] { Catch.Exception }); VariableBase eventsThis = method.Cast(method.This, typeof(IEvents)); Type eventHelperType = typeof(DelegateExtensions); MethodInfo[] methods = eventHelperType.GetMethods() .Where(x => x.GetParameters().Length == 3) .ToArray(); MethodInfo tempMethod = methods.Length > 0 ? methods[0] : null; tempMethod = tempMethod.MakeGenericMethod(new[] { typeof(Exception) }); method.Call(null, tempMethod, new object[] { aspectusException, eventsThis, exceptionArgs }); }
private static void SetupStart(IMethodBuilder Method, System.Reflection.Emit.Label EndLabel, VariableBase ReturnValue, IPropertyBuilder AspectusStarting) { VariableBase StartingArgs = Method.NewObj(typeof(Starting).GetConstructor(new Type[0])); StartingArgs.Call(typeof(Starting).GetProperty("MethodName").GetSetMethod(), new object[] { Method.Name }); VariableBase ParameterList = StartingArgs.Call(typeof(Starting).GetProperty("Parameters").GetGetMethod()); for (int x = 1; x < Method.Parameters.Count; ++x) { if (Method.Parameters.ElementAt(x).DataType != null && Method.Parameters.ElementAt(x).DataType.IsValueType) { ParameterList.Call(typeof(List <object>).GetMethod("Add"), new object[] { Method.Box(Method.Parameters.ElementAt(x)) }); } else { ParameterList.Call(typeof(List <object>).GetMethod("Add"), new object[] { Method.Parameters.ElementAt(x) }); } } VariableBase IEventsThis = Method.Cast(Method.This, typeof(IEvents)); Type EventHelperType = typeof(Utilities.DataTypes.ExtensionMethods.DelegateExtensions); MethodInfo[] Methods = EventHelperType.GetMethods() .Where <MethodInfo>(x => x.GetParameters().Length == 3) .ToArray(); MethodInfo TempMethod = Methods.Length > 0 ? Methods[0] : null; TempMethod = TempMethod.MakeGenericMethod(new Type[] { typeof(Starting) }); Method.Call(null, TempMethod, new object[] { AspectusStarting, IEventsThis, StartingArgs }); if (Method.ReturnType != typeof(void)) { VariableBase TempReturnValue = StartingArgs.Call(typeof(Starting).GetProperty("ReturnValue").GetGetMethod()); VariableBase TempNull = Method.CreateLocal("TempNull", typeof(object)); Utilities.Reflection.Emit.Commands.If If = Method.If(TempReturnValue, Utilities.Reflection.Emit.Enums.Comparison.NotEqual, TempNull); { ReturnValue.Assign(TempReturnValue); Method.Generator.Emit(System.Reflection.Emit.OpCodes.Br, EndLabel); } Method.SetCurrentMethod(); If.EndIf(); } }