new internal static unsafe MonitoredRollingFabricUpgradePolicyDescription FromNative(IntPtr policyPtr)
        {
            if (policyPtr == IntPtr.Zero)
            {
                return(null);
            }

            var castedPtr = (NativeTypes.FABRIC_ROLLING_UPGRADE_POLICY_DESCRIPTION *)policyPtr;

            var monitoringPolicy = new MonitoredRollingFabricUpgradePolicyDescription();

            if (castedPtr->Reserved != IntPtr.Zero)
            {
                var castedEx1Ptr = (NativeTypes.FABRIC_ROLLING_UPGRADE_POLICY_DESCRIPTION_EX1 *)castedPtr->Reserved;
                if (castedEx1Ptr->MonitoringPolicy != IntPtr.Zero)
                {
                    monitoringPolicy.MonitoringPolicy = RollingUpgradeMonitoringPolicy.FromNative(castedEx1Ptr->MonitoringPolicy);
                }

                if (castedEx1Ptr->HealthPolicy != IntPtr.Zero)
                {
                    monitoringPolicy.HealthPolicy = ClusterHealthPolicy.FromNative(castedEx1Ptr->HealthPolicy);
                }

                if (castedEx1Ptr->Reserved != IntPtr.Zero)
                {
                    var castedEx2Ptr = (NativeTypes.FABRIC_ROLLING_UPGRADE_POLICY_DESCRIPTION_EX2 *)castedEx1Ptr->Reserved;
                    monitoringPolicy.EnableDeltaHealthEvaluation = NativeTypes.FromBOOLEAN(castedEx2Ptr->EnableDeltaHealthEvaluation);

                    if (castedEx2Ptr->UpgradeHealthPolicy != IntPtr.Zero)
                    {
                        monitoringPolicy.UpgradeHealthPolicy = ClusterUpgradeHealthPolicy.FromNative(castedEx2Ptr->UpgradeHealthPolicy);
                    }

                    if (castedEx2Ptr->Reserved != IntPtr.Zero)
                    {
                        var castedEx3Ptr = (NativeTypes.FABRIC_ROLLING_UPGRADE_POLICY_DESCRIPTION_EX3 *)castedEx2Ptr->Reserved;

                        if (castedEx3Ptr->ApplicationHealthPolicyMap != IntPtr.Zero)
                        {
                            monitoringPolicy.ApplicationHealthPolicyMap.FromNative(castedEx3Ptr->ApplicationHealthPolicyMap);
                        }
                    }
                }
            }

            monitoringPolicy.FromNativeHelper(policyPtr);

            return(monitoringPolicy);
        }
        internal static unsafe ChaosParameters CreateFromNative(IntPtr nativeRaw)
        {
            NativeTypes.FABRIC_CHAOS_PARAMETERS native = *(NativeTypes.FABRIC_CHAOS_PARAMETERS *)nativeRaw;

            TimeSpan maxClusterStabilizationTimeout =
                TimeSpan.FromSeconds(native.MaxClusterStabilizationTimeoutInSeconds);

            var maxConcurrentFaults = native.MaxConcurrentFaults;

            TimeSpan waitTimeBetweenIterations = TimeSpan.FromSeconds(native.WaitTimeBetweenIterationsInSeconds);

            TimeSpan waitTimeBetweenFaults = TimeSpan.FromSeconds(native.WaitTimeBetweenFaultsInSeconds);

            TimeSpan timeToRun = TimeSpan.FromSeconds(native.TimeToRunInSeconds);

            var enabledMoveReplicaFaults = NativeTypes.FromBOOLEAN(native.EnableMoveReplicaFaults);

            var contextMap = new Dictionary <string, string>();

            if (native.Context != IntPtr.Zero)
            {
                var nativeMapPtr = (NativeTypes.FABRIC_EVENT_CONTEXT_MAP *)native.Context;
                var bytesPerItem = Marshal.SizeOf(typeof(NativeTypes.FABRIC_EVENT_CONTEXT_MAP_ITEM));
                for (int i = 0; i < nativeMapPtr->Count; ++i)
                {
                    var nativeItemPtr    = nativeMapPtr->Items + (i * bytesPerItem);
                    var nativeMapItemPtr = (NativeTypes.FABRIC_EVENT_CONTEXT_MAP_ITEM *)nativeItemPtr;

                    contextMap.Add(
                        NativeTypes.FromNativeString(nativeMapItemPtr->Key),
                        NativeTypes.FromNativeString(nativeMapItemPtr->Value));
                }
            }

            var parameters = new ChaosParameters(
                maxClusterStabilizationTimeout,
                maxConcurrentFaults,
                enabledMoveReplicaFaults,
                timeToRun,
                contextMap,
                waitTimeBetweenIterations,
                waitTimeBetweenFaults);

            if (native.Reserved != IntPtr.Zero)
            {
                var ex1 = *((NativeTypes.FABRIC_CHAOS_PARAMETERS_EX1 *)native.Reserved);

                if (ex1.ClusterHealthPolicy != IntPtr.Zero)
                {
                    parameters.ClusterHealthPolicy = ClusterHealthPolicy.FromNative(ex1.ClusterHealthPolicy);
                }

                if (ex1.Reserved != IntPtr.Zero)
                {
                    var ex2 = *(NativeTypes.FABRIC_CHAOS_PARAMETERS_EX2 *)ex1.Reserved;
                    parameters.ChaosTargetFilter = ChaosTargetFilter.FromNative(ex2.ChaosTargetFilter);
                }
            }

            return(parameters);
        }