コード例 #1
0
        internal static void PrependPropertyValue(
            PSObject maml1,
            PSObject maml2,
            string[] path,
            bool shouldOverride)
        {
            List <object>  objectList   = new List <object>();
            PSPropertyInfo properyInfo1 = MamlUtil.GetProperyInfo(maml2, path);

            if (properyInfo1.Value is PSObject[])
            {
                objectList.AddRange((IEnumerable <object>)(PSObject[]) properyInfo1.Value);
            }
            else
            {
                objectList.Add(properyInfo1.Value);
            }
            MamlUtil.EnsurePropertyInfoPathExists(maml1, path);
            PSPropertyInfo properyInfo2 = MamlUtil.GetProperyInfo(maml1, path);

            if (!shouldOverride)
            {
                if (properyInfo2.Value is PSObject[])
                {
                    objectList.AddRange((IEnumerable <object>)(PSObject[]) properyInfo2.Value);
                }
                else
                {
                    objectList.Add(properyInfo2.Value);
                }
            }
            if (objectList.Count == 1)
            {
                properyInfo2.Value = objectList[0];
            }
            else
            {
                if (objectList.Count < 2)
                {
                    return;
                }
                properyInfo2.Value = (object)objectList.ToArray();
            }
        }
コード例 #2
0
        internal static void OverrideParameters(PSObject maml1, PSObject maml2)
        {
            string[] path = new string[2]
            {
                "Parameters",
                "Parameter"
            };
            List <PSObject> psObjectList1 = new List <PSObject>();
            PSPropertyInfo  properyInfo1  = MamlUtil.GetProperyInfo(maml2, path);

            if (properyInfo1.Value is PSObject[])
            {
                psObjectList1.AddRange((IEnumerable <PSObject>)(PSObject[]) properyInfo1.Value);
            }
            else
            {
                psObjectList1.Add(PSObject.AsPSObject(properyInfo1.Value));
            }
            MamlUtil.EnsurePropertyInfoPathExists(maml1, path);
            PSPropertyInfo  properyInfo2  = MamlUtil.GetProperyInfo(maml1, path);
            List <PSObject> psObjectList2 = new List <PSObject>();

            if (properyInfo2.Value is PSObject[])
            {
                psObjectList2.AddRange((IEnumerable <PSObject>)(PSObject[]) properyInfo2.Value);
            }
            else
            {
                psObjectList2.Add(PSObject.AsPSObject(properyInfo2.Value));
            }
            for (int index = 0; index < psObjectList1.Count; ++index)
            {
                string result1;
                if (LanguagePrimitives.TryConvertTo <string>(psObjectList1[index].Properties["Name"].Value, out result1))
                {
                    bool flag = false;
                    foreach (PSObject psObject in psObjectList2)
                    {
                        string result2;
                        if (LanguagePrimitives.TryConvertTo <string>(psObject.Properties["Name"].Value, out result2) && result2.Equals(result1, StringComparison.OrdinalIgnoreCase))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        psObjectList2.Add(psObjectList1[index]);
                    }
                }
            }
            if (psObjectList2.Count == 1)
            {
                properyInfo2.Value = (object)psObjectList2[0];
            }
            else
            {
                if (psObjectList2.Count < 2)
                {
                    return;
                }
                properyInfo2.Value = (object)psObjectList2.ToArray();
            }
        }