public void TestUsing() { ContextVariable<bool> var = new ContextVariable<bool>(true); Assert.AreEqual(true, var.Value); bool executedBlock = false; var.Using(false, delegate { executedBlock = true; Assert.AreEqual(false, var.Value); }); Assert.IsTrue(executedBlock); Assert.AreEqual(true, var.Value); }
private bool UnmarshalResult(int dataTypeId, IntPtr dataPtr, out object result) { if (dataTypeId < 0) { result = new ContextVariable(m_opaque, dataPtr); return(true); } if (dataTypeId == 0) // special case for null object { result = null; return(true); } if (dataTypeId >= basicTypes.Length) { result = null; return(false); } Type dataType = Type.GetType(basicTypes[dataTypeId]); if (dataType == typeof(string)) { if (dataPtr == IntPtr.Zero) { result = string.Empty; return(true); } result = Marshal.PtrToStringBSTR(dataPtr); Marshal.FreeBSTR(dataPtr); return(true); } if (dataType == typeof(char)) { BlittableChar c = Marshal.PtrToStructure <BlittableChar>(dataPtr); Marshal.FreeCoTaskMem(dataPtr); result = (char)c; return(true); } if (dataType == typeof(bool)) { BlittableBoolean b = Marshal.PtrToStructure <BlittableBoolean>(dataPtr); Marshal.FreeCoTaskMem(dataPtr); result = (bool)b; return(true); } result = Marshal.PtrToStructure(dataPtr, dataType); Marshal.FreeCoTaskMem(dataPtr); return(true); }
public void Put(string forecast) { var backendUrlVariableName = "backendUrl"; _policyBuilder .Inbound(builder => builder .Base() .SetVariable(backendUrlVariableName, NamedValue.Get("Backend")) .Create() ) .Backend(builder => builder .SetBackendService(ContextVariable.GetAsString(backendUrlVariableName)) .Base() .Create()) .Outbound() .OnError(); }
public void OnCountChanged(int prevCount) { if (count > prevCount) { // first create and add children int diff = count - prevCount; for (int i = 0; i < diff; i++) { UIElement child = application.CreateTemplate(templateSpawnId, templateContextRoot, this, scope); ContextVariable <int> indexVariable = ContextVariable <int> .Create(indexVarId, "index", prevCount + i); child.bindingNode.CreateLocalContextVariable(indexVariable); } } else { int diff = prevCount - count; for (int i = 0; i < diff; i++) { children.array[children.size - 1].Destroy(); } } }
public void GetBodyAsStringGeneratesCorrectPolicy(string variableName, bool strict, string expected) { var policy = ContextVariable.GetBodyAsString(variableName, strict); policy.Should().Be(expected); }
public void GetAsBooleanGeneratesCorrectPolicy(string variableName, bool strict, bool inline, string expected) { var policy = ContextVariable.GetAsBoolean(variableName, strict, inline); policy.Should().Be(expected); }
public void GetStatusReasonGeneratesCorrectPolicy(string variableName, bool inline, string expected) { var policy = ContextVariable.GetStatusReason(variableName, inline); policy.Should().Be(expected); }
public void GetBodyGeneratesCorrectPolicy(string variableName, string expected) { var policy = ContextVariable.GetBody(variableName); policy.Should().Be(expected); }
public void ContainsGeneratesCorrectPolicy(string variableName, string expected) { var policy = ContextVariable.Contains(variableName); policy.Should().Be(expected); }