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


C# PSObject.AddOrSetProperty方法代码示例

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


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

示例1: WrapOutputInPSObject

        /// <summary>
        /// Wraps the item in a PSObject and attaches some notes to the
        /// object that deal with path information.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        private PSObject WrapOutputInPSObject(
            FileInfo item,
            string path)
        {
            PSObject result = new PSObject(item);

            // Now get the parent path and child name
            if (path != null)
            {
                // Get the parent path
                string parentPath = Directory.GetParent(path).FullName;
                result.AddOrSetProperty("PSParentPath", parentPath);

                // Get the child name
                string childName = item.Name;
                result.AddOrSetProperty("PSChildName", childName);
            }
            return result;
        }
开发者ID:dfinke,项目名称:powershell,代码行数:26,代码来源:GetClipboardCommand.cs

示例2: TestGetProperty

        public void TestGetProperty()
        {
			FileSystemProvider fileSystemProvider = new FileSystemProvider();
			ProviderInfo providerInfoToSet = GetProvider();
			fileSystemProvider.SetProviderInformation(providerInfoToSet);
			fileSystemProvider.Context = new CmdletProviderContext(GetExecutionContext());
			PSObject pso=new PSObject();
			pso.AddOrSetProperty("IsReadOnly",false);
			fileSystemProvider.SetProperty(testPath, pso);
			fileSystemProvider.GetProperty(testPath, new Collection<string>(){"IsReadOnly"});
			FileInfo fileSystemObject1 = new FileInfo(testPath);
			PSObject psobject1=PSObject.AsPSObject(fileSystemObject1);
			foreach(PSPropertyInfo property in psobject1.Properties)
			{
				if(property.Name == "IsReadOnly")
				{
					Assert.Equal(property.Value,false);
				}
			}
        }
开发者ID:40a,项目名称:PowerShell,代码行数:20,代码来源:test_FileSystemProvider.cs

示例3: WrapOutputInPSObject

 private PSObject WrapOutputInPSObject(object item, string path)
 {
     if (item == null)
     {
         throw PSTraceSource.NewArgumentNullException("item");
     }
     PSObject obj2 = new PSObject(item);
     PSObject obj3 = item as PSObject;
     if (obj3 != null)
     {
         obj2.InternalTypeNames = new ConsolidatedString(obj3.InternalTypeNames);
     }
     string providerQualifiedPath = LocationGlobber.GetProviderQualifiedPath(path, this.ProviderInfo);
     obj2.AddOrSetProperty("PSPath", providerQualifiedPath);
     providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSPath", providerQualifiedPath });
     NavigationCmdletProvider provider = this as NavigationCmdletProvider;
     if ((provider != null) && (path != null))
     {
         string str2 = null;
         if (this.PSDriveInfo != null)
         {
             str2 = provider.GetParentPath(path, this.PSDriveInfo.Root, this.Context);
         }
         else
         {
             str2 = provider.GetParentPath(path, string.Empty, this.Context);
         }
         string str3 = string.Empty;
         if (!string.IsNullOrEmpty(str2))
         {
             str3 = LocationGlobber.GetProviderQualifiedPath(str2, this.ProviderInfo);
         }
         obj2.AddOrSetProperty("PSParentPath", str3);
         providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSParentPath", str3 });
         string childName = provider.GetChildName(path, this.Context);
         obj2.AddOrSetProperty("PSChildName", childName);
         providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSChildName", childName });
     }
     if (this.PSDriveInfo != null)
     {
         obj2.AddOrSetProperty(this.PSDriveInfo.GetNotePropertyForProviderCmdlets("PSDrive"));
         providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSDrive", this.PSDriveInfo });
     }
     obj2.AddOrSetProperty(this.ProviderInfo.GetNotePropertyForProviderCmdlets("PSProvider"));
     providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSProvider", this.ProviderInfo });
     return obj2;
 }
开发者ID:nickchal,项目名称:pash,代码行数:47,代码来源:CmdletProvider.cs


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