Inheritance: System.Management.Automation.PSPropertyInfo
Exemplo n.º 1
0
 public override PSMemberInfo Copy()
 {
     PSProperty destiny = new PSProperty(base.name, this.adapter, this.baseObject, this.adapterData);
     base.CloneBaseProperties(destiny);
     destiny.typeOfValue = this.typeOfValue;
     destiny.serializedValue = this.serializedValue;
     destiny.isDeserialized = this.isDeserialized;
     return destiny;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Get the property signature.
        /// </summary>
        /// <param name="property">Property object whose signature we want.</param>
        /// <returns>String representing the signature of the property.</returns>
        protected override string PropertyToString(PSProperty property)
        {
            ComProperty prop = (ComProperty)property.adapterData;

            return(prop.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns true if the property is gettable.
        /// </summary>
        /// <param name="property">Property to check.</param>
        /// <returns>True if the property is gettable.</returns>
        protected override bool PropertyIsGettable(PSProperty property)
        {
            ComProperty prop = (ComProperty)property.adapterData;

            return(prop.IsGettable);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the value from a property coming from a previous call to DoGetProperty.
        /// </summary>
        /// <param name="property">PSProperty coming from a previous call to DoGetProperty.</param>
        /// <returns>The value of the property.</returns>
        protected override object PropertyGet(PSProperty property)
        {
            ComProperty prop = (ComProperty)property.adapterData;

            return(prop.GetValue(property.baseObject));
        }
Exemplo n.º 5
0
        protected override bool PropertyIsSettable(PSProperty property)
        {
            ComProperty adapterData = (ComProperty)property.adapterData;

            return(adapterData.IsSettable);
        }
Exemplo n.º 6
0
 protected override bool PropertyIsGettable(PSProperty property) => true;
Exemplo n.º 7
0
        protected override string PropertyType(PSProperty property)
        {
            string adapterData = (string)property.adapterData;

            return(((DataRow)property.baseObject).Table.Columns[adapterData].DataType.FullName);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Sets the value of a property coming from a previous call to GetMember
        /// </summary>
        /// <param name="property">PSProperty coming from a previous call to GetMember</param>
        /// <param name="setValue">value to set the property with</param>
        /// <param name="convertIfPossible">instructs the adapter to convert before setting, if the adapter supports conversion</param>
        protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible)
        {
            PropertyValueCollection values = property.adapterData as PropertyValueCollection;

            if (null != values)
            {
                // This means GetMember returned PropertyValueCollection
                try
                {
                    values.Clear();
                }
                catch (System.Runtime.InteropServices.COMException e)
                {
                    if (e.ErrorCode != unchecked ((int)0x80004005) || (setValue == null))
                    {
                        // When clear is called, DirectoryEntry calls PutEx on AD object with Clear option and Null Value
                        // WinNT provider throws E_FAIL when null value is specified though actually ADS_PROPERTY_CLEAR option is used,
                        // we need to catch  this exception here.
                        // But at the same time we don't want to catch the exception if user explicitly sets the value to null.
                        throw;
                    }
                }

                IEnumerable enumValues = LanguagePrimitives.GetEnumerable(setValue);

                if (enumValues == null)
                {
                    values.Add(setValue);
                }
                else
                {
                    foreach (object objValue in enumValues)
                    {
                        values.Add(objValue);
                    }
                }
            }
            else
            {
                // This means GetMember returned the value from InvokeGet..So set the value using InvokeSet.
                DirectoryEntry entry = (DirectoryEntry)property.baseObject;
                Diagnostics.Assert(entry != null, "Object should be of type DirectoryEntry in DirectoryEntry adapter.");

                List <object> setValues  = new List <object>();
                IEnumerable   enumValues = LanguagePrimitives.GetEnumerable(setValue);

                if (enumValues == null)
                {
                    setValues.Add(setValue);
                }
                else
                {
                    foreach (object objValue in enumValues)
                    {
                        setValues.Add(objValue);
                    }
                }

                entry.InvokeSet(property.name, setValues.ToArray());
            }

            return;
        }
Exemplo n.º 9
0
 protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Exemplo n.º 10
0
 protected override bool PropertyIsSettable(PSProperty property)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Exemplo n.º 11
0
 protected override object PropertyGet(PSProperty property)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Exemplo n.º 12
0
 protected override AttributeCollection PropertyAttributes(PSProperty property)
 {
     return new AttributeCollection(new Attribute[0]);
 }
Exemplo n.º 13
0
 protected override object PropertyGet(PSProperty property) => property.adapterData;
Exemplo n.º 14
0
 protected override AttributeCollection PropertyAttributes(PSProperty property) => base.PropertyAttributes(property);
Exemplo n.º 15
0
 protected override string PropertyToString(PSProperty property) => base.PropertyToString(property);
Exemplo n.º 16
0
 /// <summary>
 /// Returns true if the property is gettable
 /// </summary>
 /// <param name="property">property to check</param>
 /// <returns>true if the property is gettable</returns>
 protected override bool PropertyIsGettable(PSProperty property)
 {
     return(true);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Returns null if memberName is not a member in the adapter or
        /// the corresponding PSMemberInfo
        /// </summary>
        /// <param name="obj">object to retrieve the PSMemberInfo from</param>
        /// <param name="memberName">name of the member to be retrieved</param>
        /// <returns>The PSMemberInfo corresponding to memberName from obj</returns>
        protected override T GetMember <T>(object obj, string memberName)
        {
            PSProperty     property;
            DirectoryEntry entry = (DirectoryEntry)obj;

            // This line must precede InvokeGet. See the comment below.
            PropertyValueCollection collection = entry.Properties[memberName];
            object valueToTake = collection;

#pragma warning disable 56500
            // Even for the cases where propertyName does not exist
            // entry.Properties[propertyName] still returns a PropertyValueCollection.
            // The non schema way to check for a non existing property is to call entry.InvokeGet
            // and catch an eventual exception.
            // Specifically for "LDAP://RootDse" there are some cases where calling
            // InvokeGet will throw COMException for existing properties like defaultNamingContext.
            // Having a call to entry.Properties[propertyName] fixes the RootDse problem.
            // Calling entry.RefreshCache() also fixes the RootDse problem.
            try
            {
                object invokeGetValue = entry.InvokeGet(memberName);
                // if entry.Properties[memberName] returns empty value and invokeGet non-empty
                // value..take invokeGet's value. This will fix bug Windows Bug 121188.
                if ((null == collection) || ((null == collection.Value) && (null != invokeGetValue)))
                {
                    valueToTake = invokeGetValue;
                }

                property = new PSProperty(collection.PropertyName, this, obj, valueToTake);
            }
            catch (Exception e)
            {
                CommandProcessorBase.CheckForSevereException(e);
                property = null;
            }
#pragma warning restore 56500

            if (valueToTake == null)
            {
                property = null;
            }

            if (typeof(T).IsAssignableFrom(typeof(PSProperty)) && property != null)
            {
                return(property as T);
            }

            if (typeof(T).IsAssignableFrom(typeof(PSMethod)))
            {
                if (property == null)
                {
                    #region Readme
                    // we are unable to find a native adsi object property.
                    // The next option is to find method. Unfortunately DirectoryEntry
                    // doesn't provide us a way to access underlying native object's method
                    // metadata.
                    // Adapter engine resolve's members in the following steps:
                    //  1. Extended members -> 2. Adapted members -> 3. Dotnet members
                    // We cannot say from DirectoryEntryAdapter if a method with name "memberName"
                    // is available. So check if a DotNet property with the same name is available
                    // If yes, return null from the adapted view and let adapter engine
                    // take care of DotNet member resolution. If not, assume memberName method
                    // is available on native adsi object.
                    // In case of collisions between Dotnet Property and adsi native object methods,
                    // Dotnet wins. Looking through IADs com interfaces there doesn't appear
                    // to be a collision like this.
                    // Powershell Parser will call only GetMember<PSMemberInfo>, so here
                    // we cannot distinguish if the caller is looking for a property or a
                    // method.
                    #endregion

                    if (base.GetDotNetProperty <T>(obj, memberName) == null)
                    {
                        return(new PSMethod(memberName, this, obj, null) as T);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 18
0
 protected override string PropertyToString(PSProperty property)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Exemplo n.º 19
0
 protected override string PropertyType(PSProperty property, bool forDisplay)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Exemplo n.º 20
0
 protected override string PropertyType(PSProperty property, bool forDisplay)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Exemplo n.º 21
0
        protected override bool PropertyIsSettable(PSProperty property)
        {
            string adapterData = (string)property.adapterData;

            return(!((DataRow)property.baseObject).Table.Columns[adapterData].ReadOnly);
        }
Exemplo n.º 22
0
        protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible)
        {
            DataRowView baseObject = (DataRowView)property.baseObject;

            baseObject[(string)property.adapterData] = setValue;
        }
Exemplo n.º 23
0
 protected override object PropertyGet(PSProperty property) => ((DataRow)property.baseObject)[(string)property.adapterData];
Exemplo n.º 24
0
 protected abstract object PropertyGet(PSProperty property);
Exemplo n.º 25
0
 /// <summary>
 /// Returns an array with the property attributes.
 /// </summary>
 /// <param name="property">Property we want the attributes from.</param>
 /// <returns>An array with the property attributes.</returns>
 protected override AttributeCollection PropertyAttributes(PSProperty property)
 {
     return(new AttributeCollection());
 }
Exemplo n.º 26
0
 protected abstract void PropertySet(
     PSProperty property,
     object setValue,
     bool convertIfPossible);
Exemplo n.º 27
0
        /// <summary>
        /// Sets the value of a property coming from a previous call to DoGetProperty.
        /// </summary>
        /// <param name="property">PSProperty coming from a previous call to DoGetProperty.</param>
        /// <param name="setValue">Value to set the property with.</param>
        ///  <param name="convertIfPossible">instructs the adapter to convert before setting, if the adapter supports conversion</param>
        protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible)
        {
            ComProperty prop = (ComProperty)property.adapterData;

            prop.SetValue(property.baseObject, setValue);
        }
Exemplo n.º 28
0
 protected abstract bool PropertyIsGettable(PSProperty property);
Exemplo n.º 29
0
        /// <summary>
        /// Returns the name of the type corresponding to the property.
        /// </summary>
        /// <param name="property">PSProperty obtained in a previous DoGetProperty.</param>
        /// <param name="forDisplay">True if the result is for display purposes only.</param>
        /// <returns>The name of the type corresponding to the property.</returns>
        protected override string PropertyType(PSProperty property, bool forDisplay)
        {
            ComProperty prop = (ComProperty)property.adapterData;

            return(forDisplay ? ToStringCodeMethods.Type(prop.Type) : prop.Type.FullName);
        }
Exemplo n.º 30
0
 protected abstract string PropertyType(PSProperty property);
Exemplo n.º 31
0
        private void CheckAndAddProperty(PSPropertyInfo propertyInfo, Attribute[] attributes, ref PropertyDescriptorCollection returnValue)
        {
            using (typeDescriptor.TraceScope("Checking property \"{0}\".", propertyInfo.Name))
            {
                // WriteOnly properties are not returned in TypeDescriptor.GetProperties, so we do the same.
                if (!propertyInfo.IsGettable)
                {
                    typeDescriptor.WriteLine("Property \"{0}\" is write-only so it has been skipped.", propertyInfo.Name);
                    return;
                }

                AttributeCollection propertyAttributes = null;
                Type propertyType = typeof(object);
                if (attributes != null && attributes.Length != 0)
                {
                    PSProperty property = propertyInfo as PSProperty;
                    if (property != null)
                    {
                        DotNetAdapter.PropertyCacheEntry propertyEntry = property.adapterData as DotNetAdapter.PropertyCacheEntry;
                        if (propertyEntry is null)
                        {
                            typeDescriptor.WriteLine("Skipping attribute check for property \"{0}\" because it is an adapted property (not a .NET property).", property.Name);
                        }
                        else if (property.isDeserialized)
                        {
                            // At the moment we are not serializing attributes, so we can skip
                            // the attribute check if the property is deserialized.
                            typeDescriptor.WriteLine("Skipping attribute check for property \"{0}\" because it has been deserialized.", property.Name);
                        }
                        else
                        {
                            propertyType       = propertyEntry.propertyType;
                            propertyAttributes = propertyEntry.Attributes;
                            foreach (Attribute attribute in attributes)
                            {
                                if (!propertyAttributes.Contains(attribute))
                                {
                                    typeDescriptor.WriteLine("Property \"{0}\" does not contain attribute \"{1}\" so it has been skipped.", property.Name, attribute);
                                    return;
                                }
                            }
                        }
                    }
                }

                if (propertyAttributes is null)
                {
                    propertyAttributes = new AttributeCollection();
                }

                typeDescriptor.WriteLine("Adding property \"{0}\".", propertyInfo.Name);

                PSObjectPropertyDescriptor propertyDescriptor =
                    new PSObjectPropertyDescriptor(propertyInfo.Name, propertyType, !propertyInfo.IsSettable, propertyAttributes);

                propertyDescriptor.SettingValueException += this.SettingValueException;
                propertyDescriptor.GettingValueException += this.GettingValueException;

                returnValue.Add(propertyDescriptor);
            }
        }
Exemplo n.º 32
0
 protected abstract string PropertyToString(PSProperty property);
Exemplo n.º 33
0
        /// <summary>
        /// Returns the value from a property coming from a previous call to DoGetProperty
        /// </summary>
        /// <param name="property">PSProperty coming from a previous call to DoGetProperty</param>
        /// <returns>The value of the property</returns>
        protected override object PropertyGet(PSProperty property)
        {
            DataRowView dataRowView = (DataRowView)property.baseObject;

            return(dataRowView[(string)property.adapterData]);
        }
Exemplo n.º 34
0
 protected abstract AttributeCollection PropertyAttributes(PSProperty property);
Exemplo n.º 35
0
 /// <summary>
 /// Returns the value from a property coming from a previous call to GetMember
 /// </summary>
 /// <param name="property">PSProperty coming from a previous call to GetMember</param>
 /// <returns>The value of the property</returns>
 protected override object PropertyGet(PSProperty property)
 {
     return(property.adapterData);
 }
Exemplo n.º 36
0
        /// <summary>
        /// Returns the value from a property coming from a previous call to DoGetProperty
        /// </summary>
        /// <param name="property">PSProperty coming from a previous call to DoGetProperty</param>
        /// <returns>The value of the property</returns>
        protected override object PropertyGet(PSProperty property)
        {
            PropertyData pd = property.adapterData as PropertyData;

            return(pd.Value);
        }
Exemplo n.º 37
0
 private void ReadProperties(PSObject dso)
 {
     dso.isDeserialized = true;
     dso.adaptedMembers = new PSMemberInfoInternalCollection<PSPropertyInfo>();
     dso.clrMembers = new PSMemberInfoInternalCollection<PSPropertyInfo>();
     if (this.ReadStartElementAndHandleEmpty("Props"))
     {
         while (this._reader.NodeType == XmlNodeType.Element)
         {
             string name = this.ReadNameAttribute();
             object serializedValue = this.ReadOneObject();
             PSProperty member = new PSProperty(name, serializedValue);
             dso.adaptedMembers.Add(member);
         }
         this.ReadEndElement();
     }
 }
Exemplo n.º 38
0
 protected override string PropertyToString(PSProperty property)
 {
     throw PSTraceSource.NewNotSupportedException();
 }