/// Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Reflection; using System.Runtime.InteropServices; namespace Microsoft.VisualStudio.Project.Automation { [CLSCompliant(false), ComVisible(true)] public class OAProperty : EnvDTE.Property { #region fields private OAProperties parent; private PropertyInfo pi; #endregion #region ctors public OAProperty(OAProperties parent, PropertyInfo pi) { this.parent = parent; this.pi = pi; } #endregion #region EnvDTE.Property /// /// Microsoft Internal Use Only. /// public object Application { get { return null; } } /// /// Gets the Collection containing the Property object supporting this property. /// public EnvDTE.Properties Collection { get { //todo: EnvDTE.Property.Collection return this.parent; } } /// /// Gets the top-level extensibility object. /// public EnvDTE.DTE DTE { get { return this.parent.DTE; } } /// /// Returns one element of a list. /// /// The index of the item to display. /// The index of the item to display. Reserved for future use. /// The index of the item to display. Reserved for future use. /// The index of the item to display. Reserved for future use. /// The value of a property public object get_IndexedValue(object index1, object index2, object index3, object index4) { ParameterInfo[] par = pi.GetIndexParameters(); int len = Math.Min(par.Length, 4); if(len == 0) return this.Value; object[] index = new object[len]; Array.Copy(new object[4] { index1, index2, index3, index4 }, index, len); return this.pi.GetValue(this.parent.Target, index); } /// /// Setter function to set properties values. /// /// public void let_Value(object value) { this.Value = value; } /// /// Gets the name of the object. /// public string Name { get { return pi.Name; } } /// /// Gets the number of indices required to access the value. /// public short NumIndices { get { return (short)pi.GetIndexParameters().Length; } } /// /// Sets or gets the object supporting the Property object. /// public object Object { get { return this.parent.Target; } set { } } /// /// Microsoft Internal Use Only. /// public EnvDTE.Properties Parent { get { return this.parent; } } /// /// Sets the value of the property at the specified index. /// /// The index of the item to set. /// Reserved for future use. /// Reserved for future use. /// Reserved for future use. /// The value to set. public void set_IndexedValue(object index1, object index2, object index3, object index4, object value) { ParameterInfo[] par = pi.GetIndexParameters(); int len = Math.Min(par.Length, 4); if(len == 0) { this.Value = value; } else { object[] index = new object[len]; Array.Copy(new object[4] { index1, index2, index3, index4 }, index, len); using(AutomationScope scope = new AutomationScope(this.parent.Target.Node.ProjectMgr.Site)) { this.pi.SetValue(this.parent.Target, value, index); } } } /// /// Gets or sets the value of the property returned by the Property object. /// public object Value { get { return pi.GetValue(this.parent.Target, null); } set { using(AutomationScope scope = new AutomationScope(this.parent.Target.Node.ProjectMgr.Site)) { this.pi.SetValue(this.parent.Target, value, null); } } } #endregion } }