public OverloadDoc(string name, string documentation, ICollection<ParameterDoc> parameters, ParameterDoc returnParameter) { ContractUtils.RequiresNotNull(name, "name"); ContractUtils.RequiresNotNullItems(parameters, "parameters"); _name = name; _params = parameters; _doc = documentation; _returnParam = returnParameter; }
public OverloadDoc(string name, string documentation, ICollection <ParameterDoc> parameters, ParameterDoc returnParameter) { ContractUtils.RequiresNotNull(name, "name"); ContractUtils.RequiresNotNullItems(parameters, "parameters"); _name = name; _params = parameters; _doc = documentation; _returnParam = returnParameter; }
public OverloadDoc(string name, string documentation, ICollection <ParameterDoc> parameters, ParameterDoc returnParameter) { ContractUtils.RequiresNotNull(name, nameof(name)); ContractUtils.RequiresNotNullItems(parameters, nameof(parameters)); Name = name; Parameters = parameters; Documentation = documentation; ReturnParameter = returnParameter; }
/// <summary> /// Creates a DLR OverloadDoc object which describes information about this overload. /// </summary> /// <param name="info">The method to document</param> /// <param name="name">The name of the method if it should override the name in the MethodBase</param> /// <param name="endParamSkip">Parameters to skip at the end - used for removing the value on a setter method</param> /// <param name="includeSelf">true to include self on instance methods</param> public static OverloadDoc GetOverloadDoc(MethodBase info, string name, int endParamSkip, bool includeSelf) { string summary = null, returns = null; List<KeyValuePair<string, string>> parameters = null; #if !SILVERLIGHT // XML doc GetXmlDoc(info, out summary, out returns, out parameters); #endif StringBuilder retType = new StringBuilder(); int returnCount = 0; MethodInfo mi = info as MethodInfo; if (mi != null) { if (mi.ReturnType != typeof(void)) { retType.Append(GetPythonTypeName(mi.ReturnType)); returnCount++; var typeAttrs = mi.ReturnParameter.GetCustomAttributes(typeof(SequenceTypeInfoAttribute), true); if (typeAttrs.Length > 0) { retType.Append(" (of "); SequenceTypeInfoAttribute typeAttr = (SequenceTypeInfoAttribute)typeAttrs[0]; for (int curTypeAttr = 0; curTypeAttr < typeAttr.Types.Count; curTypeAttr++) { if (curTypeAttr != 0) { retType.Append(", "); } retType.Append(GetPythonTypeName(typeAttr.Types[curTypeAttr])); } retType.Append(")"); } var dictTypeAttrs = mi.ReturnParameter.GetCustomAttributes(typeof(DictionaryTypeInfoAttribute), true); if (dictTypeAttrs.Length > 0) { var dictTypeAttr = (DictionaryTypeInfoAttribute)dictTypeAttrs[0]; retType.Append(String.Format(" (of {0} to {1})", GetPythonTypeName(dictTypeAttr.KeyType), GetPythonTypeName(dictTypeAttr.ValueType))); } } if (name == null) { var hashIndex = mi.Name.IndexOf('#'); if (hashIndex == -1) { name = mi.Name; } else { name = mi.Name.Substring(0, hashIndex); } } } else if(name == null) { name = "__new__"; } // For generic methods display either type parameters (for unbound methods) or // type arguments (for bound ones). if (mi != null && mi.IsGenericMethod) { Type[] typePars = mi.GetGenericArguments(); bool unbound = mi.ContainsGenericParameters; StringBuilder tmp = new StringBuilder(); tmp.Append(name); tmp.Append("["); if (typePars.Length > 1) tmp.Append("("); bool insertComma = false; foreach (Type t in typePars) { if (insertComma) tmp.Append(", "); if (unbound) tmp.Append(t.Name); else tmp.Append(GetPythonTypeName(t)); insertComma = true; } if (typePars.Length > 1) tmp.Append(")"); tmp.Append("]"); name = tmp.ToString(); } List<ParameterDoc> paramDoc = new List<ParameterDoc>(); if (mi == null) { if (name == "__new__") { // constructor, auto-insert cls paramDoc.Add(new ParameterDoc("cls", "type")); } } else if (!mi.IsStatic && includeSelf) { paramDoc.Add(new ParameterDoc("self", GetPythonTypeName(mi.DeclaringType))); } ParameterInfo[] pis = info.GetParameters(); for (int i = 0; i < pis.Length - endParamSkip; i++) { ParameterInfo pi = pis[i]; if (i == 0 && pi.ParameterType == typeof(CodeContext)) { // hide CodeContext parameters continue; } if ((pi.Attributes & ParameterAttributes.Out) == ParameterAttributes.Out || pi.ParameterType.IsByRef) { if (returnCount == 1) { retType.Insert(0, "("); } if (returnCount != 0) retType.Append(", "); returnCount++; retType.Append(GetPythonTypeName(pi.ParameterType)); if ((pi.Attributes & ParameterAttributes.Out) == ParameterAttributes.Out) continue; } ParameterFlags flags = ParameterFlags.None; if (pi.IsDefined(typeof(ParamArrayAttribute), false)) { flags |= ParameterFlags.ParamsArray; } else if (pi.IsDefined(typeof(ParamDictionaryAttribute), false)) { flags |= ParameterFlags.ParamsDict; } string paramDocString = null; if (parameters != null) { foreach (var paramXmlDoc in parameters) { if (paramXmlDoc.Key == pi.Name) { paramDocString = paramXmlDoc.Value; break; } } } paramDoc.Add( new ParameterDoc( pi.Name ?? "", // manufactured methods, such as string[].ctor(int) can have no parameter names. GetPythonTypeName(pi.ParameterType), paramDocString, flags ) ); } if (returnCount > 1) { retType.Append(')'); } ParameterDoc retDoc = new ParameterDoc(String.Empty, retType.ToString(), returns); return new OverloadDoc( name, summary, paramDoc, retDoc ); }
private static ICollection<ParameterDoc> GetParameterDocs(PythonFunction pf) { ParameterDoc[] res = new ParameterDoc[pf.ArgNames.Length]; for (int i = 0; i < res.Length; i++) { ParameterFlags flags = ParameterFlags.None; if (i == pf.ExpandDictPosition) { flags |= ParameterFlags.ParamsDict; } else if (i == pf.ExpandListPosition) { flags |= ParameterFlags.ParamsArray; } res[i] = new ParameterDoc( pf.ArgNames[i], flags ); } return res; }