Exemplo n.º 1
0
        public static PSObject WrapElement(AutomationElement element)
        {
            var psObj = new PSObject(element);

            foreach (var prop in element.GetSupportedProperties())
            {
                if (prop.Id == AutomationElement.NameProperty.Id ||
                    prop.Id == AutomationElement.ControlTypeProperty.Id)
                {
                    continue;
                }

                string name   = Automation.PropertyName(prop);
                string script = string.Format("$this.GetCurrentPropertyValue([System.Windows.Automation.AutomationProperty]::LookupById({0}))", prop.Id);
                var    psProp = new PSScriptProperty(name, ScriptBlock.Create(script));
                psObj.Properties.Add(psProp);
            }

            foreach (var pattern in element.GetSupportedPatterns())
            {
                string name   = Automation.PatternName(pattern) + "Pattern";
                string script = string.Format("$this.GetCurrentPattern([System.Windows.Automation.AutomationPattern]::LookupById({0}))", pattern.Id);
                var    psProp = new PSScriptProperty(name, ScriptBlock.Create(script));
                psObj.Properties.Add(psProp);
            }
            return(psObj);
        }
Exemplo n.º 2
0
        public static string GetReadableName(PSScriptProperty prop)
        {
            var getter = prop.GetterScript;

            var name = getter.ToString().Replace("if( -not($_) ){ $_ = $this; } ", "");

            return(String.Format("{{ {0} }}", name));
        }
Exemplo n.º 3
0
        private IEnumerable <DynamicMemberDescriptor> CreateMemberDescriptors(DynamicMemberSpecification spec, PSObject ps, DynamicMemberDescriptor byItemMember)
        {
            var list = new List <DynamicMemberDescriptor>();
            PSScriptProperty scriptProperty = null;

            var plotItemMembers = UpdatePlotItemMembers(spec, ps, byItemMember);

            list.AddRange(plotItemMembers);
            list.Add(UpdateAgainstItemMember(spec, ps, byItemMember));
            return(list);
        }
Exemplo n.º 4
0
        private void CreateDynamicMemberProperty(ref PSPropertyInfo plotMember, string name, string proxyPropertyName)
        {
            if (String.IsNullOrEmpty(proxyPropertyName))
            {
                return;
            }

            var pm     = plotMember as PSScriptProperty;
            var script = String.Format("$this.'{0}' | foreach-object  {{ {1} }}", proxyPropertyName, pm.GetterScript);

            plotMember = new PSScriptProperty(name, System.Management.Automation.ScriptBlock.Create(script));
        }
Exemplo n.º 5
0
        public DynamicMemberSpecification(object[] plotItems, object againstItem, PSScriptProperty acrossSpecifier, PSScriptProperty indexSpecifier,
                                          IDictionary <Regex, IScaleDescriptor> scaleDescriptors)
        {
            if (plotItems == null)
            {
                throw new ArgumentNullException("plotItems");
            }

            _scaleDescriptors    = scaleDescriptors;
            _plotItemDescriptors = new List <DynamicMemberDescriptor>();
            _plotItems           = plotItems;
            _againstItem         = againstItem;
            _acrossSpecifier     = acrossSpecifier;
            _indexSpecifier      = indexSpecifier;
        }
Exemplo n.º 6
0
        object TransformItem(EngineIntrinsics engineIntrinsics, object inputData)
        {
            var inputObject = inputData.ToPSObject().BaseObject;

            var scriptBlock = inputObject as ScriptBlock;

            if (null == scriptBlock)
            {
                return(inputData);
            }

            scriptBlock = ScriptBlock.Create("if( -not($_) ){ $_ = $this; } " + scriptBlock);

            var property = new PSScriptProperty("_" + Guid.NewGuid().ToString("N"), scriptBlock);

            return(property);
        }
Exemplo n.º 7
0
        void WriteResult(ulong sz, string p)
        {
            PSObject o = new PSObject();

            // probably should just calculate that here and insert it as another column
            string human = @"switch($this.Length) { { $_ -gt 1tb } 
                        { ""{ 0:n2}T"" -f ($_ / 1tb) ; break }
                    { $_ -gt 1gb }
                        { ""{0:n2}G"" -f ($_ / 1gb) ; break }
                    { $_ -gt 1mb }
                        { ""{0:n2}M"" -f ($_ / 1mb) ; break }
                    { $_ -gt 1kb }
                        { ""{0:n2}K"" -f ($_ / 1Kb) ; break }
                    default
                        { ""{0}"" -f $_}
                } 
            ";

            string[] props  = { "Length", "FullName" };
            string[] propsh = { "ReadableLength", "FullName" };

            ScriptBlock      sb  = ScriptBlock.Create(human);
            PSScriptProperty psp = new PSScriptProperty("ReadableLength", sb);
            PSPropertySet    ps;

            if (humanreadable)
            {
                ps = new PSPropertySet("DefaultDisplayPropertySet", propsh);
            }
            else
            {
                ps = new PSPropertySet("DefaultDisplayPropertySet", props);
            }

            PSMemberSet pm = new PSMemberSet("PSStandardMembers", new PSMemberInfo[] { ps });

            // pm.Members.Add();

            o.Members.Add(pm);

            o.Properties.Add(new PSNoteProperty("Length", sz));
            o.Properties.Add(new PSNoteProperty("FullName", p));
            o.Members.Add(psp);

            WriteObject(o);
        }
Exemplo n.º 8
0
        public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
        {
            if (null == inputData)
            {
                return(inputData);
            }

            var inputObject = inputData.ToPSObject().BaseObject;

            var name = inputObject as ScriptBlock;

            if (null == name)
            {
                return(inputData);
            }

            var scriptBlock = ScriptBlock.Create("group-object -property {" + name + "}");

            var property = new PSScriptProperty("_GroupObjectScript_" + Guid.NewGuid().ToString("N"), scriptBlock);

            return(property);
        }
        public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
        {
            if (null == inputData)
            {
                return(inputData);
            }

            var inputObject = inputData.ToPSObject().BaseObject;

            var name = inputObject as string;

            if (null == name)
            {
                return(inputData);
            }

            var scriptBlock = ScriptBlock.Create("@($this | select-object -expand '" + name + "' )");

            var property = new PSScriptProperty("_SelectExpand" + Guid.NewGuid().ToString("N"), scriptBlock);

            return(property);
        }
Exemplo n.º 10
0
        public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
        {
            if (null == inputData)
            {
                return(inputData);
            }

            var inputObject = inputData.ToPSObject().BaseObject;

            var name = inputObject as string;

            if (null == name)
            {
                return(inputData);
            }

            var scriptBlock = ScriptBlock.Create("group-object -property '" + name + "'");

            var property = new PSScriptProperty("_GroupObject" + name, scriptBlock);

            return(property);
        }
Exemplo n.º 11
0
        public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
        {
            PSMemberInfo        info;
            BindingRestrictions restrictions2;
            bool flag3;
            Type type4;

            if (!target.HasValue || !value.HasValue)
            {
                return(base.Defer(target, new DynamicMetaObject[] { value }));
            }
            object obj2 = PSObject.Base(target.Value);

            if (obj2 == null)
            {
                return(target.ThrowRuntimeError(new DynamicMetaObject[] { value }, BindingRestrictions.Empty, "PropertyNotFound", ParserStrings.PropertyNotFound, new Expression[] { Expression.Constant(base.Name) }).WriteToDebugLog(this));
            }
            if (value.Value == AutomationNull.Value)
            {
                value = new DynamicMetaObject(ExpressionCache.NullConstant, value.PSGetTypeRestriction(), null);
            }
            if (this._getMemberBinder.HasInstanceMember && PSGetMemberBinder.TryGetInstanceMember(target.Value, base.Name, out info))
            {
                ParameterExpression   expression   = Expression.Variable(typeof(PSMemberInfo));
                ParameterExpression   expression2  = Expression.Variable(typeof(object));
                ConditionalExpression expression3  = Expression.Condition(Expression.Call(CachedReflectionInfo.PSGetMemberBinder_TryGetInstanceMember, target.Expression.Cast(typeof(object)), Expression.Constant(base.Name), expression), Expression.Assign(Expression.Property(expression, "Value"), value.Expression.Cast(typeof(object))), base.GetUpdateExpression(typeof(object)));
                BindingRestrictions   restrictions = BinderUtils.GetVersionCheck(this._getMemberBinder, this._getMemberBinder._version).Merge(value.PSGetTypeRestriction());
                return(new DynamicMetaObject(Expression.Block(new ParameterExpression[] { expression, expression2 }, new Expression[] { expression3 }), restrictions).WriteToDebugLog(this));
            }
            if (obj2 is IDictionary)
            {
                Type genericTypeArg = null;
                bool flag           = PSGetMemberBinder.IsGenericDictionary(obj2, ref genericTypeArg);
                if (!flag || (genericTypeArg != null))
                {
                    bool                flag2;
                    Type                type       = flag ? typeof(IDictionary <,>).MakeGenericType(new Type[] { typeof(string), genericTypeArg }) : typeof(IDictionary);
                    MethodInfo          method     = type.GetMethod("set_Item");
                    ParameterExpression left       = Expression.Variable(genericTypeArg ?? typeof(object));
                    Type                resultType = left.Type;
                    LanguagePrimitives.ConversionData conversion = LanguagePrimitives.FigureConversion(value.Value, resultType, out flag2);
                    if (conversion.Rank != ConversionRank.None)
                    {
                        Expression right = PSConvertBinder.InvokeConverter(conversion, value.Expression, resultType, flag2, ExpressionCache.InvariantCulture);
                        return(new DynamicMetaObject(Expression.Block(new ParameterExpression[] { left }, new Expression[] { Expression.Assign(left, right), Expression.Call(PSGetMemberBinder.GetTargetExpr(target).Cast(type), method, Expression.Constant(base.Name), right), right.Cast(typeof(object)) }), target.CombineRestrictions(new DynamicMetaObject[] { value })).WriteToDebugLog(this));
                    }
                }
            }
            info          = this._getMemberBinder.GetPSMemberInfo(target, out restrictions2, out flag3, out type4, null, null);
            restrictions2 = restrictions2.Merge(value.PSGetTypeRestriction());
            if (ExecutionContext.HasEverUsedConstrainedLanguage)
            {
                restrictions2 = restrictions2.Merge(BinderUtils.GetLanguageModeCheckIfHasEverUsedConstrainedLanguage());
                DynamicMetaObject obj3 = PSGetMemberBinder.EnsureAllowedInLanguageMode(LocalPipeline.GetExecutionContextFromTLS().LanguageMode, target, obj2, base.Name, this._static, new DynamicMetaObject[] { value }, restrictions2, "PropertySetterNotSupportedInConstrainedLanguage", ParserStrings.PropertySetConstrainedLanguage);
                if (obj3 != null)
                {
                    return(obj3.WriteToDebugLog(this));
                }
            }
            if (flag3)
            {
                if (info == null)
                {
                    return((errorSuggestion ?? new DynamicMetaObject(Compiler.ThrowRuntimeError("PropertyAssignmentException", ParserStrings.PropertyNotFound, this.ReturnType, new Expression[] { Expression.Constant(base.Name) }), restrictions2)).WriteToDebugLog(this));
                }
                PSPropertyInfo info3 = info as PSPropertyInfo;
                if (info3 != null)
                {
                    if (!info3.IsSettable)
                    {
                        Expression innerException = Expression.New(CachedReflectionInfo.SetValueException_ctor, new Expression[] { Expression.Constant("PropertyAssignmentException"), Expression.Constant(null, typeof(Exception)), Expression.Constant(ParserStrings.PropertyIsReadOnly), Expression.NewArrayInit(typeof(object), new Expression[] { Expression.Constant(base.Name) }) });
                        return(new DynamicMetaObject(Compiler.ThrowRuntimeErrorWithInnerException("PropertyAssignmentException", Expression.Constant(ParserStrings.PropertyIsReadOnly), innerException, this.ReturnType, new Expression[] { Expression.Constant(base.Name) }), restrictions2).WriteToDebugLog(this));
                    }
                    PSProperty property = info3 as PSProperty;
                    if (property != null)
                    {
                        DotNetAdapter.PropertyCacheEntry adapterData = property.adapterData as DotNetAdapter.PropertyCacheEntry;
                        if (adapterData != null)
                        {
                            Expression expression10;
                            Type       propertyType;
                            if (adapterData.member.DeclaringType.IsGenericTypeDefinition)
                            {
                                Expression expression9 = Expression.New(CachedReflectionInfo.SetValueException_ctor, new Expression[] { Expression.Constant("PropertyAssignmentException"), Expression.Constant(null, typeof(Exception)), Expression.Constant(ExtendedTypeSystem.CannotInvokeStaticMethodOnUninstantiatedGenericType), Expression.NewArrayInit(typeof(object), new Expression[] { Expression.Constant(adapterData.member.DeclaringType.FullName) }) });
                                return(new DynamicMetaObject(Compiler.ThrowRuntimeErrorWithInnerException("PropertyAssignmentException", Expression.Constant(ExtendedTypeSystem.CannotInvokeStaticMethodOnUninstantiatedGenericType), expression9, this.ReturnType, new Expression[] { Expression.Constant(adapterData.member.DeclaringType.FullName) }), restrictions2).WriteToDebugLog(this));
                            }
                            PropertyInfo member = adapterData.member as PropertyInfo;
                            if (member != null)
                            {
                                propertyType = member.PropertyType;
                                Expression expression11 = this._static ? null : PSGetMemberBinder.GetTargetExpr(target);
                                expression10 = Expression.Property(expression11, member);
                            }
                            else
                            {
                                FieldInfo field = (FieldInfo)adapterData.member;
                                propertyType = field.FieldType;
                                Expression expression12 = this._static ? null : PSGetMemberBinder.GetTargetExpr(target);
                                expression10 = Expression.Field(expression12, field);
                            }
                            Type underlyingType = Nullable.GetUnderlyingType(propertyType);
                            Type type7          = underlyingType ?? propertyType;
                            ParameterExpression expression13 = Expression.Variable(type7);
                            Expression          expression14 = (underlyingType != null) ? ((value.Value == null) ? ((Expression)Expression.Constant(null, propertyType)) : ((Expression)Expression.New(propertyType.GetConstructor(new Type[] { underlyingType }), new Expression[] { expression13 }))) : ((Expression)expression13);
                            Expression          expression15 = (type7.Equals(typeof(object)) && value.LimitType.Equals(typeof(PSObject))) ? Expression.Call(CachedReflectionInfo.PSObject_Base, value.Expression.Cast(typeof(PSObject))) : value.CastOrConvert(type7);
                            Expression          expr         = Expression.Block(new ParameterExpression[] { expression13 }, new Expression[] { Expression.Assign(expression13, expression15), Expression.Assign(expression10, expression14), expression13.Cast(typeof(object)) });
                            ParameterExpression variable     = Expression.Variable(typeof(Exception));
                            return(new DynamicMetaObject(Expression.TryCatch(expr.Cast(typeof(object)), new CatchBlock[] { Expression.Catch(variable, Expression.Block(Expression.Call(CachedReflectionInfo.ExceptionHandlingOps_ConvertToMethodInvocationException, variable, Expression.Constant(typeof(SetValueInvocationException)), Expression.Constant(base.Name), ExpressionCache.Constant(0), Expression.Constant(null, typeof(MemberInfo))), Expression.Rethrow(typeof(object)))) }), restrictions2).WriteToDebugLog(this));
                        }
                    }
                    PSCodeProperty property2 = info3 as PSCodeProperty;
                    if (property2 != null)
                    {
                        ParameterExpression expression17 = Expression.Variable(typeof(object));
                        return(new DynamicMetaObject(Expression.Block(new ParameterExpression[] { expression17 }, new Expression[] { Expression.Assign(expression17, value.CastOrConvert(expression17.Type)), PSInvokeMemberBinder.InvokeMethod(property2.SetterCodeReference, null, new DynamicMetaObject[] { target, value }, false), expression17 }), restrictions2).WriteToDebugLog(this));
                    }
                    PSScriptProperty property3 = info3 as PSScriptProperty;
                    if (property3 != null)
                    {
                        return(new DynamicMetaObject(Expression.Call(Expression.Constant(property3), CachedReflectionInfo.PSScriptProperty_InvokeSetter, PSGetMemberBinder.GetTargetExpr(target), value.Expression.Cast(typeof(object))), restrictions2).WriteToDebugLog(this));
                    }
                }
                if (errorSuggestion != null)
                {
                    return(errorSuggestion.WriteToDebugLog(this));
                }
            }
            return(new DynamicMetaObject(Expression.Call(CachedReflectionInfo.PSSetMemberBinder_SetAdaptedValue, PSGetMemberBinder.GetTargetExpr(target).Cast(typeof(object)), Expression.Constant(base.Name), value.Expression.Cast(typeof(object))), restrictions2).WriteToDebugLog(this));
        }
        IEnumerable <TSeriesViewModel> CreatePlotSeriesViewModels(object[] plotItems, object againstItem, PSScriptProperty acrossItem, PSScriptProperty indexItem)
        {
            var dataSource = DataSource;

            _spec = new DynamicMemberSpecification(plotItems, againstItem, acrossItem, indexItem, ScaleDescriptorTable);
            dataSource.AddDynamicMemberSpecification(_spec);

            if (0 < dataSource.Data.Count || 0 < dataSource.AllRecords.Count)
            {
                CreateAndAddSeriesViewModels();
            }
            else
            {
                dataSource.Data.CollectionChanged       += OnFirstDataItem;
                dataSource.AllRecords.CollectionChanged += OnFirstDataItem;
            }
            return(null);
        }
Exemplo n.º 13
0
        private IEnumerable <DynamicMemberDescriptor> CreateByItemMemberDescriptors(DynamicMemberSpecification spec, PSObject ps)
        {
            if (null == spec.AcrossSpecifier)
            {
                return(new DynamicMemberDescriptor[] { });
            }
            var list = new List <DynamicMemberDescriptor>();
            var acrossAccessorName = spec.AcrossSpecifier.Name;

            ps.Properties.Add(spec.AcrossSpecifier);
            var    sps   = new PSObjectSolidifier().AsConcreteType(ps) as SolidPSObjectBase;
            object oitem = sps.GetPropValue <object>(acrossAccessorName);

            ps.Properties.Remove(acrossAccessorName);

            var items = oitem as ICollection;

            if (null == items)
            {
                items = new object[] { oitem };
            }

            if (null == spec.IndexSpecifier)
            {
                for (int i = 0; i < items.Count; ++i)
                {
                    var byItemScript = String.Format("$this.'{1}' | select-object -index '{0}'", i, acrossAccessorName);
                    var prop         = new PSScriptProperty(
                        acrossAccessorName + i,
                        System.Management.Automation.ScriptBlock.Create(byItemScript));
                    var scale = (from sd in spec.ScaleDescriptors
                                 where sd.Key.IsMatch(prop.Name)
                                 select sd.Value).FirstOrDefault();
                    list.Add(new DynamicMemberDescriptor(prop, scale, "Index " + i));
                }
            }
            else
            {
                foreach (var item in items)
                {
                    var pso          = item.ToPSObject();
                    var tempProperty = new PSScriptProperty(
                        "_" + Guid.NewGuid().ToString("N"),
                        System.Management.Automation.ScriptBlock.Create(
                            "$this | " + spec.IndexSpecifier.GetterScript));
                    pso.Properties.Add(tempProperty);
                    var specValue = pso.Properties[tempProperty.Name].Value.ToPSObject();
                    pso.Properties.Remove(tempProperty.Name);
                    var name = specValue.Properties["Name"].Value;

                    var byItemScript =
                        String.Format("$this.'{1}' | {2} | where {{ $_.Name -eq '{0}' }} | select -expand Group",
                                      name, acrossAccessorName, spec.IndexSpecifier.GetterScript);
                    var prop = new PSScriptProperty(
                        acrossAccessorName + "_" + name,
                        System.Management.Automation.ScriptBlock.Create(byItemScript));
                    var scale = (from sd in spec.ScaleDescriptors
                                 where sd.Key.IsMatch(prop.Name)
                                 select sd.Value).FirstOrDefault();
                    list.Add(new DynamicMemberDescriptor(prop, scale, name));
                }
            }
            return(list);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Create a script property from a script property
 /// </summary>
 /// <param name="Property">The property to add</param>
 public SelectScriptPropertyParameter(PSScriptProperty Property)
 {
     InputObject = Property;
     Value.Add(Property);
 }
Exemplo n.º 15
0
 public DynamicMemberSpecification(object[] plotItems, object againstItem, PSScriptProperty acrossSpecifier, PSScriptProperty indexSpecifier)
     : this(plotItems, againstItem, acrossSpecifier, indexSpecifier, new Dictionary <Regex, IScaleDescriptor>())
 {
 }
Exemplo n.º 16
0
        internal override IEnumerable <PSTypeName> GetInferredType(CompletionContext context)
        {
            StringConstantExpressionAst member = this.Member as StringConstantExpressionAst;

            if (member != null)
            {
                PSTypeName[] iteratorVariable1;
                if (this.Static)
                {
                    TypeExpressionAst expression = this.Expression as TypeExpressionAst;
                    if (expression == null)
                    {
                        goto Label_064A;
                    }
                    Type type = expression.TypeName.GetReflectionType();
                    if (type == null)
                    {
                        goto Label_064A;
                    }
                    iteratorVariable1 = new PSTypeName[] { new PSTypeName(type) };
                }
                else
                {
                    iteratorVariable1 = this.Expression.GetInferredType(context).ToArray <PSTypeName>();
                    if (iteratorVariable1.Length == 0)
                    {
                        goto Label_064A;
                    }
                }
                List <string> iteratorVariable2 = new List <string> {
                    member.Value
                };
                foreach (PSTypeName iteratorVariable3 in iteratorVariable1)
                {
                    IEnumerable <object> iteratorVariable4 = CompletionCompleters.GetMembersByInferredType(iteratorVariable3, this.Static, context);
                    for (int i = 0; i < iteratorVariable2.Count; i++)
                    {
                        string iteratorVariable6 = iteratorVariable2[i];
                        foreach (object iteratorVariable7 in iteratorVariable4)
                        {
                            PropertyInfo iteratorVariable8 = iteratorVariable7 as PropertyInfo;
                            if (iteratorVariable8 != null)
                            {
                                if (iteratorVariable8.Name.Equals(iteratorVariable6, StringComparison.OrdinalIgnoreCase) && !(this is InvokeMemberExpressionAst))
                                {
                                    yield return(new PSTypeName(iteratorVariable8.PropertyType));

                                    break;
                                }
                            }
                            else
                            {
                                FieldInfo iteratorVariable9 = iteratorVariable7 as FieldInfo;
                                if (iteratorVariable9 != null)
                                {
                                    if (iteratorVariable9.Name.Equals(iteratorVariable6, StringComparison.OrdinalIgnoreCase) && !(this is InvokeMemberExpressionAst))
                                    {
                                        yield return(new PSTypeName(iteratorVariable9.FieldType));

                                        break;
                                    }
                                    continue;
                                }
                                DotNetAdapter.MethodCacheEntry iteratorVariable10 = iteratorVariable7 as DotNetAdapter.MethodCacheEntry;
                                if (iteratorVariable10 != null)
                                {
                                    if (iteratorVariable10[0].method.Name.Equals(iteratorVariable6, StringComparison.OrdinalIgnoreCase))
                                    {
                                        if (!(this is InvokeMemberExpressionAst))
                                        {
                                            yield return(new PSTypeName(typeof(PSMethod)));

                                            break;
                                        }
                                        foreach (MethodInformation iteratorVariable11 in iteratorVariable10.methodInformationStructures)
                                        {
                                            MethodInfo method = iteratorVariable11.method as MethodInfo;
                                            if ((method != null) && !method.ReturnType.ContainsGenericParameters)
                                            {
                                                yield return(new PSTypeName(method.ReturnType));
                                            }
                                        }
                                        break;
                                    }
                                    continue;
                                }
                                PSMemberInfo iteratorVariable13 = iteratorVariable7 as PSMemberInfo;
                                if ((iteratorVariable13 != null) && iteratorVariable13.Name.Equals(iteratorVariable6, StringComparison.OrdinalIgnoreCase))
                                {
                                    PSNoteProperty iteratorVariable14 = iteratorVariable7 as PSNoteProperty;
                                    if (iteratorVariable14 != null)
                                    {
                                        yield return(new PSTypeName(iteratorVariable14.Value.GetType()));

                                        break;
                                    }
                                    PSAliasProperty iteratorVariable15 = iteratorVariable7 as PSAliasProperty;
                                    if (iteratorVariable15 != null)
                                    {
                                        iteratorVariable2.Add(iteratorVariable15.ReferencedMemberName);
                                    }
                                    else
                                    {
                                        PSCodeProperty iteratorVariable16 = iteratorVariable7 as PSCodeProperty;
                                        if (iteratorVariable16 != null)
                                        {
                                            if (iteratorVariable16.GetterCodeReference != null)
                                            {
                                                yield return(new PSTypeName(iteratorVariable16.GetterCodeReference.ReturnType));

                                                break;
                                            }
                                        }
                                        else
                                        {
                                            ScriptBlock      getterScript       = null;
                                            PSScriptProperty iteratorVariable18 = iteratorVariable7 as PSScriptProperty;
                                            if (iteratorVariable18 != null)
                                            {
                                                getterScript = iteratorVariable18.GetterScript;
                                            }
                                            PSScriptMethod iteratorVariable19 = iteratorVariable7 as PSScriptMethod;
                                            if (iteratorVariable19 != null)
                                            {
                                                getterScript = iteratorVariable19.Script;
                                            }
                                            if (getterScript != null)
                                            {
                                                foreach (PSTypeName iteratorVariable20 in getterScript.OutputType)
                                                {
                                                    yield return(iteratorVariable20);
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
Label_064A:
            yield break;
        }
Exemplo n.º 17
0
        public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
        {
            BindingRestrictions restrictions;
            PSMemberInfo        info;
            bool flag;
            Type type;

            if (!target.HasValue)
            {
                return(base.Defer(target, new DynamicMetaObject[0]));
            }
            object obj2 = PSObject.Base(target.Value);

            if (obj2 == null)
            {
                return(this.PropertyDoesntExist(target, target.PSGetTypeRestriction()).WriteToDebugLog(this));
            }
            Expression expr = null;

            if (this._hasInstanceMember && TryGetInstanceMember(target.Value, base.Name, out info))
            {
                ParameterExpression expression2 = Expression.Variable(typeof(PSMemberInfo));
                expr = WrapGetMemberInTry(Expression.Condition(Expression.Call(CachedReflectionInfo.PSGetMemberBinder_TryGetInstanceMember, target.Expression.Cast(typeof(object)), Expression.Constant(base.Name), expression2), Expression.Property(expression2, "Value"), base.GetUpdateExpression(typeof(object))));
                return(new DynamicMetaObject(Expression.Block(new ParameterExpression[] { expression2 }, new Expression[] { expr }), BinderUtils.GetVersionCheck(this, this._version)).WriteToDebugLog(this));
            }
            info = this.GetPSMemberInfo(target, out restrictions, out flag, out type, null, null);
            if (!flag)
            {
                return(new DynamicMetaObject(WrapGetMemberInTry(Expression.Call(CachedReflectionInfo.PSGetMemberBinder_GetAdaptedValue, GetTargetExpr(target).Cast(typeof(object)), Expression.Constant(base.Name))), restrictions).WriteToDebugLog(this));
            }
            if (info != null)
            {
                PSPropertyInfo info2 = info as PSPropertyInfo;
                if (info2 != null)
                {
                    if (!info2.IsGettable)
                    {
                        return(new DynamicMetaObject(Compiler.ThrowRuntimeError("WriteOnlyProperty", ExtendedTypeSystem.WriteOnlyProperty, this.ReturnType, new Expression[] { Expression.Constant(base.Name) }), restrictions).WriteToDebugLog(this));
                    }
                    PSProperty property = info2 as PSProperty;
                    if (property != null)
                    {
                        DotNetAdapter.PropertyCacheEntry adapterData = property.adapterData as DotNetAdapter.PropertyCacheEntry;
                        if (!adapterData.member.DeclaringType.IsGenericTypeDefinition)
                        {
                            Expression   expression = this._static ? null : GetTargetExpr(target);
                            PropertyInfo member     = adapterData.member as PropertyInfo;
                            if (member != null)
                            {
                                expr = Expression.Property(expression, member);
                            }
                            else
                            {
                                expr = Expression.Field(expression, (FieldInfo)adapterData.member);
                            }
                        }
                        else
                        {
                            expr = ExpressionCache.NullConstant;
                        }
                    }
                    PSScriptProperty property2 = info2 as PSScriptProperty;
                    if (property2 != null)
                    {
                        expr = Expression.Call(Expression.Constant(property2), CachedReflectionInfo.PSScriptProperty_InvokeGetter, new Expression[] { target.Expression.Cast(typeof(object)) });
                    }
                    PSCodeProperty property3 = info2 as PSCodeProperty;
                    if (property3 != null)
                    {
                        expr = PSInvokeMemberBinder.InvokeMethod(property3.GetterCodeReference, null, new DynamicMetaObject[] { target }, false);
                    }
                    if (info2 is PSNoteProperty)
                    {
                        expr = Expression.Property(Expression.Constant(info2), CachedReflectionInfo.PSNoteProperty_Value);
                    }
                    if (type != null)
                    {
                        expr = expr.Convert(type);
                    }
                }
                else
                {
                    expr = Expression.Call(CachedReflectionInfo.PSGetMemberBinder_CloneMemberInfo, Expression.Constant(info).Cast(typeof(PSMemberInfo)), target.Expression.Cast(typeof(object)));
                }
            }
            if (obj2 is IDictionary)
            {
                Type genericTypeArg = null;
                bool flag2          = IsGenericDictionary(obj2, ref genericTypeArg);
                if (!flag2 || (genericTypeArg != null))
                {
                    ParameterExpression ifTrue = Expression.Variable(typeof(object));
                    if (expr == null)
                    {
                        expr = (errorSuggestion ?? this.PropertyDoesntExist(target, restrictions)).Expression;
                    }
                    MethodInfo method = flag2 ? CachedReflectionInfo.PSGetMemberBinder_TryGetGenericDictionaryValue.MakeGenericMethod(new Type[] { genericTypeArg }) : CachedReflectionInfo.PSGetMemberBinder_TryGetIDictionaryValue;
                    expr = Expression.Block(new ParameterExpression[] { ifTrue }, new Expression[] { Expression.Condition(Expression.Call(method, GetTargetExpr(target).Cast(method.GetParameters()[0].ParameterType), Expression.Constant(base.Name), ifTrue), ifTrue, expr.Cast(typeof(object))) });
                }
            }
            if (expr != null)
            {
                return(new DynamicMetaObject(WrapGetMemberInTry(expr), restrictions).WriteToDebugLog(this));
            }
            return((errorSuggestion ?? this.PropertyDoesntExist(target, restrictions)).WriteToDebugLog(this));
        }