예제 #1
0
        private IEnumerable <DynamicMemberDescriptor> GetMemberDescriptorForSpecItem(DynamicMemberSpecification spec, PSObject ps, object specItem, DynamicMemberDescriptor byProperty)
        {
            var    list              = new List <DynamicMemberDescriptor>();
            var    specMember        = specItem as PSPropertyInfo;
            string proxyPropertyName = null;

            if (null != byProperty && null != byProperty.MemberInfo)
            {
                proxyPropertyName = byProperty.MemberInfo.Name;
            }

            if (null != specMember)
            {
                var name = specItem.ToString();

                var psp = specMember as PSScriptProperty;
                if (null != psp)
                {
                    name = ScriptBlockDynamicPropertyArgumentTransformationAttribute.GetReadableName(psp);
                }

                if (null != byProperty && null != byProperty.IndexValue)
                {
                    name = byProperty.IndexValue.ToString() + "\\" + name;
                    //name.Replace("$", "").Replace("{","").Replace("}","").Replace(".","");
                }

                CreateDynamicMemberProperty(ref specMember, "_" + Guid.NewGuid().ToString(), proxyPropertyName);
                IScaleDescriptor scale = new DynamicPropertyScaleDescriptor(_dataSource, specMember.Name);
                scale = (from sd in spec.ScaleDescriptors
                         where sd.Key.IsMatch(name)
                         select sd.Value).FirstOrDefault() ??
                        (from sd in spec.ScaleDescriptors
                         where sd.Key.IsMatch(specMember.Name)
                         select sd.Value).FirstOrDefault() ??
                        scale;

                spec.ScaleDescriptors.Add(new Regex(Regex.Escape(specMember.Name)), scale);
                //var assignment = AddDynamicScaleForProperty(specMember.Name);


                list.Add(new DynamicMemberDescriptor(specMember, scale, name));
            }
            else if (specItem is string && WildcardPattern.ContainsWildcardCharacters(specItem.ToString()))
            {
                var p       = new WildcardPattern(specItem.ToString());
                var members = AddWildcardDynamicMembers(spec, p, ps, proxyPropertyName);
                foreach (var member in members)
                {
                    list.Add(member);
                }
            }
            else
            {
                var name = specItem.ToString();
                if (null != byProperty && null != byProperty.IndexValue)
                {
                    name = byProperty.IndexValue.ToString() + "\\" + name;
                }

                if (null != proxyPropertyName)
                {
                    var m     = CreateDynamicMemberProperty(specItem.ToString(), proxyPropertyName);
                    var scale = (from sd in spec.ScaleDescriptors
                                 where sd.Key.IsMatch(m.Name)
                                 select sd.Value).FirstOrDefault();
                    //var s = GetOrCreateScaleAssignment(name, m).Scale;
                    list.Add(new DynamicMemberDescriptor(m, scale, name));
                }
                else
                {
                    var scale = (from sd in spec.ScaleDescriptors
                                 where sd.Key.IsMatch(name)
                                 select sd.Value).FirstOrDefault();
                    if (null == ps.Properties[name])
                    {
                        //throw new DataPropertyNotFoundException(name);

                        list.Add(new DynamicMemberDescriptor(
                                     new PSScriptProperty(
                                         "_" + Guid.NewGuid().ToString("N") + "_" + name,
                                         ScriptBlock.Create(String.Format("$local:val = $this.'{0}'; if( $local:val ) {{ $local:val }} else {{ 0 }}", specItem.ToString()))
                                         ),
                                     scale,
                                     name
                                     )
                                 );
                    }
                    list.Add(new DynamicMemberDescriptor(ps.Properties[name], scale, name));
                }
            }

            return(list);
        }
예제 #2
0
        private IEnumerable<DynamicMemberDescriptor> GetMemberDescriptorForSpecItem(DynamicMemberSpecification spec, PSObject ps, object specItem, DynamicMemberDescriptor byProperty)
        {
            var list = new List<DynamicMemberDescriptor>();
            var specMember = specItem as PSPropertyInfo;
            string proxyPropertyName = null;

            if( null != byProperty && null != byProperty.MemberInfo )
            {
                proxyPropertyName = byProperty.MemberInfo.Name;
            }

            if (null != specMember)
            {
                var name = specItem.ToString();

                var psp = specMember as PSScriptProperty;
                if (null != psp)
                {
                    name = ScriptBlockDynamicPropertyArgumentTransformationAttribute.GetReadableName(psp);
                }

                if (null != byProperty && null != byProperty.IndexValue)
                {
                    name = byProperty.IndexValue.ToString() + "\\" + name;
                    //name.Replace("$", "").Replace("{","").Replace("}","").Replace(".","");
                }

                CreateDynamicMemberProperty(ref specMember, "_" + Guid.NewGuid().ToString(), proxyPropertyName);
                IScaleDescriptor scale = new DynamicPropertyScaleDescriptor(_dataSource, specMember.Name);
                scale = (from sd in spec.ScaleDescriptors
                         where sd.Key.IsMatch(name)
                         select sd.Value).FirstOrDefault() ??
                        (from sd in spec.ScaleDescriptors
                         where sd.Key.IsMatch(specMember.Name)
                         select sd.Value).FirstOrDefault() ??
                        scale;

                spec.ScaleDescriptors.Add( new Regex( Regex.Escape(specMember.Name)), scale );
                //var assignment = AddDynamicScaleForProperty(specMember.Name);

                list.Add( new DynamicMemberDescriptor(specMember, scale, name) );
            }
            else if (specItem is string && WildcardPattern.ContainsWildcardCharacters(specItem.ToString()))
            {
                var p = new WildcardPattern(specItem.ToString());
                var members = AddWildcardDynamicMembers(spec, p, ps, proxyPropertyName);
                foreach (var member in members)
                {

                    list.Add(member);
                }
            }
            else
            {
                var name = specItem.ToString();
                if( null != byProperty && null != byProperty.IndexValue )
                {
                    name = byProperty.IndexValue.ToString() + "\\" + name;
                }

                if (null != proxyPropertyName)
                {
                    var m = CreateDynamicMemberProperty(specItem.ToString(), proxyPropertyName);
                    var scale = (from sd in spec.ScaleDescriptors
                                 where sd.Key.IsMatch(m.Name)
                                 select sd.Value).FirstOrDefault();
                    //var s = GetOrCreateScaleAssignment(name, m).Scale;
                    list.Add(new DynamicMemberDescriptor(m, scale, name));
                }
                else
                {
                    var scale = (from sd in spec.ScaleDescriptors
                                 where sd.Key.IsMatch(name)
                                 select sd.Value).FirstOrDefault();
                    if (null == ps.Properties[name])
                    {
                        //throw new DataPropertyNotFoundException(name);

                        list.Add(new DynamicMemberDescriptor(
                            new PSScriptProperty(
                                "_" + Guid.NewGuid().ToString("N") + "_" + name,
                                ScriptBlock.Create(String.Format("$local:val = $this.'{0}'; if( $local:val ) {{ $local:val }} else {{ 0 }}", specItem.ToString()))
                                ),
                            scale,
                            name
                            )
                        );
                    }
                    list.Add(new DynamicMemberDescriptor(ps.Properties[name],scale,name));
                }
            }

            return list;
        }