当前位置: 首页>>代码示例>>C#>>正文


C# CmdletProvider.IsFilterSet方法代码示例

本文整理汇总了C#中System.Management.Automation.Provider.CmdletProvider.IsFilterSet方法的典型用法代码示例。如果您正苦于以下问题:C# CmdletProvider.IsFilterSet方法的具体用法?C# CmdletProvider.IsFilterSet怎么用?C# CmdletProvider.IsFilterSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.Provider.CmdletProvider的用法示例。


在下文中一共展示了CmdletProvider.IsFilterSet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoManualGetChildItems

 private void DoManualGetChildItems(CmdletProvider providerInstance, string path, bool recurse, CmdletProviderContext context, bool skipIsItemContainerCheck = false)
 {
     Collection<WildcardPattern> patterns = SessionStateUtilities.CreateWildcardsFromStrings(context.Include, WildcardOptions.IgnoreCase);
     Collection<WildcardPattern> collection2 = SessionStateUtilities.CreateWildcardsFromStrings(context.Exclude, WildcardOptions.IgnoreCase);
     if (skipIsItemContainerCheck || this.IsItemContainer(providerInstance, path, context))
     {
         CmdletProviderContext context2 = new CmdletProviderContext(context);
         Collection<PSObject> accumulatedObjects = null;
         Dictionary<string, bool> dictionary = null;
         try
         {
             this.GetChildNames(providerInstance, path, recurse ? ReturnContainers.ReturnAllContainers : ReturnContainers.ReturnMatchingContainers, context2);
             context2.WriteErrorsToContext(context);
             accumulatedObjects = context2.GetAccumulatedObjects();
             if (recurse && providerInstance.IsFilterSet())
             {
                 context2.RemoveStopReferral();
                 context2 = new CmdletProviderContext(context);
                 Collection<PSObject> collection4 = new Collection<PSObject>();
                 dictionary = new Dictionary<string, bool>();
                 this.GetChildNames(providerInstance, path, ReturnContainers.ReturnMatchingContainers, context2);
                 foreach (PSObject obj2 in context2.GetAccumulatedObjects())
                 {
                     string baseObject = obj2.BaseObject as string;
                     if (baseObject != null)
                     {
                         dictionary[baseObject] = true;
                     }
                 }
             }
         }
         finally
         {
             context2.RemoveStopReferral();
         }
         for (int i = 0; i < accumulatedObjects.Count; i++)
         {
             if (context.Stopping)
             {
                 return;
             }
             string child = accumulatedObjects[i].BaseObject as string;
             if (child != null)
             {
                 string str3 = this.MakePath(providerInstance, path, child, context);
                 if (str3 != null)
                 {
                     if (SessionStateUtilities.MatchesAnyWildcardPattern(child, patterns, true) && !SessionStateUtilities.MatchesAnyWildcardPattern(child, collection2, false))
                     {
                         bool flag2 = true;
                         if (dictionary != null)
                         {
                             bool flag3 = false;
                             flag2 = dictionary.TryGetValue(child, out flag3);
                         }
                         if (flag2)
                         {
                             this.GetItemPrivate(providerInstance, str3, context);
                         }
                     }
                     if (this.IsItemContainer(providerInstance, str3, context) && recurse)
                     {
                         if (context.Stopping)
                         {
                             return;
                         }
                         this.DoManualGetChildItems(providerInstance, str3, recurse, context, true);
                     }
                 }
             }
         }
     }
     else
     {
         string text = path;
         text = this.GetChildName(providerInstance, path, context, true);
         if (SessionStateUtilities.MatchesAnyWildcardPattern(text, patterns, true) && !SessionStateUtilities.MatchesAnyWildcardPattern(text, collection2, false))
         {
             this.GetItemPrivate(providerInstance, path, context);
         }
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:82,代码来源:SessionStateInternal.cs

示例2: ProcessPathItems


//.........这里部分代码省略.........

            Collection<WildcardPattern> excludeMatcher =
                SessionStateUtilities.CreateWildcardsFromStrings(
                    context.Exclude,
                    WildcardOptions.IgnoreCase);

            // If the item is a container we have to filter its children
            // Use a hint + lazy evaluation to skip a container check

            if (skipIsItemContainerCheck || IsItemContainer(providerInstance, path, context))
            {
                CmdletProviderContext newContext =
                    new CmdletProviderContext(context);

                Collection<PSObject> childNameObjects = null;
                System.Collections.Generic.Dictionary<string, bool> filteredChildNameDictionary = null;

                try
                {
                    // Get all the child names
                    GetChildNames(
                        providerInstance,
                        path,
                        (recurse) ? ReturnContainers.ReturnAllContainers : ReturnContainers.ReturnMatchingContainers,
                        newContext);
                    newContext.WriteErrorsToContext(context);
                    childNameObjects = newContext.GetAccumulatedObjects();


                    // The code above initially retrieves all of the containers so that it doesn't limit the recursion,
                    // but then emits the non-matching container further down. The public API doesn't support a way to
                    // differentiate the two, so we need to do a diff.
                    // So if there was a filter, do it again to get the fully filtered items.
                    if (recurse && (providerInstance.IsFilterSet()))
                    {
                        newContext.RemoveStopReferral();
                        newContext = new CmdletProviderContext(context);
                        filteredChildNameDictionary = new System.Collections.Generic.Dictionary<string, bool>();

                        GetChildNames(
                            providerInstance,
                            path,
                            ReturnContainers.ReturnMatchingContainers,
                            newContext);
                        var filteredChildNameObjects = newContext.GetAccumulatedObjects();

                        foreach (PSObject filteredChildName in filteredChildNameObjects)
                        {
                            string filteredName = filteredChildName.BaseObject as string;
                            if (filteredName != null)
                            {
                                filteredChildNameDictionary[filteredName] = true;
                            }
                        }
                    }
                }
                finally
                {
                    newContext.RemoveStopReferral();
                }

                // Now loop through all the child objects matching the filters and recursing
                // into containers
                for (int index = 0; index < childNameObjects.Count; ++index)
                {
                    // Making sure to obey the StopProcessing.
开发者ID:dfinke,项目名称:powershell,代码行数:67,代码来源:SessionStateContainer.cs


注:本文中的System.Management.Automation.Provider.CmdletProvider.IsFilterSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。