mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
This commit uses psl-monad branch source-depot 7209cb9 And corresponds to [SD:688741]
67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
/*============================================================================
|
|
* Copyright (C) Microsoft Corporation, All rights reserved.
|
|
*============================================================================
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Management.Infrastructure.Generic;
|
|
using Microsoft.Management.Infrastructure.Options.Internal;
|
|
|
|
namespace Microsoft.Management.Infrastructure.Internal.Data
|
|
{
|
|
internal class CimClassPropertiesCollection : CimReadOnlyKeyedCollection<CimPropertyDeclaration>
|
|
{
|
|
private readonly Native.ClassHandle classHandle;
|
|
|
|
internal CimClassPropertiesCollection(Native.ClassHandle classHandle)
|
|
{
|
|
this.classHandle = classHandle;
|
|
}
|
|
|
|
public override int Count
|
|
{
|
|
get
|
|
{
|
|
int count;
|
|
Native.MiResult result = Native.ClassMethods.GetElementCount(
|
|
this.classHandle,
|
|
out count);
|
|
CimException.ThrowIfMiResultFailure(result);
|
|
return count;
|
|
}
|
|
}
|
|
|
|
public override CimPropertyDeclaration this[string propertyName]
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrWhiteSpace(propertyName))
|
|
{
|
|
throw new ArgumentNullException("propertyName");
|
|
}
|
|
|
|
int index;
|
|
Native.MiResult result = Native.ClassMethods.GetElement_GetIndex(this.classHandle, propertyName, out index);
|
|
switch (result)
|
|
{
|
|
case Native.MiResult.NO_SUCH_PROPERTY:
|
|
return null;
|
|
|
|
default:
|
|
CimException.ThrowIfMiResultFailure(result);
|
|
return new CimClassPropertyOfClass(this.classHandle, index);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override IEnumerator<CimPropertyDeclaration> GetEnumerator()
|
|
{
|
|
int count = this.Count;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
yield return new CimClassPropertyOfClass(this.classHandle, i);
|
|
}
|
|
}
|
|
}
|
|
} |