public void GetProperties_Returns_PropertyHelpers() { // Arrange MyProps props = new MyProps { IntProp = 42, StringProp = "abc" }; // Act PropertyHelper[] properties = PropertyHelper.GetProperties(props); // Assert Assert.Equal(2, properties.Length); Assert.Collection(properties, e => { Assert.Equal("IntProp", e.Name); Assert.Equal(42, e.GetValue(props)); }, e => { Assert.Equal("StringProp", e.Name); Assert.Equal("abc", e.GetValue(props)); }); }
public void Setter_ThrowsArgumentNull_Instance() { // Arrange & Act & Assert var mine = new MyProps(); var accessor = new FastPropertyAccessor <MyProps>(mine.GetType().GetProperty("StringProp")); ExceptionAssert.ThrowsArgumentNull(() => accessor.SetValue(null, 5), "instance"); }
public void CleanUpNativeData(IntPtr pNativeData) { // Clear() either pops an entry, or clears // the values for the next call. MyProps t = MyProps.GetTop(m_Index); t.Clear(m_Index); }
public static MyProps AddLayer(int iIndex) { MyProps p = new MyProps(); p.m_Parent = m_CurrentProps[iIndex]; m_CurrentProps[iIndex] = p; return(p); }
void Awake() { mNetworkManager = (NetworkManager)FindObjectOfType(typeof(NetworkManager)); mDialogueManager = (DialogueManager)FindObjectOfType(typeof(DialogueManager)); mCountdown = (Countdown)FindObjectOfType(typeof(Countdown)); mAvailablePropsList = (dfListbox)FindObjectOfType(typeof(dfListbox)); mMyProps = (MyProps)FindObjectOfType(typeof(MyProps)); mGame = (Game)FindObjectOfType(typeof(Game)); }
public void GetterWorksForReferenceType() { // Arrange var mine = new MyProps(); var accessor = new FastPropertyAccessor<MyProps>(mine.GetType().GetProperty("StringProp")); mine.StringProp = "*4"; // Assert Assert.Equal("*4", accessor.GetValue(mine)); }
public void GetterWorksForValueType() { // Arrange var mine = new MyProps(); var accessor = new FastPropertyAccessor<MyProps>(mine.GetType().GetProperty("IntProp")); mine.IntProp = 4; // Assert Assert.Equal(4, accessor.GetValue(mine)); }
public void GetterWorksForReferenceType() { // Arrange var mine = new MyProps(); var accessor = new FastPropertyAccessor <MyProps>(mine.GetType().GetProperty("StringProp")); mine.StringProp = "*4"; // Assert Assert.Equal("*4", accessor.GetValue(mine)); }
public static void SplitLayer(int iIndex) { MyProps t = AddLayer(iIndex); MyProps p = t.m_Parent; t.m_InProcsss = 1; t.m_ptr = p.m_ptr; t.m_obj = p.m_obj; p.m_InProcsss = 1; }
public void GetterWorksForValueType() { // Arrange var mine = new MyProps(); var accessor = new FastPropertyAccessor <MyProps>(mine.GetType().GetProperty("IntProp")); mine.IntProp = 4; // Assert Assert.Equal(4, accessor.GetValue(mine)); }
public void Copy_ThrowsArgumentNull_FromAndTo() { // Arrange var accessor = new FastPropertyAccessor <MyProps>(typeof(MyProps).GetProperty("StringProp")); // Act & Assert ExceptionAssert.ThrowsArgumentNull(() => accessor.Copy(null, null), "from"); // Act & Assert MyProps mine = new MyProps(); ExceptionAssert.ThrowsArgumentNull(() => accessor.Copy(mine, null), "to"); }
public static MyProps GetTop(int iIndex) { // If the member hasn't been initialized, do it now. And no, we can't // do this in the PVMarshaler constructor, since the constructor may // have been called on a different thread. if (m_CurrentProps == null) { m_CurrentProps = new MyProps[MaxArgs]; for (int x = 0; x < MaxArgs; x++) { m_CurrentProps[x] = new MyProps(); } } return(m_CurrentProps[iIndex]); }
public void ShouldCreateTreeWithProperties() { MyProps props = null; try { props = new DependencyInjector().CreateAndInjectDependencies <MyProps>().rootBean; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); Assert.Fail(); } Assert.IsNotNull(props); Assert.IsNotNull(props?.GetResults().MyProp); }
public void CleanUpManagedData(object ManagedObj) { // Note that if there are nested calls, one of the Cleanup*Data // methods will be called at the end of each pair: // MarshalNativeToManaged // MarshalManagedToNative // CleanUpManagedData // // or for recursion: // // MarshalManagedToNative 1 // MarshalNativeToManaged 2 // MarshalManagedToNative 2 // CleanUpManagedData 2 // MarshalNativeToManaged 1 // CleanUpNativeData 1 // Clear() either pops an entry, or clears // the values for the next call. MyProps t = MyProps.GetTop(m_Index); t.Clear(m_Index); }
void Awake() { mMyProps = (MyProps)FindObjectOfType(typeof(MyProps)); uImage = (dfTextureSprite)GetComponentInChildren(typeof(dfTextureSprite)); }
void Awake() { mNetworkManager = (NetworkManager) FindObjectOfType(typeof(NetworkManager)); mDialogueManager = (DialogueManager) FindObjectOfType(typeof(DialogueManager)); mCountdown = (Countdown) FindObjectOfType(typeof(Countdown)); mAvailablePropsList = (dfListbox) FindObjectOfType(typeof(dfListbox)); mMyProps = (MyProps) FindObjectOfType(typeof(MyProps)); mGame = (Game) FindObjectOfType(typeof(Game)); }
public object MarshalNativeToManaged(IntPtr pNativeData) { MyProps t = MyProps.GetTop(m_Index); switch (t.GetStage()) { case 0: { // We are just starting a "Unmanaged calling managed" // call. // Caller should have cleared variant before calling // us. Might be acceptable for types *other* than // IUnknown, String, Blob and StringArray, but it is // still bad design. We're checking for it, but we // work around it. // Read the 16bit VariantType. // Create an empty managed PropVariant without using // pNativeData. t.m_obj = new PropVariant(); // Save the pointer for use in MarshalManagedToNative. t.m_ptr = pNativeData; break; } case 1: { if (t.m_ptr != pNativeData) { // If we get here, we have already received a call // to MarshalManagedToNative where we created an // IntPtr and stored it into t.m_ptr. But the // value we just got passed here isn't the same // one. Therefore instead of being the second half // of a "Managed calling unmanaged" (as m_InProcsss // led us to believe) this is really the first half // of a nested "Unmanaged calling managed" (see // Recursion in the comments at the top of this // class). Add another layer. MyProps.AddLayer(m_Index); // Try this call again now that we have fixed // m_CurrentProps. return(MarshalNativeToManaged(pNativeData)); } // This is (probably) the second half of "Managed // calling unmanaged." However, it could be the first // half of a nested usage of PropVariants. If it is a // nested, we'll eventually figure that out in case 2. // Copy the data from the native pointer into the // managed object that we received in // MarshalManagedToNative. Marshal.PtrToStructure(pNativeData, t.m_obj); break; } case 2: { // Apparently this is 'part 3' of a 2 part call. Which // means we are doing a nested call. Normally we would // catch the fact that this is a nested call with the // (t.m_ptr != pNativeData) check above. However, if // the same PropVariant instance is being passed thru // again, we end up here. So, add a layer. MyProps.SplitLayer(m_Index); // Try this call again now that we have fixed // m_CurrentProps. return(MarshalNativeToManaged(pNativeData)); } default: { Environment.FailFast("Something horrible has " + "happened, probaby due to " + "marshaling of nested " + "PropVariant calls."); break; } } t.StageComplete(); return(t.m_obj); }
public IntPtr MarshalManagedToNative(object managedObj) { MyProps t = MyProps.GetTop(m_Index); switch (t.GetStage()) { case 0: { // We are just starting a "Managed calling unmanaged" // call. // Cast the object back to a PropVariant and save it // for use in MarshalNativeToManaged. t.m_obj = managedObj as PropVariant; // This could happen if (somehow) managedObj isn't a // PropVariant. During normal marshaling, the custom // marshaler doesn't get called if the parameter is // null. // Release any memory currently allocated in the // PropVariant. In theory, the (managed) caller // should have done this before making the call that // got us here, but .Net programmers don't generally // think that way. To avoid any leaks, do it for them. t.m_obj.Clear(); // Create an appropriately sized buffer (varies from // x86 to x64). int iSize = GetNativeDataSize(); t.m_ptr = t.Alloc(iSize); // Copy in the (empty) PropVariant. In theory we could // just zero out the first 2 bytes (the VariantType), // but since PropVariantClear wipes the whole struct, // that's what we do here to be safe. Marshal.StructureToPtr(t.m_obj, t.m_ptr, false); break; } case 1: { if (!System.Object.ReferenceEquals(t.m_obj, managedObj)) { // If we get here, we have already received a call // to MarshalNativeToManaged where we created a // PropVariant and stored it into t.m_obj. But // the object we just got passed here isn't the // same one. Therefore instead of being the second // half of an "Unmanaged calling managed" (as // m_InProcsss led us to believe), this is really // the first half of a nested "Managed calling // unmanaged" (see Recursion in the comments at the // top of this class). Add another layer. MyProps.AddLayer(m_Index); // Try this call again now that we have fixed // m_CurrentProps. return(MarshalManagedToNative(managedObj)); } // This is (probably) the second half of "Unmanaged // calling managed." However, it could be the first // half of a nested usage of PropVariants. If it is a // nested, we'll eventually figure that out in case 2. // Copy the data from the managed object into the // native pointer that we received in // MarshalNativeToManaged. Marshal.StructureToPtr(t.m_obj, t.m_ptr, false); break; } case 2: { // Apparently this is 'part 3' of a 2 part call. Which // means we are doing a nested call. Normally we would // catch the fact that this is a nested call with the // ReferenceEquals check above. However, if the same // PropVariant instance is being passed thru again, we // end up here. // So, add a layer. MyProps.SplitLayer(m_Index); // Try this call again now that we have fixed // m_CurrentProps. return(MarshalManagedToNative(managedObj)); } default: { Environment.FailFast("Something horrible has " + "happened, probaby due to " + "marshaling of nested " + "PropVariant calls."); break; } } t.StageComplete(); return(t.m_ptr); }