internal IntPtr ToNative(PinCollection pinCollection)
        {
            var nativeDescription = new NativeTypes.FABRIC_APPLICATION_UPGRADE_DESCRIPTION();

            nativeDescription.ApplicationName = pinCollection.AddObject(this.ApplicationName);
            nativeDescription.TargetApplicationTypeVersion = pinCollection.AddBlittable(this.TargetApplicationTypeVersion);

            if (this.ApplicationParameters.Count != 0)
            {
                var applicationParameterList = new ApplicationParameterList(this.ApplicationParameters);
                nativeDescription.ApplicationParameters = applicationParameterList.ToNative(pinCollection);
            }
            else
            {
                nativeDescription.ApplicationParameters = IntPtr.Zero;
            }

            var rollingUpgradePolicyDescription = this.UpgradePolicyDescription as RollingUpgradePolicyDescription;

            if (rollingUpgradePolicyDescription != null)
            {
                nativeDescription.UpgradeKind = NativeTypes.FABRIC_APPLICATION_UPGRADE_KIND.FABRIC_APPLICATION_UPGRADE_KIND_ROLLING;
                nativeDescription.UpgradePolicyDescription = rollingUpgradePolicyDescription.ToNative(pinCollection);
            }
            else
            {
                throw new ArgumentException("description.UpgradePolicyDescription");
            }

            return(pinCollection.AddBlittable(nativeDescription));
        }
        internal IntPtr ToNative(PinCollection pinCollection)
        {
            var nativeDescription = new NativeTypes.FABRIC_APPLICATION_DESCRIPTION();

            nativeDescription.ApplicationName        = pinCollection.AddObject(this.ApplicationName);
            nativeDescription.ApplicationTypeName    = pinCollection.AddObject(this.ApplicationTypeName);
            nativeDescription.ApplicationTypeVersion = pinCollection.AddObject(this.ApplicationTypeVersion);

            if (this.ApplicationParameters.Count != 0)
            {
                var applicationParameterList = new ApplicationParameterList(this.ApplicationParameters);
                nativeDescription.ApplicationParameters = applicationParameterList.ToNative(pinCollection);
            }
            else
            {
                nativeDescription.ApplicationParameters = IntPtr.Zero;
            }

            if (this.MaximumNodes > 0 || this.MinimumNodes > 0 || this.Metrics != null)
            {
                var nativeDescriptionEx1 = new NativeTypes.FABRIC_APPLICATION_DESCRIPTION_EX1();
                var nativeApplicationCapacityDescription = new NativeTypes.FABRIC_APPLICATION_CAPACITY_DESCRIPTION();
                nativeApplicationCapacityDescription.MaximumNodes = checked ((uint)this.MaximumNodes);
                nativeApplicationCapacityDescription.MinimumNodes = checked ((uint)this.MinimumNodes);

                var nativeMetricsList = new NativeTypes.FABRIC_APPLICATION_METRIC_LIST();
                if (null != this.Metrics)
                {
                    nativeMetricsList.Count = (uint)this.Metrics.Count;
                    if (this.Metrics.Count > 0)
                    {
                        var nativeMetricsArray = new NativeTypes.FABRIC_APPLICATION_METRIC_DESCRIPTION[this.Metrics.Count];
                        for (int i = 0; i < this.Metrics.Count; i++)
                        {
                            Metrics[i].ToNative(pinCollection, ref nativeMetricsArray[i]);
                        }

                        nativeMetricsList.Metrics = pinCollection.AddBlittable(nativeMetricsArray);
                    }
                    else
                    {
                        nativeMetricsList.Metrics = IntPtr.Zero;
                    }
                }
                else
                {
                    nativeMetricsList.Count   = 0;
                    nativeMetricsList.Metrics = IntPtr.Zero;
                }
                nativeApplicationCapacityDescription.Metrics = pinCollection.AddBlittable(nativeMetricsList);

                nativeDescriptionEx1.ApplicationCapacity = pinCollection.AddBlittable(nativeApplicationCapacityDescription);

                nativeDescription.Reserved = pinCollection.AddBlittable(nativeDescriptionEx1);
            }

            return(pinCollection.AddBlittable(nativeDescription));
        }