本文整理汇总了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;
}
示例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);
}
}
}
示例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;
}