public override string ToString() { StringBuilder builder = new StringBuilder(); string str = ""; if (this.MethodTargetType != null) { builder.Append("this: "); builder.Append(ToStringCodeMethods.Type(this.MethodTargetType, true)); str = " "; } if (this.parameterTypes != null) { builder.Append(str); builder.Append("args: "); str = ""; foreach (Type type in this.parameterTypes) { builder.Append(str); builder.Append(ToStringCodeMethods.Type(type, true)); str = ", "; } } if (builder.Length == 0) { builder.Append("<empty>"); } return(builder.ToString()); }
/// <summary> /// Returns the name of the type corresponding to the property /// </summary> /// <param name="property">PSProperty obtained in a previous DoGetProperty</param> /// <param name="forDisplay">True if the result is for display purposes only</param> /// <returns>the name of the type corresponding to the property</returns> protected override string PropertyType(PSProperty property, bool forDisplay) { PropertyData pd = property.adapterData as PropertyData; // GetDotNetType will never return null Type dotNetType = GetDotNetType(pd); string typeName; // Display Embedded object type name to // assist users in passing appropriate // object if (pd.Type == CimType.Object) { typeName = GetEmbeddedObjectTypeName(pd); if (pd.IsArray) { typeName += "[]"; } } else { typeName = forDisplay ? ToStringCodeMethods.Type(dotNetType) : dotNetType.ToString(); } return(typeName); }
public override string GetPropertyTypeName(PSAdaptedProperty adaptedProperty) { if (adaptedProperty == null) { throw new ArgumentNullException("adaptedProperty"); } CimProperty tag = adaptedProperty.Tag as CimProperty; if (tag == null) { if (!adaptedProperty.Name.Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentNullException("adaptedProperty"); } return(ToStringCodeMethods.Type(typeof(string), false)); } switch (tag.CimType) { case CimType.DateTime: case CimType.Reference: case CimType.Instance: case CimType.DateTimeArray: case CimType.ReferenceArray: case CimType.InstanceArray: return("CimInstance#" + tag.CimType.ToString()); } return(ToStringCodeMethods.Type(CimConverter.GetDotNetType(tag.CimType), false)); }
internal static string GetParameterTypeString(Type type, IEnumerable <Attribute> attributes) { PSTypeNameAttribute attribute; if ((attributes != null) && ((attribute = attributes.OfType <PSTypeNameAttribute>().FirstOrDefault <PSTypeNameAttribute>()) != null)) { string pSTypeName; Match match = Regex.Match(attribute.PSTypeName, @"(.*\.)?(?<NetTypeName>.*)#(.*[/\\])?(?<CimClassName>.*)"); if (match.Success) { pSTypeName = match.Groups["NetTypeName"].Value + "#" + match.Groups["CimClassName"].Value; } else { pSTypeName = attribute.PSTypeName; int num = pSTypeName.LastIndexOfAny(new char[] { '.' }); if ((num != -1) && ((num + 1) < pSTypeName.Length)) { pSTypeName = pSTypeName.Substring(num + 1); } } if (type.IsArray && (pSTypeName.IndexOf("[]", StringComparison.OrdinalIgnoreCase) == -1)) { for (Type type2 = type; type2.IsArray; type2 = type2.GetElementType()) { pSTypeName = pSTypeName + "[]"; } } return(pSTypeName); } Type type3 = Nullable.GetUnderlyingType(type) ?? type; return(ToStringCodeMethods.Type(type3, true)); }
/// <summary> /// Returns the name of the type corresponding to the property /// </summary> /// <param name="property">PSProperty obtained in a previous DoGetProperty</param> /// <param name="forDisplay">True if the result is for display purposes only</param> /// <returns>the name of the type corresponding to the property</returns> protected override string PropertyType(PSProperty property, bool forDisplay) { string columnName = (string)property.adapterData; DataRow dataRow = (DataRow)property.baseObject; var dataType = dataRow.Table.Columns[columnName].DataType; return(forDisplay ? ToStringCodeMethods.Type(dataType) : dataType.FullName); }
private static CompletionResult NewResult(Type type) { return(new CompletionResult( ToStringCodeMethods.Type(PSObject.AsPSObject(type)), type.Name, CompletionResultType.ParameterValue, type.FullName)); }
protected override string PropertyType(PSProperty property, bool forDisplay) { ComProperty adapterData = (ComProperty)property.adapterData; if (!forDisplay) { return(adapterData.Type.FullName); } return(ToStringCodeMethods.Type(adapterData.Type, false)); }
protected override string PropertyType(PSProperty property, bool forDisplay) { string adapterData = (string)property.adapterData; DataRowView baseObject = (DataRowView)property.baseObject; Type dataType = baseObject.Row.Table.Columns[adapterData].DataType; if (!forDisplay) { return(dataType.FullName); } return(ToStringCodeMethods.Type(dataType, false)); }
internal static string GetParameterTypeString(Type type, IEnumerable <Attribute> attributes) { string parameterTypeString; PSTypeNameAttribute typeName; if (attributes != null && (typeName = attributes.OfType <PSTypeNameAttribute>().FirstOrDefault()) != null) { // If we have a PSTypeName specified on the class, we assume it has a more useful type than the actual // parameter type. This is a reasonable assumption, the parameter binder does honor this attribute. // // This typename might be long, e.g.: // Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_Process // System.Management.ManagementObject#root\cimv2\Win32_Process // To shorten this, we will drop the namespaces, both on the .Net side and the CIM/WMI side: // CimInstance#Win32_Process // If our regex doesn't match, we'll just use the full name. var match = Regex.Match(typeName.PSTypeName, "(.*\\.)?(?<NetTypeName>.*)#(.*[/\\\\])?(?<CimClassName>.*)"); if (match.Success) { parameterTypeString = match.Groups["NetTypeName"].Value + "#" + match.Groups["CimClassName"].Value; } else { parameterTypeString = typeName.PSTypeName; // Drop the namespace from the typename, if any. var lastDotIndex = parameterTypeString.LastIndexOfAny(Utils.Separators.Dot); if (lastDotIndex != -1 && lastDotIndex + 1 < parameterTypeString.Length) { parameterTypeString = parameterTypeString.Substring(lastDotIndex + 1); } } // If the type is really an array, but the typename didn't include [], then add it. if (type.IsArray && !parameterTypeString.Contains("[]", StringComparison.Ordinal)) { var t = type; while (t.IsArray) { parameterTypeString += "[]"; t = t.GetElementType(); } } } else { Type parameterType = Nullable.GetUnderlyingType(type) ?? type; parameterTypeString = ToStringCodeMethods.Type(parameterType, true); } return(parameterTypeString); }
/// <summary> /// Returns the name of the type corresponding to the property's value /// </summary> /// <param name="property">PSProperty obtained in a previous GetMember</param> /// <param name="forDisplay">True if the result is for display purposes only</param> /// <returns>the name of the type corresponding to the member</returns> protected override string PropertyType(PSProperty property, bool forDisplay) { object value = null; try { value = BasePropertyGet(property); } catch (GetValueException) { } var type = value == null ? typeof(object) : value.GetType(); return(forDisplay ? ToStringCodeMethods.Type(type) : type.FullName); }
protected override string PropertyType(PSProperty property, bool forDisplay) { PropertyData adapterData = property.adapterData as PropertyData; Type dotNetType = GetDotNetType(adapterData); if (adapterData.Type == CimType.Object) { string embeddedObjectTypeName = GetEmbeddedObjectTypeName(adapterData); if (adapterData.IsArray) { embeddedObjectTypeName = embeddedObjectTypeName + "[]"; } return(embeddedObjectTypeName); } return(forDisplay ? ToStringCodeMethods.Type(dotNetType, false) : dotNetType.ToString()); }
internal static string CimTypeToTypeNameDisplayString(CimType cimType) { switch (cimType) { case CimType.DateTime: case CimType.Instance: case CimType.Reference: case CimType.DateTimeArray: case CimType.InstanceArray: case CimType.ReferenceArray: return("CimInstance#" + cimType.ToString()); default: return(ToStringCodeMethods.Type( CimConverter.GetDotNetType(cimType))); } }
protected override string PropertyType(PSProperty property, bool forDisplay) { object obj2 = null; try { obj2 = base.BasePropertyGet(property); } catch (GetValueException) { } Type type = (obj2 == null) ? typeof(object) : obj2.GetType(); if (!forDisplay) { return(type.FullName); } return(ToStringCodeMethods.Type(type, false)); }
/// <summary> /// /// </summary> /// <param name="adaptedProperty"></param> /// <returns></returns> public override string GetPropertyTypeName(PSAdaptedProperty adaptedProperty) { if (null == adaptedProperty) { throw new ArgumentNullException("adaptedProperty"); } CimProperty cimProperty = adaptedProperty.Tag as CimProperty; if (cimProperty != null) { return(CimTypeToTypeNameDisplayString(cimProperty.CimType)); } if (adaptedProperty.Name.Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase)) { return(ToStringCodeMethods.Type(typeof(string))); } throw new ArgumentNullException("adaptedProperty"); }
public override string ToString() { return(string.Format(CultureInfo.InvariantCulture, "PSConvertBinder [{0}] ver:{1}", new object[] { ToStringCodeMethods.Type(base.Type, true), this._version })); }
/// <summary> /// Returns the name of the type corresponding to the property /// </summary> /// <param name="property">PSProperty obtained in a previous DoGetProperty</param> /// <param name="forDisplay">True if the result is for display purposes only</param> /// <returns>the name of the type corresponding to the property</returns> protected override string PropertyType(PSProperty property, bool forDisplay) { ComProperty prop = (ComProperty)property.adapterData; return(forDisplay ? ToStringCodeMethods.Type(prop.Type) : prop.Type.FullName); }
internal string GetProxyParameterData(string prefix, string paramNameOverride, bool isProxyForCmdlet) { StringBuilder builder = new StringBuilder(); if ((this.parameterSets != null) && isProxyForCmdlet) { foreach (string str in this.parameterSets.Keys) { string proxyParameterData = this.parameterSets[str].GetProxyParameterData(); if (!string.IsNullOrEmpty(proxyParameterData) || !str.Equals("__AllParameterSets")) { string str3 = ""; builder.Append(prefix); builder.Append("[Parameter("); if (!str.Equals("__AllParameterSets")) { builder.AppendFormat(CultureInfo.InvariantCulture, "ParameterSetName='{0}'", new object[] { CommandMetadata.EscapeSingleQuotedString(str) }); str3 = ", "; } if (!string.IsNullOrEmpty(proxyParameterData)) { builder.Append(str3); builder.Append(proxyParameterData); } builder.Append(")]"); } } } if ((this.aliases != null) && (this.aliases.Count > 0)) { StringBuilder builder2 = new StringBuilder(); string str4 = ""; foreach (string str5 in this.aliases) { builder2.AppendFormat(CultureInfo.InvariantCulture, "{0}'{1}'", new object[] { str4, CommandMetadata.EscapeSingleQuotedString(str5) }); str4 = ","; } builder.AppendFormat(CultureInfo.InvariantCulture, "{0}[Alias({1})]", new object[] { prefix, builder2.ToString() }); } if ((this.attributes != null) && (this.attributes.Count > 0)) { foreach (Attribute attribute in this.attributes) { string proxyAttributeData = this.GetProxyAttributeData(attribute, prefix); if (!string.IsNullOrEmpty(proxyAttributeData)) { builder.Append(proxyAttributeData); } } } if (this.SwitchParameter) { builder.AppendFormat(CultureInfo.InvariantCulture, "{0}[{1}]", new object[] { prefix, "switch" }); } else if (this.parameterType != null) { builder.AppendFormat(CultureInfo.InvariantCulture, "{0}[{1}]", new object[] { prefix, ToStringCodeMethods.Type(this.parameterType, false) }); } builder.AppendFormat(CultureInfo.InvariantCulture, "{0}${{{1}}}", new object[] { prefix, CommandMetadata.EscapeVariableName(string.IsNullOrEmpty(paramNameOverride) ? this.name : paramNameOverride) }); return(builder.ToString()); }