Exemplo n.º 1
0
        internal void AddToTypesXmlCache(T member, bool preValidated)
        {
            if (member == null)
            {
                throw PSTraceSource.NewArgumentNullException("member");
            }
            if (!preValidated && PSMemberInfoCollection <T> .IsReservedName(member.Name))
            {
                throw new ExtendedTypeSystemException("PSObjectMembersMembersAddReservedName", null, ExtendedTypeSystem.ReservedMemberName, new object[] { member.Name });
            }
            PSMemberInfo info = member.Copy();

            if (this.mshOwner != null)
            {
                if (!preValidated)
                {
                    TypeTable typeTable = this.mshOwner.GetTypeTable();
                    if ((typeTable != null) && (typeTable.GetMembers <T>(this.mshOwner.InternalTypeNames)[member.Name] != null))
                    {
                        throw new ExtendedTypeSystemException("AlreadyPresentInTypesXml", null, ExtendedTypeSystem.MemberAlreadyPresentFromTypesXml, new object[] { member.Name });
                    }
                }
                info.ReplicateInstance(this.mshOwner);
                this.mshOwner.InstanceMembers.Add(info, preValidated);
                PSGetMemberBinder.SetHasInstanceMember(info.Name);
                PSVariableAssignmentBinder.NoteTypeHasInstanceMemberOrTypeName(PSObject.Base(this.mshOwner).GetType());
            }
            else
            {
                this.memberSetOwner.InternalMembers.Add(info, preValidated);
            }
        }
Exemplo n.º 2
0
        private static PSMemberSet MaskDeserializedAndGetStandardMembers(PSObject so)
        {
            Collection <string> strings = Deserializer.MaskDeserializationPrefix(so.TypeNames);

            if (strings == null)
            {
                return((PSMemberSet)null);
            }
            TypeTable typeTable = so.GetTypeTable();

            return(typeTable == null ? (PSMemberSet)null : typeTable.GetMembers <PSMemberInfo>(new ConsolidatedString(strings))["PSStandardMembers"] as PSMemberSet);
        }
Exemplo n.º 3
0
        private static PSMemberSet MaskDeserializedAndGetStandardMembers(PSObject so)
        {
            Diagnostics.Assert(so != null, "Shell object to process cannot be null");
            var typeNames = so.InternalTypeNames;
            Collection <string> typeNamesWithoutDeserializedPrefix = Deserializer.MaskDeserializationPrefix(typeNames);

            if (typeNamesWithoutDeserializedPrefix == null)
            {
                return(null);
            }

            TypeTable typeTable = so.GetTypeTable();

            if (typeTable == null)
            {
                return(null);
            }

            PSMemberInfoInternalCollection <PSMemberInfo> members =
                typeTable.GetMembers <PSMemberInfo>(new ConsolidatedString(typeNamesWithoutDeserializedPrefix));

            return(members[TypeTable.PSStandardMembers] as PSMemberSet);
        }
        internal void AddToTypesXmlCache(T member, bool preValidated)
        {
            if ((object)member == null)
            {
                throw PSMemberInfoIntegratingCollection <T> .tracer.NewArgumentNullException(nameof (member));
            }
            if (!preValidated && PSMemberInfoCollection <T> .IsReservedName(member.Name))
            {
                throw new ExtendedTypeSystemException("PSObjectMembersMembersAddReservedName", (Exception)null, "ExtendedTypeSystem", "ReservedMemberName", new object[1]
                {
                    (object)member.Name
                });
            }
            PSMemberInfo member1 = member.Copy();

            if (this.mshOwner != null)
            {
                if (!preValidated)
                {
                    TypeTable typeTable = this.mshOwner.GetTypeTable();
                    if (typeTable != null && (object)typeTable.GetMembers <T>(this.mshOwner.InternalTypeNames)[member.Name] != null)
                    {
                        throw new ExtendedTypeSystemException("AlreadyPresentInTypesXml", (Exception)null, "ExtendedTypeSystem", "MemberAlreadyPresentFromTypesXml", new object[1]
                        {
                            (object)member.Name
                        });
                    }
                }
                member1.ReplicateInstance(this.mshOwner);
                this.mshOwner.InstanceMembers.Add(member1, preValidated);
            }
            else
            {
                this.memberSetOwner.InternalMembers.Add(member1, preValidated);
            }
        }
Exemplo n.º 5
0
 internal PSMemberInfo GetPSMemberInfo(DynamicMetaObject target, out BindingRestrictions restrictions, out bool canOptimize, out Type aliasConversionType, HashSet <string> aliases = null, List <BindingRestrictions> aliasRestrictions = null)
 {
     lock (this)
     {
         aliasConversionType = null;
         if (this._static)
         {
             restrictions = typeof(Type).IsAssignableFrom(target.LimitType) ? BindingRestrictions.GetInstanceRestriction(target.Expression, target.Value) : target.PSGetTypeRestriction();
             restrictions = restrictions.Merge(BinderUtils.GetVersionCheck(this, this._version));
             canOptimize  = true;
             return(PSObject.GetStaticCLRMember(target.Value, base.Name));
         }
         canOptimize = false;
         PSMemberInfo       info  = null;
         ConsolidatedString types = null;
         ExecutionContext   executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS();
         TypeTable          typeTable = (executionContextFromTLS != null) ? executionContextFromTLS.TypeTable : null;
         if (this._hasTypeTableMember)
         {
             types = PSObject.GetTypeNames(target.Value);
             if (typeTable != null)
             {
                 info = typeTable.GetMembers <PSMemberInfo>(types)[base.Name];
                 if (info != null)
                 {
                     canOptimize = true;
                 }
             }
         }
         object obj2 = PSObject.Base(target.Value);
         PSObject.AdapterSet mappedAdapter = PSObject.GetMappedAdapter(obj2, typeTable);
         if (info == null)
         {
             canOptimize = mappedAdapter.OriginalAdapter.SiteBinderCanOptimize;
             if (canOptimize)
             {
                 info = mappedAdapter.OriginalAdapter.BaseGetMember <PSMemberInfo>(obj2, base.Name);
             }
         }
         if (((info == null) && canOptimize) && (mappedAdapter.DotNetAdapter != null))
         {
             info = mappedAdapter.DotNetAdapter.BaseGetMember <PSMemberInfo>(obj2, base.Name);
         }
         restrictions = BinderUtils.GetVersionCheck(this, this._version);
         PSAliasProperty alias = info as PSAliasProperty;
         if (alias != null)
         {
             aliasConversionType = alias.ConversionType;
             if (aliasRestrictions == null)
             {
                 aliasRestrictions = new List <BindingRestrictions>();
             }
             info = ResolveAlias(alias, target, aliases, aliasRestrictions);
             if (info == null)
             {
                 canOptimize = false;
             }
             else
             {
                 foreach (BindingRestrictions restrictions2 in aliasRestrictions)
                 {
                     restrictions = restrictions.Merge(restrictions2);
                 }
             }
         }
         if (this._hasInstanceMember)
         {
             restrictions = restrictions.Merge(this.NotInstanceMember(target));
         }
         restrictions = restrictions.Merge(target.PSGetTypeRestriction());
         if (this._hasTypeTableMember)
         {
             restrictions = restrictions.Merge(BindingRestrictions.GetInstanceRestriction(Expression.Call(CachedReflectionInfo.PSGetMemberBinder_GetTypeTableFromTLS, new Expression[0]), typeTable));
             restrictions = restrictions.Merge(BindingRestrictions.GetExpressionRestriction(Expression.Call(CachedReflectionInfo.PSGetMemberBinder_IsTypeNameSame, target.Expression.Cast(typeof(object)), Expression.Constant(types.Key))));
         }
         return(info);
     }
 }