コード例 #1
0
ファイル: ParameterMetadata.cs プロジェクト: nickchal/pash
 internal bool IsMatchingType(PSTypeName psTypeName)
 {
     Type fromType = psTypeName.Type;
     if (fromType != null)
     {
         bool flag = LanguagePrimitives.FigureConversion(typeof(object), this.ParameterType).Rank >= ConversionRank.AssignableS2A;
         if (fromType.Equals(typeof(object)))
         {
             return flag;
         }
         if (flag)
         {
             return ((psTypeName.Type != null) && psTypeName.Type.Equals(typeof(object)));
         }
         LanguagePrimitives.ConversionData data = LanguagePrimitives.FigureConversion(fromType, this.ParameterType);
         return ((data != null) && (data.Rank >= ConversionRank.NumericImplicitS2A));
     }
     WildcardPattern pattern = new WildcardPattern("*" + (psTypeName.Name ?? ""), WildcardOptions.CultureInvariant | WildcardOptions.IgnoreCase);
     if (pattern.IsMatch(this.ParameterType.FullName))
     {
         return true;
     }
     if (this.ParameterType.IsArray && pattern.IsMatch(this.ParameterType.GetElementType().FullName))
     {
         return true;
     }
     if (this.Attributes != null)
     {
         PSTypeNameAttribute attribute = this.Attributes.OfType<PSTypeNameAttribute>().FirstOrDefault<PSTypeNameAttribute>();
         if ((attribute != null) && pattern.IsMatch(attribute.PSTypeName))
         {
             return true;
         }
     }
     return false;
 }
コード例 #2
0
ファイル: Attributes.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Construct the attribute from an array of names of types.
 /// </summary>
 /// <param name="type">The types output by the cmdlet</param>
 public OutputTypeAttribute(params string[] type)
 {
     if (type != null && type.Length > 0)
     {
         Type = new PSTypeName[type.Length];
         for (int i = 0; i < type.Length; i++)
         {
             Type[i] = new PSTypeName(type[i]);
         }
     }
     else
     {
         Type = Utils.EmptyArray<PSTypeName>();
     }
 }
コード例 #3
0
ファイル: MemberExpressionAst.cs プロジェクト: nickchal/pash
 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;
 }
コード例 #4
0
ファイル: TypeMetadata.cs プロジェクト: dfinke/powershell
        internal bool IsMatchingType(PSTypeName psTypeName)
        {
            Type dotNetType = psTypeName.Type;
            if (dotNetType != null)
            {
                // ConstrainedLanguage note - This conversion is analyzed, but actually invoked via regular conversion.
                bool parameterAcceptsObjects =
                    ((int)(LanguagePrimitives.FigureConversion(typeof(object), this.ParameterType).Rank)) >=
                    (int)(ConversionRank.AssignableS2A);
                if (dotNetType.Equals(typeof(object)))
                {
                    return parameterAcceptsObjects;
                }
                if (parameterAcceptsObjects)
                {
                    return (psTypeName.Type != null) && (psTypeName.Type.Equals(typeof(object)));
                }

                // ConstrainedLanguage note - This conversion is analyzed, but actually invoked via regular conversion.
                var convertionData = LanguagePrimitives.FigureConversion(dotNetType, this.ParameterType);
                if (convertionData != null)
                {
                    if ((int)(convertionData.Rank) >= (int)(ConversionRank.NumericImplicitS2A))
                    {
                        return true;
                    }
                }

                return false;
            }

            var wildcardPattern = WildcardPattern.Get(
                "*" + (psTypeName.Name ?? ""),
                WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant);
            if (wildcardPattern.IsMatch(this.ParameterType.FullName))
            {
                return true;
            }
            if (this.ParameterType.IsArray && wildcardPattern.IsMatch((this.ParameterType.GetElementType().FullName)))
            {
                return true;
            }
            if (this.Attributes != null)
            {
                PSTypeNameAttribute typeNameAttribute = this.Attributes.OfType<PSTypeNameAttribute>().FirstOrDefault();
                if (typeNameAttribute != null && wildcardPattern.IsMatch(typeNameAttribute.PSTypeName))
                {
                    return true;
                }
            }
            return false;
        }
コード例 #5
0
 public PSMemberNameAndType(string name, PSTypeName typeName, object value = null)
 {
     Name       = name;
     PSTypeName = typeName;
     Value      = value;
 }