internal static PSMemberInfoInternalCollection <T> Match <T>(PSMemberInfoInternalCollection <T> memberList, string name, WildcardPattern nameMatch, PSMemberTypes memberTypes) where T : PSMemberInfo { PSMemberInfoInternalCollection <T> internals = new PSMemberInfoInternalCollection <T>(); if (memberList == null) { throw PSTraceSource.NewArgumentNullException("memberList"); } if (string.IsNullOrEmpty(name)) { throw PSTraceSource.NewArgumentException("name"); } if (nameMatch == null) { T member = memberList[name]; if ((member != null) && ((member.MemberType & memberTypes) != 0)) { internals.Add(member); } return(internals); } foreach (T local2 in memberList) { if (nameMatch.IsMatch(local2.Name) && ((local2.MemberType & memberTypes) != 0)) { internals.Add(local2); } } return(internals); }
private PSMemberInfoInternalCollection <T> GetIntegratedMembers( MshMemberMatchOptions matchOptions) { using (PSObject.memberResolution.TraceScope("Generating the total list of members")) { PSMemberInfoInternalCollection <T> internalCollection = new PSMemberInfoInternalCollection <T>(); PSObject particularInstance; if (this.mshOwner != null) { particularInstance = this.mshOwner; foreach (PSMemberInfo instanceMember in (PSMemberInfoCollection <PSMemberInfo>) this.mshOwner.InstanceMembers) { if (instanceMember.MatchesOptions(matchOptions) && instanceMember is T member) { internalCollection.Add(member); } } } else { particularInstance = this.memberSetOwner.instance; foreach (PSMemberInfo internalMember in (PSMemberInfoCollection <PSMemberInfo>) this.memberSetOwner.InternalMembers) { if (internalMember.MatchesOptions(matchOptions) && internalMember is T member) { internalMember.ReplicateInstance(particularInstance); internalCollection.Add(member); } } } foreach (CollectionEntry <T> collection in this.collections) { foreach (T obj in (PSMemberInfoCollection <T>)collection.GetMembers(particularInstance)) { PSMemberInfo psMemberInfo = (PSMemberInfo)internalCollection[obj.Name]; if (psMemberInfo != null) { PSObject.memberResolution.WriteLine("Member \"{0}\" of type \"{1}\" has been ignored because a member with the same name and type \"{2}\" is already present.", (object)obj.Name, (object)obj.MemberType, (object)psMemberInfo.MemberType); } else if (!obj.MatchesOptions(matchOptions)) { PSObject.memberResolution.WriteLine("Skipping hidden member \"{0}\".", (object)obj.Name); } else { T member = !collection.ShouldCloneWhenReturning ? obj : (T)obj.Copy(); if (collection.ShouldReplicateWhenReturning) { member.ReplicateInstance(particularInstance); } internalCollection.Add(member); } } } return(internalCollection); } }
protected override PSMemberInfoInternalCollection <T> GetMembers <T>( object obj) { DirectoryEntry directoryEntry = (DirectoryEntry)obj; PSMemberInfoInternalCollection <T> internalCollection = new PSMemberInfoInternalCollection <T>(); if (directoryEntry.Properties == null || directoryEntry.Properties.PropertyNames == null) { return((PSMemberInfoInternalCollection <T>)null); } int num = 0; try { num = directoryEntry.Properties.PropertyNames.Count; } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); } if (num > 0) { foreach (PropertyValueCollection property in directoryEntry.Properties) { internalCollection.Add(new PSProperty(property.PropertyName, (Adapter)this, obj, (object)property) as T); } } return(internalCollection); }
/// <summary> /// Retrieves all the members available in the object. /// The adapter implementation is encouraged to cache all properties/methods available /// in the first call to GetMember and GetMembers so that subsequent /// calls can use the cache. /// In the case of the .NET adapter that would be a cache from the .NET type to /// the public properties and fields available in that type. /// In the case of the DirectoryEntry adapter, this could be a cache of the objectClass /// to the properties available in it. /// </summary> /// <param name="obj">object to get all the member information from</param> /// <returns>all members in obj</returns> protected override PSMemberInfoInternalCollection <T> GetMembers <T>(object obj) { DirectoryEntry entry = (DirectoryEntry)obj; PSMemberInfoInternalCollection <T> members = new PSMemberInfoInternalCollection <T>(); if (entry.Properties == null || entry.Properties.PropertyNames == null) { return(null); } int countOfProperties = 0; #pragma warning disable 56500 try { countOfProperties = entry.Properties.PropertyNames.Count; } catch (Exception) // swallow all non-severe exceptions { } #pragma warning restore 56500 if (countOfProperties > 0) { foreach (PropertyValueCollection property in entry.Properties) { members.Add(new PSProperty(property.PropertyName, this, obj, property) as T); } } return(members); }
protected override void DoAddAllProperties <T>( object obj, PSMemberInfoInternalCollection <T> members) { Collection <PSAdaptedProperty> properties; try { properties = this.externalAdapter.GetProperties(obj); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); throw new ExtendedTypeSystemException("PSPropertyAdapter.GetProperties", ex, "ExtendedTypeSystem", "GetProperties", new object[1] { (object)obj.ToString() }); } if (properties == null) { throw new ExtendedTypeSystemException("PSPropertyAdapter.NullReturnValueError", (Exception)null, "ExtendedTypeSystem", "NullReturnValueError", new object[1] { (object)"PSPropertyAdapter.GetProperties" }); } foreach (PSAdaptedProperty property in properties) { this.InitializeProperty(property, obj); members.Add(property as T); } }
/// <summary> /// Retrieves all the properties available in the object. /// </summary> protected override void DoAddAllProperties <T>(object obj, PSMemberInfoInternalCollection <T> members) { Collection <PSAdaptedProperty> properties = null; try { properties = _externalAdapter.GetProperties(obj); } catch (Exception exception) { throw new ExtendedTypeSystemException( "PSPropertyAdapter.GetProperties", exception, ExtendedTypeSystem.GetProperties, obj.ToString()); } if (properties == null) { throw new ExtendedTypeSystemException( "PSPropertyAdapter.NullReturnValueError", null, ExtendedTypeSystem.NullReturnValueError, "PSPropertyAdapter.GetProperties"); } foreach (PSAdaptedProperty property in properties) { InitializeProperty(property, obj); members.Add(property as T); } }
protected override PSMemberInfoInternalCollection <T> GetMembers <T>(object obj) { DirectoryEntry entry = (DirectoryEntry)obj; PSMemberInfoInternalCollection <T> internals = new PSMemberInfoInternalCollection <T>(); if ((entry.Properties == null) || (entry.Properties.PropertyNames == null)) { return(null); } int count = 0; try { count = entry.Properties.PropertyNames.Count; } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); } if (count > 0) { int i = 0; string[] pArray = entry.Properties.PropertyNames.OfType <string>().ToArray(); foreach (PropertyValueCollection values in entry.Properties) { string propertyName = pArray[i]; internals.Add(new PSProperty(propertyName, this, obj, values) as T); i++; } } return(internals); }
protected override PSMemberInfoInternalCollection <T> GetMembers <T>(object obj) { PSMemberInfoInternalCollection <T> members = new PSMemberInfoInternalCollection <T>(); if (typeof(T).IsAssignableFrom(typeof(PSProperty))) { this.DoAddAllProperties <T>(obj, members); } PSObject.dotNetInstanceAdapter.AddAllMethods <T>(obj, members, true); if (DotNetAdapter.IsTypeParameterizedProperty(typeof(T))) { PSMemberInfoInternalCollection <PSParameterizedProperty> internals2 = new PSMemberInfoInternalCollection <PSParameterizedProperty>(); PSObject.dotNetInstanceAdapter.AddAllProperties <PSParameterizedProperty>(obj, internals2, true); foreach (PSParameterizedProperty property in internals2) { try { members.Add(property as T); } catch (ExtendedTypeSystemException) { } } } return(members); }
protected override void AddAllProperties <T>(ManagementBaseObject wmiObject, PSMemberInfoInternalCollection <T> members) { if (wmiObject.SystemProperties != null) { foreach (PropertyData data in wmiObject.SystemProperties) { members.Add(new PSProperty(data.Name, this, wmiObject, data) as T); } } }
protected override PSMemberInfoInternalCollection <T> GetMembers <T>( object obj) { using (ComAdapter.tracer.TraceMethod()) { ComTypeInfo typeInfo = this.GetTypeInfo(); PSMemberInfoInternalCollection <T> internalCollection = new PSMemberInfoInternalCollection <T>(); if (typeInfo != null) { bool flag1 = typeof(T).IsAssignableFrom(typeof(PSProperty)); bool flag2 = typeof(T).IsAssignableFrom(typeof(PSParameterizedProperty)); if (flag1 || flag2) { foreach (ComProperty comProperty in typeInfo.Properties.Values) { if (comProperty.IsParameterized) { if (flag2) { internalCollection.Add(new PSParameterizedProperty(comProperty.Name, (Adapter)this, obj, (object)comProperty) as T); } } else if (flag1) { internalCollection.Add(new PSProperty(comProperty.Name, (Adapter)this, obj, (object)comProperty) as T); } } } if (typeof(T).IsAssignableFrom(typeof(PSMethod))) { foreach (ComMethod comMethod in typeInfo.Methods.Values) { PSMethod psMethod = new PSMethod(comMethod.Name, (Adapter)this, obj, (object)comMethod); if (!internalCollection.hashedMembers.Contains((object)comMethod.Name)) { internalCollection.Add(psMethod as T); } } } } return(internalCollection); } }
private PSMemberInfoInternalCollection<PSMemberInfo> GetInternalMembersFromAdapted() { PSMemberInfoInternalCollection<PSMemberInfo> internals = new PSMemberInfoInternalCollection<PSMemberInfo>(); if (this.psObject.isDeserialized) { if (this.psObject.adaptedMembers != null) { foreach (PSMemberInfo info in this.psObject.adaptedMembers) { internals.Add(info.Copy()); } } return internals; } foreach (PSMemberInfo info2 in this.psObject.InternalAdapter.BaseGetMembers<PSMemberInfo>(this.psObject.ImmediateBaseObject)) { internals.Add(info2.Copy()); } return internals; }
/// <summary> /// Retrieves all the members available in the object. /// The adapter implementation is encouraged to cache all properties/methods available /// in the first call to GetMember and GetMembers so that subsequent /// calls can use the cache. /// In the case of the .NET adapter that would be a cache from the .NET type to /// the public properties and fields available in that type. /// In the case of the DirectoryEntry adapter, this could be a cache of the objectClass /// to the properties available in it. /// </summary> /// <param name="obj">object to get all the member information from</param> /// <returns>all members in obj</returns> protected override PSMemberInfoInternalCollection <T> GetMembers <T>(object obj) { PSMemberInfoInternalCollection <T> collection = new PSMemberInfoInternalCollection <T>(); bool lookingForProperties = typeof(T).IsAssignableFrom(typeof(PSProperty)); bool lookingForParameterizedProperties = typeof(T).IsAssignableFrom(typeof(PSParameterizedProperty)); if (lookingForProperties || lookingForParameterizedProperties) { foreach (ComProperty prop in _comTypeInfo.Properties.Values) { if (prop.IsParameterized) { if (lookingForParameterizedProperties) { collection.Add(new PSParameterizedProperty(prop.Name, this, obj, prop) as T); } } else if (lookingForProperties) { collection.Add(new PSProperty(prop.Name, this, obj, prop) as T); } } } bool lookingForMethods = typeof(T).IsAssignableFrom(typeof(PSMethod)); if (lookingForMethods) { foreach (ComMethod method in _comTypeInfo.Methods.Values) { if (collection[method.Name] == null) { PSMethod mshmethod = new PSMethod(method.Name, this, obj, method); collection.Add(mshmethod as T); } } } return(collection); }
protected override void DoAddAllProperties <T>(object obj, PSMemberInfoInternalCollection <T> members) { DataRowView view = (DataRowView)obj; if (((view.Row != null) && (view.Row.Table != null)) && (view.Row.Table.Columns != null)) { foreach (DataColumn column in view.Row.Table.Columns) { members.Add(new PSProperty(column.ColumnName, this, obj, column.ColumnName) as T); } } }
/// <summary> /// Serializes properties of PSObject. /// </summary> private void WritePSObjectProperties(PSObject source, int depth) { Dbg.Assert(source != null, "caller should validate the information"); depth = GetDepthOfSerialization(source, depth); //Depth available for each property is one less --depth; Dbg.Assert(depth >= 0, "depth should be greater or equal to zero"); if (source.GetSerializationMethod(null) == SerializationMethod.SpecificProperties) { PSMemberInfoInternalCollection <PSPropertyInfo> specificProperties = new PSMemberInfoInternalCollection <PSPropertyInfo>(); foreach (string propertyName in source.GetSpecificPropertiesToSerialize(null)) { PSPropertyInfo property = source.Properties[propertyName]; if (property != null) { specificProperties.Add(property); } } SerializeProperties(specificProperties, CustomSerializationStrings.Properties, depth); return; } foreach (PSPropertyInfo prop in source.Properties) { Dbg.Assert(prop != null, "propertyCollection should only have member of type PSProperty"); object value = AutomationNull.Value; //PSObject throws GetValueException if it cannot //get value for a property. try { value = prop.Value; } catch (GetValueException) { WritePropertyWithNullValue(_writer, prop, depth); continue; } //Write the property if (value == null) { WritePropertyWithNullValue(_writer, prop, depth); } else { WriteOneObject(value, prop.Name, depth); } } }
protected override void AddAllProperties <T>(ManagementBaseObject wmiObject, PSMemberInfoInternalCollection <T> members) { // Add System properties base.AddAllProperties(wmiObject, members); if (wmiObject.Properties != null) { foreach (PropertyData property in wmiObject.Properties) { members.Add(new PSProperty(property.Name, this, wmiObject, property) as T); } } }
protected override void AddAllMethods <T>(ManagementBaseObject wmiObject, PSMemberInfoInternalCollection <T> members) { if (typeof(T).IsAssignableFrom(typeof(PSMethod))) { foreach (BaseWMIAdapter.WMIMethodCacheEntry entry in BaseWMIAdapter.GetInstanceMethodTable(wmiObject, false).memberCollection) { if (members[entry.Name] == null) { Adapter.tracer.WriteLine("Adding method {0}", new object[] { entry.Name }); members.Add(new PSMethod(entry.Name, this, wmiObject, entry) as T); } } } }
protected override PSMemberInfoInternalCollection <T> GetMembers <T>( object obj) { PSMemberInfoInternalCollection <T> internalCollection = new PSMemberInfoInternalCollection <T>(); foreach (PSMemberInfo member1 in ((PSObject)obj).Members) { if (member1 is T member) { internalCollection.Add(member); } } return(internalCollection); }
protected override PSMemberInfoInternalCollection <T> GetMembers <T>(object obj) { PSMemberInfoInternalCollection <T> internals = new PSMemberInfoInternalCollection <T>(); foreach (PSMemberInfo info in ((PSMemberSet)obj).Members) { T member = info as T; if (member != null) { internals.Add(member); } } return(internals); }
protected override void DoAddAllProperties <T>( object obj, PSMemberInfoInternalCollection <T> members) { DataRow dataRow = (DataRow)obj; if (dataRow.Table == null || dataRow.Table.Columns == null) { return; } foreach (DataColumn column in (InternalDataCollectionBase)dataRow.Table.Columns) { members.Add(new PSProperty(column.ColumnName, (Adapter)this, obj, (object)column.ColumnName) as T); } }
private PSMemberInfoInternalCollection <T> GetInternalMembers( MshMemberMatchOptions matchOptions) { PSMemberInfoInternalCollection <T> internalCollection = new PSMemberInfoInternalCollection <T>(); foreach (T obj in (PSMemberInfoCollection <T>) this) { PSMemberInfo psMemberInfo = (PSMemberInfo)obj; if (psMemberInfo.MatchesOptions(matchOptions) && psMemberInfo is T member) { internalCollection.Add(member); } } return(internalCollection); }
protected override PSMemberInfoInternalCollection <T> GetMembers <T>(object obj) { PSMemberInfoInternalCollection <T> internals = new PSMemberInfoInternalCollection <T>(); bool flag = typeof(T).IsAssignableFrom(typeof(PSProperty)); bool flag2 = typeof(T).IsAssignableFrom(typeof(PSParameterizedProperty)); if (flag || flag2) { foreach (ComProperty property in this._comTypeInfo.Properties.Values) { if (property.IsParameterized) { if (flag2) { internals.Add(new PSParameterizedProperty(property.Name, this, obj, property) as T); } } else if (flag) { internals.Add(new PSProperty(property.Name, this, obj, property) as T); } } } if (typeof(T).IsAssignableFrom(typeof(PSMethod))) { foreach (ComMethod method in this._comTypeInfo.Methods.Values) { if (internals[method.Name] == null) { PSMethod method2 = new PSMethod(method.Name, this, obj, method); internals.Add(method2 as T); } } } return(internals); }
/// <summary> /// Retrieves all the properties available in the object. /// </summary> /// <param name="obj">object to get all the property information from</param> /// <param name="members">collection where the members will be added</param> protected override void DoAddAllProperties <T>(object obj, PSMemberInfoInternalCollection <T> members) { DataRow dataRow = (DataRow)obj; if (dataRow.Table == null || dataRow.Table.Columns == null) { return; } foreach (DataColumn property in dataRow.Table.Columns) { members.Add(new PSProperty(property.ColumnName, this, obj, property.ColumnName) as T); } return; }
private PSMemberInfoInternalCollection <T> GetInternalMembers(MshMemberMatchOptions matchOptions) { PSMemberInfoInternalCollection <T> internals = new PSMemberInfoInternalCollection <T>(); lock (this.members) { foreach (T local in this.members.Values.OfType <T>()) { if (local.MatchesOptions(matchOptions)) { internals.Add(local); } } } return(internals); }
private void WritePSObjectProperties(PSObject source, int depth) { depth = GetDepthOfSerialization(source, depth); depth--; if (source.GetSerializationMethod(null) == SerializationMethod.SpecificProperties) { PSMemberInfoInternalCollection <PSPropertyInfo> propertyCollection = new PSMemberInfoInternalCollection <PSPropertyInfo>(); foreach (string str in source.GetSpecificPropertiesToSerialize(null)) { PSPropertyInfo member = source.Properties[str]; if (member != null) { propertyCollection.Add(member); } } this.SerializeProperties(propertyCollection, "Property", depth); } else { foreach (PSPropertyInfo info2 in source.Properties) { object obj2 = AutomationNull.Value; try { obj2 = info2.Value; } catch (GetValueException) { this.WritePropertyWithNullValue(this._writer, info2, depth); continue; } if (obj2 == null) { this.WritePropertyWithNullValue(this._writer, info2, depth); } else { this.WriteOneObject(obj2, info2.Name, depth); } } } }
protected override void DoAddAllProperties <T>(object obj, PSMemberInfoInternalCollection <T> members) { System.Xml.XmlNode node = (System.Xml.XmlNode)obj; Dictionary <string, List <System.Xml.XmlNode> > dictionary = new Dictionary <string, List <System.Xml.XmlNode> >(StringComparer.OrdinalIgnoreCase); if (node.Attributes != null) { foreach (System.Xml.XmlNode node2 in node.Attributes) { List <System.Xml.XmlNode> list; if (!dictionary.TryGetValue(node2.LocalName, out list)) { list = new List <System.Xml.XmlNode>(); dictionary[node2.LocalName] = list; } list.Add(node2); } } if (node.ChildNodes != null) { foreach (System.Xml.XmlNode node3 in node.ChildNodes) { if (!(node3 is XmlWhitespace)) { List <System.Xml.XmlNode> list2; if (!dictionary.TryGetValue(node3.LocalName, out list2)) { list2 = new List <System.Xml.XmlNode>(); dictionary[node3.LocalName] = list2; } list2.Add(node3); } } } foreach (KeyValuePair <string, List <System.Xml.XmlNode> > pair in dictionary) { members.Add(new PSProperty(pair.Key, this, obj, pair.Value.ToArray()) as T); } }
protected override void DoAddAllProperties <T>( object obj, PSMemberInfoInternalCollection <T> members) { XmlNode xmlNode = (XmlNode)obj; Dictionary <string, List <XmlNode> > dictionary = new Dictionary <string, List <XmlNode> >((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase); if (xmlNode.Attributes != null) { foreach (XmlNode attribute in (XmlNamedNodeMap)xmlNode.Attributes) { List <XmlNode> xmlNodeList; if (!dictionary.TryGetValue(attribute.LocalName, out xmlNodeList)) { xmlNodeList = new List <XmlNode>(); dictionary[attribute.LocalName] = xmlNodeList; } xmlNodeList.Add(attribute); } } if (xmlNode.ChildNodes != null) { foreach (XmlNode childNode in xmlNode.ChildNodes) { List <XmlNode> xmlNodeList; if (!dictionary.TryGetValue(childNode.LocalName, out xmlNodeList)) { xmlNodeList = new List <XmlNode>(); dictionary[childNode.LocalName] = xmlNodeList; } xmlNodeList.Add(childNode); } } foreach (KeyValuePair <string, List <XmlNode> > keyValuePair in dictionary) { members.Add(new PSProperty(keyValuePair.Key, (Adapter)this, obj, (object)keyValuePair.Value.ToArray()) as T); } }
/// <summary> /// Adds method information of the ManagementObject. Only instance methods are added for /// a ManagementObject. /// </summary> /// <typeparam name="T">PSMemberInfo</typeparam> /// <param name="wmiObject">Object for which the members need to be retrieved.</param> /// <param name="members">Method information is added to this.</param> protected override void AddAllMethods <T>(ManagementBaseObject wmiObject, PSMemberInfoInternalCollection <T> members) { Diagnostics.Assert((wmiObject != null) && (members != null), "Input arguments should not be null."); if (!typeof(T).IsAssignableFrom(typeof(PSMethod))) { return; } CacheTable table; table = GetInstanceMethodTable(wmiObject, false); foreach (WMIMethodCacheEntry methodEntry in table.memberCollection) { if (members[methodEntry.Name] == null) { tracer.WriteLine("Adding method {0}", methodEntry.Name); members.Add(new PSMethod(methodEntry.Name, this, wmiObject, methodEntry) as T); } } }
private PSMemberInfoInternalCollection <T> GetIntegratedMembers(MshMemberMatchOptions matchOptions) { using (PSObject.memberResolution.TraceScope("Generating the total list of members", new object[0])) { object mshOwner; PSMemberInfoInternalCollection <T> internals = new PSMemberInfoInternalCollection <T>(); if (this.mshOwner != null) { mshOwner = this.mshOwner; foreach (PSMemberInfo info in this.mshOwner.InstanceMembers) { if (info.MatchesOptions(matchOptions)) { T member = info as T; if (member != null) { internals.Add(member); } } } } else { mshOwner = this.memberSetOwner.instance; foreach (PSMemberInfo info2 in this.memberSetOwner.InternalMembers) { if (info2.MatchesOptions(matchOptions)) { T local2 = info2 as T; if (local2 != null) { info2.ReplicateInstance(mshOwner); internals.Add(local2); } } } } if (mshOwner != null) { mshOwner = PSObject.AsPSObject(mshOwner); foreach (CollectionEntry <T> entry in this.collections) { foreach (T local3 in entry.GetMembers((PSObject)mshOwner)) { PSMemberInfo info3 = internals[local3.Name]; if (info3 != null) { PSObject.memberResolution.WriteLine("Member \"{0}\" of type \"{1}\" has been ignored because a member with the same name and type \"{2}\" is already present.", new object[] { local3.Name, local3.MemberType, info3.MemberType }); } else if (!local3.MatchesOptions(matchOptions)) { PSObject.memberResolution.WriteLine("Skipping hidden member \"{0}\".", new object[] { local3.Name }); } else { T local4; if (entry.ShouldCloneWhenReturning) { local4 = (T)local3.Copy(); } else { local4 = local3; } if (entry.ShouldReplicateWhenReturning) { local4.ReplicateInstance(mshOwner); } internals.Add(local4); } } } } return(internals); } }