public TargetOptions Target(Type modelType) { if (modelType == null) { throw new ArgumentNullException(nameof(modelType)); } return((TargetOptions)TargetMethod.MakeGenericMethod(modelType).Invoke(this, null)); }
public void ShowWarningMsg(string text, TargetMethod targetMethod) { WarningText.text = text; if (!this.gameObject.activeInHierarchy) { this.gameObject.SetActive(true); } tar = targetMethod; }
public void OnNoClick() { if (this.gameObject.activeInHierarchy) { this.gameObject.SetActive(false); } if (tar != null) { tar = null; } }
/// <inheritdoc /> public override int GetHashCode() { unchecked { var hashCode = Method.GetHashCode(); hashCode = (hashCode * 397) ^ TargetMethod.GetHashCode(); hashCode = (hashCode * 397) ^ DeclaringType.GetHashCode(); hashCode = (hashCode * 397) ^ TargetType.GetHashCode(); hashCode = (hashCode * 397) ^ (int)InvocationType; return(hashCode); } }
public static object ExecuteTaskVoid(string PayloadID, string Identifier) { if (!Payloads.TryGetValue(PayloadID, out var TargetPayload)) { throw new Exception($"Payload {PayloadID} does not exist"); } if (!TargetPayload.Methods.TryGetValue(Identifier, out var TargetMethod)) { throw new Exception($"Payload does not container method {Identifier}"); } return(TargetMethod.Invoke(TargetPayload.Instance, null)); }
/// <summary> /// Constructs a new implementation. /// </summary> /// <param name="backendType">The main backend type.</param> /// <param name="targetMethod">The associated target method.</param> /// <param name="mode">The code-generation mode.</param> protected IntrinsicImplementation( BackendType backendType, MethodInfo targetMethod, IntrinsicImplementationMode mode) { BackendType = backendType; TargetMethod = targetMethod ?? throw new NotSupportedException( string.Format(ErrorMessages.NotSupportedIntrinsic, GetType())); if (TargetMethod.IsGenericMethod) { TargetMethod = TargetMethod.GetGenericMethodDefinition(); } Mode = mode; }
public MethodToHook(SmaliAnnotation annot, SmaliMethod interceptor) { TargetClass = annot.Properties["clazz"].Trim(); TargetMethod = annot.Properties["method"].Trim(); Interceptor = interceptor; TargetClassFormatted = string.Format("L{0};", TargetClass.Replace('.', '/')); string[] split = TargetMethod.Split(' '); string when = split[0].Trim(); if (when == "after") { HookAfter = true; } else if (when == "before") { HookBefore = true; } else { throw new Exception("Not specified when to hook method"); } if (split.Length >= 3) { if (split[1].Trim() == "static") { IsStatic = true; } else if (split[1].Trim() == "nostatic") { IsStatic = false; } } string signature = split[split.Length - 1].Trim(); int firstParenthesis = signature.IndexOf('('); if (firstParenthesis >= 0) { } else { MethodName = signature; } }
/// <summary> /// The set method type. /// </summary> private void SetMethodType() { if (TargetMethod.IsAsync()) { MethodType = TargetMethod.IsAsyncWithResult() ? MethodTypeOptions.AsyncFunction : MethodTypeOptions.AsyncAction; } else { MethodType = TargetMethod.HasReturnValue() ? MethodTypeOptions.SyncFunction : MethodTypeOptions.SyncAction; } }
public override string ToString() { var b = new StringBuilder(); b.AppendFormat("Calling Method: {0,30:G}\n", GetMethodName(CallingMethod)); b.AppendFormat("Target Method: {0,30:G}\n", GetMethodName(TargetMethod)); b.AppendLine("Arguments:"); foreach (var parameter in TargetMethod.GetParameters()) { object value = (Arguments[parameter.Position] ?? "(null)"); b.AppendFormat("\t{0,10:G}: {1}\n", parameter.Name, value); } b.AppendLine(); return(b.ToString()); }
public static void Patch(MethodInfo newMethod, Type typeOfPatch) { var harmony = new Harmony("SEDB-LITE"); TargetMethod TargetMethodData = (TargetMethod)newMethod.GetCustomAttribute(typeof(TargetMethod)); Log.WriteLineAndConsole($"Patching {TargetMethodData.Method} with {newMethod.Name} (Prefix)"); if (typeOfPatch == typeof(PrefixMethod)) { harmony.Patch(TargetMethodData.Type.GetMethod(TargetMethodData.Method, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public), new HarmonyMethod(newMethod)); } else { harmony.Patch(TargetMethodData.Type.GetMethod(TargetMethodData.Method, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public), null, new HarmonyMethod(newMethod)); } }
/// <inheritdoc /> public bool Equals(InvocationSignature other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Method.Equals(other.Method) && TargetMethod.Equals(other.TargetMethod) && DeclaringType == other.DeclaringType && TargetType == other.TargetType && InvocationType == other.InvocationType); }
public override CExecutionPin Execute(CNodeExecutionContext context, List <object> inParameters, List <object> outReturn) { for (int i = 0; i < inParameters.Count; i++) { if (InputPins[i].SourceNode == null) { inParameters[i] = InputPins[i].Literal; } } if (m_functionProxy.bIsCompiled) { m_functionProxy.compiledMethod(inParameters, outReturn); } else { object targetObject; object[] parameterArray; int parameterStartIndex; if (TargetMethod.IsStatic) { targetObject = null; parameterArray = new object[InputPins.Count]; parameterStartIndex = 0; } else { targetObject = inParameters[0]; parameterArray = new object[InputPins.Count - 1]; parameterStartIndex = 1; } for (int i = parameterStartIndex; i < InputPins.Count; i++) { parameterArray[i - parameterStartIndex] = inParameters[i]; } object returnValue = TargetMethod.Invoke(targetObject, parameterArray); outReturn.Add(returnValue); foreach (int returnIndex in m_additionalReturns) { outReturn.Add(parameterArray[returnIndex]); } } return(IsImplicit ? null : OutExecutionPins[0]); }
public static bool ExceptionThrown(Type expectedExceptionType, TargetMethod target) { try { target(); } catch (Exception ex) { if (ex.GetType() == expectedExceptionType) { return(true); } throw new ExceptionNotThrownException(expectedExceptionType, ex); } throw new ExceptionNotThrownException(expectedExceptionType, null); }
public static bool ExceptionThrown(Type expectedExceptionType,TargetMethod target) { try { target(); } catch (Exception ex) { if (ex.GetType() == expectedExceptionType) { return true; } throw new ExceptionNotThrownException(expectedExceptionType,ex); } throw new ExceptionNotThrownException(expectedExceptionType, null); }
/// <summary> /// Gets the node representing the target method of the delegate if no runtime lookup is needed. /// </summary> public ISymbolNode GetTargetNode(NodeFactory factory) { Debug.Assert(!NeedsRuntimeLookup); MethodDesc canonTargetMethod = TargetMethod.GetCanonMethodTarget(CanonicalFormKind.Specific); switch (_targetKind) { case TargetKind.CanonicalEntrypoint: if (TargetMethod != canonTargetMethod) { return(factory.ShadowConcreteMethod(TargetMethod, TargetMethodIsUnboxingThunk)); } else { return(factory.MethodEntrypoint(TargetMethod, TargetMethodIsUnboxingThunk)); } case TargetKind.ExactCallableAddress: if (TargetMethod != canonTargetMethod) { return(factory.FatFunctionPointer(TargetMethod, TargetMethodIsUnboxingThunk)); } else { return(factory.MethodEntrypoint(TargetMethod, TargetMethodIsUnboxingThunk)); } case TargetKind.InterfaceDispatch: return(factory.InterfaceDispatchCell(TargetMethod)); case TargetKind.MethodHandle: return(factory.RuntimeMethodHandle(TargetMethod)); case TargetKind.VTableLookup: Debug.Assert(false, "Need to do runtime lookup"); return(null); default: Debug.Assert(false); return(null); } }
public void ConfirmExceptionThrownTest2() { TargetMethod target = new TargetMethod(ThrowNoException); Confirm.ExceptionThrown(typeof(ExceptionNotThrownException), target); }
protected override async ValueTask <JsonRpcMessage> DispatchRequestAsync(JsonRpcRequest request, TargetMethod targetMethod, CancellationToken cancellationToken) { this.LastRequestDispatched = request; TaskCompletionSource <JsonRpcMessage>?completionTcs = null; if (this.EnableBuffering) { TaskCompletionSource <bool> signalTask = new TaskCompletionSource <bool>(); completionTcs = new TaskCompletionSource <JsonRpcMessage>(); this.requestSignalQueue.TryEnqueue((request, signalTask, completionTcs.Task)); await signalTask.Task; } JsonRpcMessage result = await base.DispatchRequestAsync(request, targetMethod, cancellationToken); completionTcs?.SetResult(result); return(result); }
/// <summary>Returns a hash code for this instance.</summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() => HashCode.Combine( TargetMethod?.GetHashCode() ?? 0, BenchmarkType?.GetHashCode() ?? 0);
protected void OnButtonClicked() { TargetMethod.Invoke(null, null); // all console methods are static }
public void doPing(TargetMethod method, Control ctrl) { this.theControl = ctrl; this.callbackMethod = method; this.theProxy.Beginping(new AsyncCallback(this.GetResponse), null); }
public PersistentEvent ToEvent() { var ev = new PersistentEvent { Id = Id, OrganizationId = OrganizationId, ProjectId = ProjectId, StackId = ErrorStackId, Type = Code == "404" ? Event.KnownTypes.NotFound : Event.KnownTypes.Error, Date = OccurrenceDate, IsFixed = IsFixed, IsHidden = IsHidden, Message = Message }; ev.Tags.AddRange(Tags); var error = new Exceptionless.Models.Data.Error { Message = Message, Type = Type, Code = Code }; if (StackTrace != null && StackTrace.Count > 0) { error.StackTrace = StackTrace.ToStackTrace(); } if (TargetMethod != null) { error.TargetMethod = TargetMethod.ToMethod(); } if (Modules != null && Modules.Count > 0) { error.Modules = Modules.ToModules(); } if (Inner != null) { error.Inner = Inner.ToInnerError(); } object traceLog; if (ExtendedData != null && ExtendedData.TryGetValue("TraceLog", out traceLog)) { ev.Data[Event.KnownDataKeys.TraceLog] = traceLog; ExtendedData.Remove("TraceLog"); } if (ExtendedData != null && ExtendedData.Count > 0) { error.Data.AddRange(ExtendedData.ToData()); } // TODO: __ExceptionInfo ev.Data[Event.KnownDataKeys.Error] = error; if (!String.IsNullOrEmpty(UserEmail) || !String.IsNullOrEmpty(UserDescription)) { ev.SetUserDescription(UserEmail, UserDescription); } if (!String.IsNullOrEmpty(UserName)) { ev.SetUserIdentity(UserName); } if (RequestInfo != null) { ev.Data[Event.KnownDataKeys.RequestInfo] = RequestInfo.ToRequestInfo(); } if (EnvironmentInfo != null) { ev.Data[Event.KnownDataKeys.EnvironmentInfo] = EnvironmentInfo.ToEnvironmentInfo(); } return(ev); }
public override int GetHashCode() { return(Constructor.GetHashCode() ^ TargetMethod.GetHashCode()); }
public void ConfirmExceptionThrownTest() { TargetMethod target = new TargetMethod(ThrowDivideByZeroException); Confirm.ExceptionThrown(typeof(DivideByZeroException), target); }
public void ConfirmEqualityExceptionThrownTest() { TargetMethod target = new TargetMethod(ThrowsEqualityException); Confirm.ExceptionThrown(typeof(EqualityException),target); }
private void ThrowNoException() { TargetMethod target = new TargetMethod(ThrowDivideByZeroException); Confirm.ExceptionThrown(typeof(ArgumentException), target); }
private void OnTargetMethodChanged() { OutputPins.Clear(); InputPins.Clear(); CKlaxScriptRegistry registry = CKlaxScriptRegistry.Instance; registry.TryGetFunctionInfo(TargetMethod, out CKlaxScriptFunctionInfo outFunctionInfo); Name = outFunctionInfo.displayName; if (TargetMethod.ReturnType != typeof(void)) { COutputPin returnOutput = new COutputPin() { Name = "Return", Type = TargetMethod.ReturnType, }; OutputPins.Add(returnOutput); } if (!TargetMethod.IsStatic) { CInputPin targetObjectInput = new CInputPin() { Name = "Target", Type = TargetMethod.DeclaringType, Literal = null, SourceNode = null, SourceParameterIndex = -1, StackIndex = -1, }; InputPins.Add(targetObjectInput); } ParameterInfo[] methodParameters = TargetMethod.GetParameters(); for (var index = 0; index < methodParameters.Length; index++) { ParameterInfo parameter = methodParameters[index]; Type elementType = parameter.ParameterType; if (parameter.ParameterType.IsByRef) { elementType = parameter.ParameterType.GetElementType(); if (!parameter.IsIn) { m_additionalReturns.Add(index); COutputPin output = new COutputPin() { Name = parameter.Name, Type = elementType, }; OutputPins.Add(output); } } if (parameter.IsOut) { continue; } CInputPin input = new CInputPin() { Name = outFunctionInfo.inputParameterNames[index], Type = elementType, SourceNode = null, SourceParameterIndex = -1, StackIndex = -1, }; input.Literal = input.Type.IsValueType ? Activator.CreateInstance(input.Type) : null; InputPins.Add(input); m_functionProxy = new SKlaxScriptFunctionProxy(outFunctionInfo); } }
public void Proceed() { ReturnValue = TargetMethod.Invoke(Target, Arguments); }
public void ConfirmEqualityExceptionThrownTest() { TargetMethod target = new TargetMethod(ThrowsEqualityException); Confirm.ExceptionThrown(typeof(EqualityException), target); }