public override PSMemberInfo Copy() { PSMemberSet outVal = new PSMemberSet(Name); foreach (PSMemberInfo member in Members) { outVal.Members.Add(member); } CopyProperties(outVal); return outVal; }
public override PSMemberInfo Copy() { PSMemberSet outVal = new PSMemberSet(Name); foreach (PSMemberInfo member in Members) { outVal.Members.Add(member); } CopyProperties(outVal); return(outVal); }
private void GeneratePSObjectMemberSet() { if (this.mshOwner.InstanceMembers["psobject"] != null) { return; } PSMemberSet psMemberSet = (PSMemberSet) new PSInternalMemberSet("psobject", this.mshOwner); psMemberSet.ShouldSerialize = false; psMemberSet.isHidden = true; psMemberSet.isReservedMember = true; this.mshOwner.InstanceMembers.Add((PSMemberInfo)psMemberSet); }
internal PSMemberInfoIntegratingCollection( object owner, Collection <CollectionEntry <T> > collections) { this.mshOwner = owner != null ? owner as PSObject : throw PSMemberInfoIntegratingCollection <T> .tracer.NewArgumentNullException(nameof (owner)); this.memberSetOwner = owner as PSMemberSet; if (this.mshOwner == null && this.memberSetOwner == null) { throw PSMemberInfoIntegratingCollection <T> .tracer.NewArgumentException(nameof (owner)); } this.collections = collections != null ? collections : throw PSMemberInfoIntegratingCollection <T> .tracer.NewArgumentNullException(nameof (collections)); }
private void GenerateExtendedMemberSet() { if (this.mshOwner.InstanceMembers["psextended"] != null) { return; } PSMemberSet psMemberSet = new PSMemberSet("psextended", this.mshOwner); psMemberSet.ReplicateInstance(this.mshOwner); psMemberSet.ShouldSerialize = false; psMemberSet.isHidden = true; psMemberSet.isReservedMember = true; this.mshOwner.InstanceMembers.Add((PSMemberInfo)psMemberSet); }
/// <summary> /// Returns the default property for this object. /// </summary> /// <returns>An <see cref="PSObjectPropertyDescriptor"/> that represents the default property for this object, or a null reference (Nothing in Visual Basic) if this object does not have properties.</returns> public override PropertyDescriptor GetDefaultProperty() { if (this.Instance == null) { return(null); } string defaultProperty = null; PSMemberSet standardMembers = this.Instance.PSStandardMembers; if (standardMembers != null) { PSNoteProperty note = standardMembers.Properties[TypeTable.DefaultDisplayProperty] as PSNoteProperty; if (note != null) { defaultProperty = note.Value as string; } } if (defaultProperty == null) { object[] defaultPropertyAttributes = this.Instance.BaseObject.GetType().GetCustomAttributes(typeof(DefaultPropertyAttribute), true); if (defaultPropertyAttributes.Length == 1) { DefaultPropertyAttribute defaultPropertyAttribute = defaultPropertyAttributes[0] as DefaultPropertyAttribute; if (defaultPropertyAttribute != null) { defaultProperty = defaultPropertyAttribute.Name; } } } PropertyDescriptorCollection properties = this.GetProperties(); if (defaultProperty != null) { // There is a defaultProperty, but let's check if it is actually one of the properties we are // returning in GetProperties foreach (PropertyDescriptor descriptor in properties) { if (string.Equals(descriptor.Name, defaultProperty, StringComparison.OrdinalIgnoreCase)) { return(descriptor); } } } return(null); }
public override PSMemberInfo Copy() { if (this.constructorPSObject != null) { return((PSMemberInfo) new PSMemberSet(this.name, this.constructorPSObject)); } PSMemberSet psMemberSet = new PSMemberSet(this.name); foreach (PSMemberInfo member in this.Members) { psMemberSet.Members.Add(member); } this.CloneBaseProperties((PSMemberInfo)psMemberSet); return((PSMemberInfo)psMemberSet); }
public override PSMemberInfo Copy() { if (this.constructorPSObject != null) { return(new PSMemberSet(base.name, this.constructorPSObject)); } PSMemberSet destiny = new PSMemberSet(base.name); foreach (PSMemberInfo info in this.Members) { destiny.Members.Add(info); } base.CloneBaseProperties(destiny); return(destiny); }
private static MshExpression GetDefaultNameExpression(PSMemberSet standardMembersSet) { if (standardMembersSet != null) { PSNoteProperty property = standardMembersSet.Members["DefaultDisplayProperty"] as PSNoteProperty; if (property != null) { string str = property.Value.ToString(); if (string.IsNullOrEmpty(str)) { return null; } return new MshExpression(str); } } return null; }
internal PSMemberInfoIntegratingCollection(object owner, Collection <CollectionEntry <T> > collections) { if (owner == null) { throw PSTraceSource.NewArgumentNullException("owner"); } this.mshOwner = owner as PSObject; this.memberSetOwner = owner as PSMemberSet; if ((this.mshOwner == null) && (this.memberSetOwner == null)) { throw PSTraceSource.NewArgumentException("owner"); } if (collections == null) { throw PSTraceSource.NewArgumentNullException("collections"); } this.collections = collections; }
internal static object GeneratePSExtendedMemberSet(object obj) { PSObject mshObject = PSObject.AsPSObject(obj); PSMemberInfo member = mshObject.InstanceMembers["psextended"]; if (member == null) { PSMemberSet set = new PSMemberSet("psextended", mshObject) { ShouldSerialize = false, isHidden = true, isReservedMember = true }; member = set; member.ReplicateInstance(mshObject); member.instance = mshObject; mshObject.InstanceMembers.Add(member); } return member; }
internal static object GeneratePSExtendedMemberSet(object obj) { PSObject mshObject = PSObject.AsPSObject(obj); PSMemberInfo member = mshObject.InstanceMembers["psextended"]; if (member == null) { PSMemberSet set = new PSMemberSet("psextended", mshObject) { ShouldSerialize = false, isHidden = true, isReservedMember = true }; member = set; member.ReplicateInstance(mshObject); member.instance = mshObject; mshObject.InstanceMembers.Add(member); } return(member); }
private static List<MshExpression> GetDefaultPropertySet(PSMemberSet standardMembersSet) { if (standardMembersSet != null) { PSPropertySet set = standardMembersSet.Members["DefaultDisplayPropertySet"] as PSPropertySet; if (set != null) { List<MshExpression> list = new List<MshExpression>(); foreach (string str in set.ReferencedPropertyNames) { if (!string.IsNullOrEmpty(str)) { list.Add(new MshExpression(str)); } } return list; } } return new List<MshExpression>(); }
public override PropertyDescriptor GetDefaultProperty() { if (this.Instance != null) { string b = null; PSMemberSet pSStandardMembers = this.Instance.PSStandardMembers; if (pSStandardMembers != null) { PSNoteProperty property = pSStandardMembers.Properties["DefaultDisplayProperty"] as PSNoteProperty; if (property != null) { b = property.Value as string; } } if (b == null) { object[] customAttributes = this.Instance.BaseObject.GetType().GetCustomAttributes(typeof(DefaultPropertyAttribute), true); if (customAttributes.Length == 1) { DefaultPropertyAttribute attribute = customAttributes[0] as DefaultPropertyAttribute; if (attribute != null) { b = attribute.Name; } } } PropertyDescriptorCollection properties = this.GetProperties(); if (b != null) { foreach (PropertyDescriptor descriptor in properties) { if (string.Equals(descriptor.Name, b, StringComparison.OrdinalIgnoreCase)) { return(descriptor); } } } } return(null); }
private void ReadMemberSet(PSMemberInfoCollection<PSMemberInfo> collection) { if (this.ReadStartElementAndHandleEmpty("MS")) { while (this._reader.NodeType == XmlNodeType.Element) { if (this.IsNextElement("MS")) { string name = this.ReadNameAttribute(); PSMemberSet member = new PSMemberSet(name); collection.Add(member); this.ReadMemberSet(member.Members); PSGetMemberBinder.SetHasInstanceMember(name); } else { PSNoteProperty property = this.ReadNoteProperty(); collection.Add(property); PSGetMemberBinder.SetHasInstanceMember(property.Name); } } this.ReadEndElement(); } }
/// <summary> /// Creates and caches an instance of the "PSStandardMembers" <see cref="PSMemberSet"/> to attach to a <see cref="Record"/>. /// </summary> /// <param name="view">The <see cref="View"/> from which column information is retrieved.</param> /// <returns>A new or cached copy of the "PSStandardMembers" <see cref="PSMemberSet"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="view"/> parameter value is null.</exception> internal static PSMemberSet GetMemberSet(View view) { if (null == view) { throw new ArgumentNullException("view"); } PSMemberSet memberSet; if (memberSets.ContainsKey(view.QueryString) && memberSets[view.QueryString].IsAlive) { // Get an existing PSMemberSet. memberSet = (PSMemberSet)memberSets[view.QueryString].Target; } else { // Add or set a new PSMemberSet. memberSet = new PSMemberSet("PSStandardMembers"); var columns = ViewManager.GetColumns(view).Select(column => column.Key); var properties = new PSPropertySet("DefaultDisplayPropertySet", columns); memberSet.Members.Add(properties); columns = ViewManager.GetColumns(view).PrimaryKeys; if (0 < columns.Count()) { properties = new PSPropertySet("DefaultKeyPropertySet", columns); memberSet.Members.Add(properties); } memberSets[view.QueryString] = new WeakReference(memberSet); } return memberSet; }
public override PSMemberInfo Copy() { if (this.constructorPSObject != null) { return new PSMemberSet(base.name, this.constructorPSObject); } PSMemberSet destiny = new PSMemberSet(base.name); foreach (PSMemberInfo info in this.Members) { destiny.Members.Add(info); } base.CloneBaseProperties(destiny); return destiny; }
private static MshExpression GetDefaultNameExpression(PSMemberSet standardMembersSet) { if (null != standardMembersSet) { PSNoteProperty defaultDisplayProperty = standardMembersSet.Members[TypeTable.DefaultDisplayProperty] as PSNoteProperty; if (null != defaultDisplayProperty) { string expressionString = defaultDisplayProperty.Value.ToString(); if (string.IsNullOrEmpty(expressionString)) { // invalid data, the PSObject is empty return null; } else { return new MshExpression(expressionString); } } } return null; }
private static List<MshExpression> GetDefaultPropertySet(PSMemberSet standardMembersSet) { if (null != standardMembersSet) { PSPropertySet defaultDisplayPropertySet = standardMembersSet.Members[TypeTable.DefaultDisplayPropertySet] as PSPropertySet; if (null != defaultDisplayPropertySet) { List<MshExpression> retVal = new List<MshExpression>(); foreach (string prop in defaultDisplayPropertySet.ReferencedPropertyNames) { if (!string.IsNullOrEmpty(prop)) { retVal.Add(new MshExpression(prop)); } } return retVal; } } return new List<MshExpression>(); }