/// <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);
            }
        }
Example #2
0
 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;
 }
Example #3
0
        internal static PSMemberInfoInternalCollection <T> Match <T>(
            PSMemberInfoInternalCollection <T> memberList,
            string name,
            WildcardPattern nameMatch,
            PSMemberTypes memberTypes)
            where T : PSMemberInfo
        {
            PSMemberInfoInternalCollection <T> internalCollection = new PSMemberInfoInternalCollection <T>();

            if (memberList == null)
            {
                throw MemberMatch.tracer.NewArgumentNullException(nameof(memberList));
            }
            if (string.IsNullOrEmpty(name))
            {
                throw MemberMatch.tracer.NewArgumentException(nameof(name));
            }
            if (nameMatch == null)
            {
                object hashedMember = memberList.hashedMembers[(object)name];
                if (hashedMember != null)
                {
                    PSMemberInfo member = (PSMemberInfo)memberList.members[((int?)hashedMember).Value];
                    if ((member.MemberType & memberTypes) != (PSMemberTypes)0)
                    {
                        internalCollection.Add(member as T);
                    }
                }
                return(internalCollection);
            }
            foreach (T member in (PSMemberInfoCollection <T>)memberList)
            {
                PSMemberInfo psMemberInfo = (PSMemberInfo)member;
                if (nameMatch.IsMatch(psMemberInfo.Name) && (psMemberInfo.MemberType & memberTypes) != (PSMemberTypes)0)
                {
                    internalCollection.Add(psMemberInfo as T);
                }
            }
            return(internalCollection);
        }
 protected override void AddAllProperties <T>(
     ManagementBaseObject wmiObject,
     PSMemberInfoInternalCollection <T> members)
 {
     if (wmiObject.SystemProperties == null)
     {
         return;
     }
     foreach (PropertyData systemProperty in wmiObject.SystemProperties)
     {
         members.Add(new PSProperty(systemProperty.Name, (Adapter)this, (object)wmiObject, (object)systemProperty) as T);
     }
 }
        private PSMemberInfoInternalCollection <PSMemberInfo> GetInternalMembersFromAdapted()
        {
            PSMemberInfoInternalCollection <PSMemberInfo> internalCollection = new PSMemberInfoInternalCollection <PSMemberInfo>();

            if (this.psObject.isDeserialized)
            {
                if (this.psObject.adaptedMembers != null)
                {
                    foreach (PSMemberInfo adaptedMember in (PSMemberInfoCollection <PSPropertyInfo>) this.psObject.adaptedMembers)
                    {
                        internalCollection.Add(adaptedMember.Copy());
                    }
                }
            }
            else
            {
                foreach (PSMemberInfo member in (PSMemberInfoCollection <PSMemberInfo>) this.psObject.InternalAdapter.BaseGetMembers <PSMemberInfo>(this.psObject.ImmediateBaseObject))
                {
                    internalCollection.Add(member.Copy());
                }
            }
            return(internalCollection);
        }
Example #6
0
        private ReadOnlyPSMemberInfoCollection <PSMemberInfo> GetMatchMembers()
        {
            if (WildcardPattern.ContainsWildcardCharacters(this._property))
            {
                return(this._inputObject.Members.Match(this._property, PSMemberTypes.All));
            }
            PSMemberInfoInternalCollection <PSMemberInfo> members = new PSMemberInfoInternalCollection <PSMemberInfo>();
            PSMemberInfo member = this._inputObject.Members[this._property];

            if (member != null)
            {
                members.Add(member);
            }
            return(new ReadOnlyPSMemberInfoCollection <PSMemberInfo>(members));
        }
 protected override void AddAllMethods <T>(
     ManagementBaseObject wmiObject,
     PSMemberInfoInternalCollection <T> members)
 {
     if (!typeof(T).IsAssignableFrom(typeof(PSMethod)))
     {
         return;
     }
     foreach (BaseWMIAdapter.WMIMethodCacheEntry member in BaseWMIAdapter.GetInstanceMethodTable(wmiObject, true).memberCollection)
     {
         if ((object)members[member.Name] == null)
         {
             Adapter.tracer.WriteLine("Adding method {0}", (object)member.Name);
             members.Add(new PSMethod(member.Name, (Adapter)this, (object)wmiObject, (object)member) as T);
         }
     }
 }
        protected override PSMemberInfoInternalCollection <T> GetMembers <T>(
            object obj)
        {
            PSMemberInfoInternalCollection <T> members1 = new PSMemberInfoInternalCollection <T>();

            if (typeof(T).IsAssignableFrom(typeof(PSProperty)))
            {
                this.DoAddAllProperties <T>(obj, members1);
            }
            PSObject.dotNetInstanceAdapter.AddAllMethods <T>(obj, members1, true);
            if (DotNetAdapter.IsTypeParameterizedProperty(typeof(T)))
            {
                PSMemberInfoInternalCollection <PSParameterizedProperty> members2 = new PSMemberInfoInternalCollection <PSParameterizedProperty>();
                PSObject.dotNetInstanceAdapter.AddAllProperties <PSParameterizedProperty>(obj, members2, true);
                foreach (PSParameterizedProperty parameterizedProperty in (PSMemberInfoCollection <PSParameterizedProperty>)members2)
                {
                    members1.Add(parameterizedProperty as T);
                }
            }
            return(members1);
        }
Example #9
0
        /// <summary>
        /// Get the matched PSMembers
        /// </summary>
        /// <returns></returns>
        private ReadOnlyPSMemberInfoCollection<PSMemberInfo> GetMatchMembers()
        {
            if (!WildcardPattern.ContainsWildcardCharacters(_property))
            {
                PSMemberInfoInternalCollection<PSMemberInfo> restuls = new PSMemberInfoInternalCollection<PSMemberInfo>();
                PSMemberInfo member = _inputObject.Members[_property];
                if (member != null)
                {
                    restuls.Add(member);
                }
                return new ReadOnlyPSMemberInfoCollection<PSMemberInfo>(restuls);
            }

            ReadOnlyPSMemberInfoCollection<PSMemberInfo> members = _inputObject.Members.Match(_property, PSMemberTypes.All);
            Dbg.Assert(members != null, "The return value of Members.Match should never be null.");
            return members;
        }
Example #10
0
 private ReadOnlyPSMemberInfoCollection<PSMemberInfo> GetMatchMembers()
 {
     if (WildcardPattern.ContainsWildcardCharacters(this._property))
     {
         return this._inputObject.Members.Match(this._property, PSMemberTypes.All);
     }
     PSMemberInfoInternalCollection<PSMemberInfo> members = new PSMemberInfoInternalCollection<PSMemberInfo>();
     PSMemberInfo member = this._inputObject.Members[this._property];
     if (member != null)
     {
         members.Add(member);
     }
     return new ReadOnlyPSMemberInfoCollection<PSMemberInfo>(members);
 }
Example #11
0
 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);
             }
         }
     }
 }
Example #12
0
        /// <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);
                }
            }
        }