public void ReturnParameter_OrThrowIfWhiteSpace_Ok() { const string valueToTest = "Hello"; Assert.DoesNotThrow(() => ReturnParameter.OrThrowIfWhitespace(valueToTest, "test")); Assert.AreEqual(ReturnParameter.OrThrowIfWhitespace(valueToTest, "test"), valueToTest); }
public void ReturnParameter_OrThrowIfNull_Ok() { var obj = new object(); Assert.DoesNotThrow(() => ReturnParameter.OrThrowIfNull(obj, "test")); Assert.AreEqual(ReturnParameter.OrThrowIfNull(obj, "test"), obj); }
public void ReturnParameterMultipleSkipableTest() { var view = new ViewWithButton { BindingContext = new ViewModelSimleHandling() }; var behavior = new EventToMultipleHandlersBehavior { EventName = "Clicked" }; var handlerWithReturn = new EventToMethodHandler <int> { MethodName = "MethodWithReturnInt" }; var handlerWithReturnParameter = new EventToMethodHandler { MethodName = "MethodWithParameterInt" }; var returnParameter = new ReturnParameter <int>(); handlerWithReturnParameter.Parameters.Add(returnParameter); behavior.Handlers.Add(handlerWithReturn); behavior.Handlers.Add(new DelayEventHandler()); behavior.Handlers.Add(new DelayEventHandler()); behavior.Handlers.Add(new DelayEventHandler()); behavior.Handlers.Add(handlerWithReturnParameter); view.Button.Behaviors.Add(behavior); view.Button.SendClicked(); returnParameter.GetValue().Should().Be(9); view.BindingContext.GetFieldValue("_parameterValue").Should().Be(9); }
/// <summary> /// 获取数据 /// </summary> /// <param name="getMessage"></param> internal void Get(QueueTaskThread.GetMessage getMessage) { ReturnType returnType = ReturnType.MessageQueueNotFoundReader; try { if (isDisposed == 0) { if (getMessage.Identity == Identity) { if (onGetMessage == null || !onGetMessage(new ReturnParameter { Type = ReturnType.Success })) { onGetMessage = getMessage.OnReturn; isGetMessageStream = getMessage.IsReturnStream; ulong endIdentity = Math.Min(Identity + config.SendClientCount, writeIdentity); sendIdentity = Identity; sendMessageIndex = messageIndex; getMessage = null; ReturnParameter returnParameter = new ReturnParameter { IsDeSerializeStream = isGetMessageStream, Type = ReturnType.Success }; while (sendIdentity != endIdentity) { returnParameter.Parameter = messages[sendMessageIndex].Data; if (onGetMessage(returnParameter)) { nextSendIndex(); } else { onGetMessage = null; return; } } return; } else { returnType = ReturnType.MessageQueueGetMessageExists; } } else { returnType = ReturnType.MessageQueueReaderIdentityError; } } } finally { if (getMessage != null) { getMessage.OnReturn(new ReturnParameter { Type = returnType }); } } }
internal void CallOnReturn(uint sendCount) { ReturnParameter returnParameter = default(ReturnParameter); returnParameter.Parameter.ReturnParameterSet(sendCount); onReturn.Callback(returnParameter); onReturn = null; }
internal void CallOnReturn(ulong identity) { ReturnParameter returnParameter = default(ReturnParameter); returnParameter.Parameter.ReturnParameterSet(identity); onReturn.Callback(returnParameter); onReturn = null; }
/// <summary> /// Applies a member mapping to this method body's implementation, /// 'this' parameter, parameter list and return parameter. /// The result is returned as a new method body. /// </summary> /// <param name="memberMapping">The member mapping to apply.</param> /// <returns>A new method body.</returns> public MethodBody Map(MemberMapping memberMapping) { var newRetParam = ReturnParameter.Map(memberMapping); var newThisParam = ThisParameter.Map(memberMapping); var newParamList = Parameter.MapAll(Parameters, memberMapping); var newImpl = Implementation.Map(memberMapping); return(new MethodBody(newRetParam, newThisParam, newParamList, newImpl)); }
public void ReturnParameter_OrThrowIfNullOrEmpty_Collection_Ok() { var testColl = new List <int> { 1, 2, 3 }; Assert.DoesNotThrow(() => ReturnParameter.OrThrowIfNullOrEmpty(testColl, "list")); Assert.That(ReturnParameter.OrThrowIfNullOrEmpty(testColl, "list"), Is.EqualTo(testColl)); }
public void ReturnParameterForParallelTest() { var view = new ViewWithButton { BindingContext = new ViewModelSimleHandling() }; var behavior = new EventToMultipleHandlersBehavior { EventName = "Clicked" }; var handlerWithReturn = new EventToMethodHandler <int> { MethodName = "MethodWithReturnInt" }; var parallelExecutor = new ParallelHandlerExecutor(); var innerParallelExecutor = new ParallelHandlerExecutor(); var handlerWithMethod = new EventToMethodHandler { MethodName = "Method" }; var handlerWithReturnParameter1 = new EventToMethodHandler { MethodName = "MethodWithParameterInt" }; var returnParameter1 = new ReturnParameter <int>(); handlerWithReturnParameter1.Parameters.Add(returnParameter1); var handlerWithReturnParameter2 = new EventToMethodHandler { MethodName = "MethodWithParameterInt" }; var returnParameter2 = new ReturnParameter <int>(); handlerWithReturnParameter2.Parameters.Add(returnParameter2); var handlerWithReturnParameter3 = new EventToMethodHandler { MethodName = "MethodWithParameterInt" }; var returnParameter3 = new ReturnParameter <int>(); handlerWithReturnParameter3.Parameters.Add(returnParameter3); parallelExecutor.Handlers.Add(handlerWithReturnParameter1); parallelExecutor.Handlers.Add(handlerWithMethod); parallelExecutor.Handlers.Add(innerParallelExecutor); parallelExecutor.Handlers.Add(handlerWithReturnParameter2); innerParallelExecutor.Handlers.Add(handlerWithReturnParameter3); innerParallelExecutor.Handlers.Add(handlerWithMethod); behavior.Handlers.Add(handlerWithReturn); behavior.Handlers.Add(handlerWithMethod); behavior.Handlers.Add(new DelayEventHandler()); behavior.Handlers.Add(parallelExecutor); view.Button.Behaviors.Add(behavior); view.Button.SendClicked(); returnParameter1.GetValue().Should().Be(9); returnParameter2.GetValue().Should().Be(9); returnParameter3.GetValue().Should().Be(9); }
/// <summary> /// 搜索树字典获取数据 /// </summary> public override void RunTask() { ReturnParameter returnParameter = default(ReturnParameter); try { returnParameter.Parameter.ReturnParameterSetBinary(new ReturnArray <valueType>(getCount > 0 ? dictionary.Dictionary.GetRange(skipCount, getCount) : dictionary.Dictionary.GetRangeDesc(skipCount, -getCount))); } finally { OnReturn.Callback(returnParameter); } }
private Buffer callback() { if (onReturn != null) { ReturnParameter returnParameter = new ReturnParameter(); returnParameter.Parameter.ReturnParameterSet(true); onReturn.Callback(returnParameter); onReturn = null; } return(LinkNext); }
private void UpdateParameterTypes() { // Update implicit parameters. ReturnParameter.SetParameterTypeInternal(_owner.Signature.ReturnType); ThisParameter?.SetParameterTypeInternal(GetThisParameterType()); // Update remaining parameter types. for (int i = 0; i < _parameters.Count; i++) { _parameters[i].SetParameterTypeInternal(_owner.Signature.ParameterTypes[i]); } }
private void callback(ref Buffer next) { next = LinkNext; LinkNext = null; if (onReturn != null) { ReturnParameter returnParameter = new ReturnParameter(); returnParameter.Parameter.ReturnParameterSet(true); onReturn.Callback(returnParameter); onReturn = null; } }
/// <summary> /// 获取数据 /// </summary> /// <param name="getMessage"></param> internal void Get(QueueTaskThread.GetMessage getMessage) { ReturnType returnType = ReturnType.MessageQueueNotFoundReader; try { if (isDisposed == 0) { if (getMessage.Identity == Identity) { if (onGetMessage == null || !onGetMessage.Callback(new ReturnParameter(ReturnType.Success))) { onGetMessage = getMessage.OnReturn; isGetMessageStream = getMessage.IsReturnStream; ulong endIdentity = Math.Min(Identity + Config.SendClientCount, writeIdentity); sendIdentity = Identity; sendMessageIndex = messageIndex; getMessage = null; ReturnParameter returnParameter = default(ReturnParameter); while (sendIdentity != endIdentity) { returnParameter.Set(messages[sendMessageIndex].Data, isGetMessageStream); if (onGetMessage.Callback(returnParameter)) { nextSendIndex(); } else { onGetMessage = null; return; } } return; } else { returnType = ReturnType.MessageQueueGetMessageExists; } } else { returnType = ReturnType.MessageQueueReaderIdentityError; } } } finally { if (getMessage != null) { getMessage.OnReturn.Callback(new ReturnParameter(returnType)); } } }
/// <summary> /// 申请锁 /// </summary> /// <returns></returns> internal bool Enter() { ReturnParameter returnParameter = new ReturnParameter(); returnParameter.Parameter.ReturnParameterSet(++node.RandomNo); if (OnReturn.Callback(returnParameter)) { AutoCSer.Threading.SecondTimer.InternalTaskArray.Append(onTimeout, AutoCSer.Threading.SecondTimer.SetNow().AddTicks(timeOutTicks)); return(true); } return(false); }
/// <summary> /// 申请锁 /// </summary> /// <returns></returns> internal bool Enter() { ReturnParameter returnParameter = new ReturnParameter(); returnParameter.Parameter.ReturnParameterSet(++node.RandomNo); if (OnReturn(returnParameter)) { AutoCSer.Threading.TimerTask.Default.Add(onTimeout, Date.NowTime.Set().AddTicks(timeOutTicks)); return(true); } return(false); }
public void MapReturnValue() { ReturnParameter e = new ReturnParameter(); using (DbManager db = new DbManager()) { db .SetSpCommand("Scalar_ReturnParameter") .ExecuteNonQuery("Value", e); } Assert.AreEqual(12345, e.Value); }
public void TestAlgorithm2() { decimal a, b; a = 0.1m; b = 0.5m; var function = FunctionType.Algorithm2; TestProject.Services.Repository.CalculateAlgotithm calculateAlgotithm = new CalculateAlgotithm(); ReturnParameter param = calculateAlgotithm.CalAlgorithm(a, b, function); Assert.AreEqual(0.55m, Convert.ToDecimal(param.Var)); }
/// <summary> /// 搜索树字典获取数据 /// </summary> public override void Call() { ReturnParameter returnParameter = default(ReturnParameter); try { returnParameter.Parameter.ReturnParameterSetBinary(new ReturnArray <valueType>(getCount > 0 ? dictionary.Dictionary.GetRange(skipCount, getCount) : dictionary.Dictionary.GetRangeDesc(skipCount, -getCount))); } catch (Exception error) { cache.TcpServer.AddLog(error); } finally { OnReturn.Callback(returnParameter); } }
private bool onGetSendCount(ref ReturnParameter sendCount) { switch (sendCount.Parameter.ReturnType) { case ReturnType.Success: if (sendCount.Parameter.Type == ValueData.DataType.UInt && consumer.IsProcessor(this)) { getMessageKeepCallback = consumer.GetMessage(onGetMessage); return(true); } break; } return(false); }
public static void Write(Stream stream, List <SpawnPoint> items) { stream.Write(2); stream.Write(items.Count); foreach (var item in items) { BinaryMapping.WriteObject(stream, new Raw { Type = item.Type, Flag = item.Flag, Id = item.Id, EntityCount = (short)item.Entities.Count, EventActivatorCount = (short)item.EventActivators.Count, WalkPathCount = (short)item.WalkPath.Count, ReturnParameterCount = (short)item.ReturnParameters.Count, SignalCount = (short)item.Signals.Count, Reserved10 = 0, Reserved14 = 0, Reserved18 = 0, Place = item.Teleport.Place, Door = item.Teleport.Door, World = item.Teleport.World, Unk1f = item.Teleport.Unknown, Unk20 = item.Unk20, Unk24 = item.Unk24, Unk28 = 0, }); foreach (var spawnPoint in item.Entities) { Entity.Write(stream, spawnPoint); } foreach (var unk in item.EventActivators) { EventActivator.Write(stream, unk); } foreach (var unk in item.WalkPath) { WalkPathDesc.Write(stream, unk); } foreach (var unk in item.ReturnParameters) { ReturnParameter.Write(stream, unk); } foreach (var unk in item.Signals) { Signal.Write(stream, unk); } } }
public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Target == AttributeTargets.ReturnValue) { if (return_attributes == null) { return_attributes = new ReturnParameter(this, InvokeBuilder.MethodBuilder, Location); } return_attributes.ApplyAttributeBuilder(a, ctor, cdata, pa); return; } base.ApplyAttributeBuilder(a, ctor, cdata, pa); }
private bool onGetDequeueIdentity(ref ReturnParameter identity) { switch (identity.Parameter.ReturnType) { case ReturnType.Success: if (identity.Parameter.Type == ValueData.DataType.ULong && consumer.IsProcessor(this)) { messageTime = Date.NowTime.Now; sendClientCount = (consumer.Config.SendClientCount >> 1) | 1U; getMessageKeepCallback = consumer.GetMessage(this.identity = identity.Parameter.Int64.ULong, onGetMessage); return(true); } break; } return(false); }
public void ReturnParameterTest() { var intParameter = new ReturnParameter <int>(); var stringParameter = new ReturnParameter <string>(); intParameter.SetReturnValue(3); stringParameter.SetReturnValue("qwerty1234"); intParameter.GetParamType().Should().BeAssignableTo <int>(); intParameter.GetValue().Should().Be(3); intParameter.Should().BeAssignableTo <IReturnable>(); stringParameter.GetParamType().Should().BeAssignableTo <string>(); stringParameter.GetValue().Should().Be("qwerty1234"); stringParameter.Should().BeAssignableTo <IReturnable>(); }
internal IEnumerable <ITypeModelDifference> FindDifferences(MethodDescription actualMethod) { var differences = new List <ITypeModelDifference>(); differences.AddRange(ReturnParameter.FindDifferences(actualMethod.ReturnParameter)); if (Parameters.Length != actualMethod.Parameters.Length) { differences.Add(new ParameterCountMismatch(this, actualMethod)); } else { for (int i = 0; i < Parameters.Length; ++i) { var expectedParameter = Parameters[i]; var actualParameter = actualMethod.Parameters[i]; differences.AddRange(expectedParameter.FindDifferences(actualParameter)); } } return(differences); }
/// <summary> /// 释放锁 /// </summary> /// <param name="exit"></param> internal void Exit(QueueTaskThread.Exit exit) { ReturnParameter returnParameter = new ReturnParameter(ReturnType.NotFoundLock); try { if (head != null && RandomNo == exit.RandomNo) { returnParameter.Parameter.ReturnParameterSet(true); do { if ((head = head.Next) == null) { end = null; return; } }while (!head.Enter()); } } finally { exit.OnReturn.Callback(returnParameter); } }
public IActionResult Index(AlgorithmModel algorithmModel) { if (ModelState.IsValid) { decimal result = 0; ReturnParameter param = _calculateAlgotithm.CalAlgorithm(algorithmModel.a, algorithmModel.b, algorithmModel.FunctionType); if (param.Flag == true) { result = Convert.ToDecimal(param.Var); _log.LogData(algorithmModel.FunctionType, algorithmModel.a, algorithmModel.b, result.ToString()); result = Math.Round(result, 2); return(RedirectToAction("Result", "Home", new { @result = param.Var })); } else { _log.LogData(algorithmModel.FunctionType, algorithmModel.a, algorithmModel.b, param.Message); return(RedirectToAction("Result", "Home", new { @result = param.Message })); } } return(View()); }
public override void Emit() { base.Emit(); if (ReturnType.Type != null) { if (ReturnType.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { return_attributes = new ReturnParameter(this, InvokeBuilder.MethodBuilder, Location); Module.PredefinedAttributes.Dynamic.EmitAttribute(return_attributes.Builder); } else if (ReturnType.Type.HasDynamicElement) { return_attributes = new ReturnParameter(this, InvokeBuilder.MethodBuilder, Location); Module.PredefinedAttributes.Dynamic.EmitAttribute(return_attributes.Builder, ReturnType.Type, Location); } ConstraintChecker.Check(this, ReturnType.Type, ReturnType.Location); } Constructor.ParameterInfo.ApplyAttributes(this, Constructor.ConstructorBuilder); Constructor.ConstructorBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); parameters.CheckConstraints(this); parameters.ApplyAttributes(this, InvokeBuilder.MethodBuilder); InvokeBuilder.MethodBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); if (BeginInvokeBuilder != null) { BeginInvokeBuilder.ParameterInfo.ApplyAttributes(this, BeginInvokeBuilder.MethodBuilder); EndInvokeBuilder.ParameterInfo.ApplyAttributes(this, EndInvokeBuilder.MethodBuilder); BeginInvokeBuilder.MethodBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); EndInvokeBuilder.MethodBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); } }
public CustomAttributeBuilder[] CloneReturnAttributes() => ReturnParameter.CloneAttributes();
public override TReturn Do <TReturn>(Func <TSuccess, TReturn> onSuccess, [AllowedToBeNull] Func <TFailure, TReturn> onFailure) { return(ReturnParameter.OrThrowIfNull(onSuccess, "onSuccess")(this.item)); }
internal MethodDefSignatureConverter(PEFileToObjectModel peFileToObjectModel, MethodDefinition moduleMethod, MemoryReader signatureMemoryReader) : base(peFileToObjectModel, signatureMemoryReader, moduleMethod) { // TODO: Check minimum required size of the signature... this.FirstByte = this.SignatureMemoryReader.ReadByte(); if (SignatureHeader.IsGeneric(this.FirstByte)) { this.GenericParamCount = (uint)this.SignatureMemoryReader.ReadCompressedUInt32(); } this.paramCount = this.SignatureMemoryReader.ReadCompressedUInt32(); bool dummyPinned; this.ReturnCustomModifiers = this.GetCustomModifiers(out dummyPinned); byte retByte = this.SignatureMemoryReader.PeekByte(0); bool isReturnByReference = false; if (retByte == ElementType.Void) { this.ReturnTypeReference = peFileToObjectModel.PlatformType.SystemVoid; this.SignatureMemoryReader.SkipBytes(1); } else if (retByte == ElementType.TypedReference) { this.ReturnTypeReference = peFileToObjectModel.PlatformType.SystemTypedReference; this.SignatureMemoryReader.SkipBytes(1); } else { if (retByte == ElementType.ByReference) { isReturnByReference = true; this.SignatureMemoryReader.SkipBytes(1); } this.ReturnTypeReference = this.GetTypeReference(); } PEFileReader peFileReader = peFileToObjectModel.PEFileReader; uint paramRowCount; uint paramRowStart = peFileReader.GetParamInformation(moduleMethod.MethodDefRowId, out paramRowCount); uint paramRowEnd = paramRowStart + paramRowCount; ParamInfo[] paramInfoArray = new ParamInfo[paramRowCount]; if (peFileReader.UseParamPtrTable) { for (uint paramRowIter = paramRowStart; paramRowIter < paramRowEnd; ++paramRowIter) { uint paramRowId = peFileReader.ParamPtrTable.GetParamFor(paramRowIter); ParamRow paramRow = peFileReader.ParamTable[paramRowId]; // TODO: Error check if seqence is in proper range... paramInfoArray[paramRowId - paramRowStart] = new ParamInfo(paramRowId, paramRow.Sequence, peFileToObjectModel.GetNameFromOffset(paramRow.Name), paramRow.Flags); } } else { for (uint paramRowId = paramRowStart; paramRowId < paramRowEnd; ++paramRowId) { ParamRow paramRow = peFileReader.ParamTable[paramRowId]; // TODO: Error check if seqence is in proper range... paramInfoArray[paramRowId - paramRowStart] = new ParamInfo(paramRowId, paramRow.Sequence, peFileToObjectModel.GetNameFromOffset(paramRow.Name), paramRow.Flags); } } if (paramRowCount > 0 && paramInfoArray[0].ParamSequence == 0) { ParamFlags paramFlag = paramInfoArray[0].ParamFlags; if (isReturnByReference) { paramFlag |= ParamFlags.ByReference; } this.ReturnParameter = new ReturnParameter(this.PEFileToObjectModel, paramInfoArray[0].ParamName, paramFlag, paramInfoArray[0].ParamRowId); } else { this.ReturnParameter = new ReturnParameter(this.PEFileToObjectModel, Dummy.Name, isReturnByReference ? ParamFlags.ByReference : 0, 0); } this.ParamInfoArray = paramInfoArray; if (this.paramCount > 0) { IParameterDefinition[] moduleParamArr = this.GetModuleParameters(true, moduleMethod, this.paramCount); this.paramCount = moduleParamArr.Length; if (this.paramCount > 0) this.Parameters = moduleParamArr; } }