/// <summary> /// Build auto generated property from given <see cref="TypeMethodInfo" />. /// </summary> /// <param name="methodInfo">Info of method that will be generated.</param> /// <returns>MethodItem.</returns> private static MethodItem buildAutoProperty(TypeMethodInfo methodInfo) { var buildGetter = !methodInfo.ReturnType.Equals(TypeDescriptor.Void); var methodName = methodInfo.MethodName; var propertyStorage = buildGetter ? methodName.Substring(Naming.GetterPrefix.Length) : methodName.Substring(Naming.SetterPrefix.Length); propertyStorage = "@" + propertyStorage; if (buildGetter) { var getterGenerator = new DirectGenerator((c) => { var fieldValue = c.GetField(c.CurrentArguments[0], propertyStorage) as Instance; c.Return(fieldValue); }); return(new MethodItem(getterGenerator, methodInfo)); } else { var setterGenerator = new DirectGenerator((c) => { var setValue = c.CurrentArguments[1]; c.SetField(c.CurrentArguments[0], propertyStorage, setValue); }); return(new MethodItem(setterGenerator, methodInfo)); } }
/// <summary> /// Adds the method defined by direct native method. /// </summary> /// <param name="methodPath">The method path.</param> /// <param name="source">The source.</param> /// <param name="description">The description of method signature.</param> /// <returns>TestingAssembly.</returns> public TestingAssembly AddMethod(string methodPath, DirectMethod source, MethodDescription description) { var methodInfo = buildDescription(description, methodPath); var method = new DirectGenerator(source); addMethod(method, methodInfo, description.Implemented); return(this); }
/// <summary> /// Register call handler that will be called instead of methods on registered <see cref="Instance" />. /// </summary> /// <param name="registeredInstance">Instance that is registered.</param> /// <param name="handler">Method that will be called.</param> internal void RegisterCallHandler(Instance registeredInstance, DirectMethod handler) { var generator = new DirectGenerator(handler); Loader.RegisterInjectedGenerator(registeredInstance, generator); }