public string GetMethodCall(CodeFunction codeFunction) { string result = codeFunction.get_Prototype(Convert.ToInt32(vsCMPrototype.vsCMPrototypeParamNames)); result = result.Replace("ByVal ", string.Empty); result = result.Replace("ByRef ", string.Empty); result = result.Replace(" )", ")"); return result; }
/// <summary> /// Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>. /// </summary> /// <returns> /// A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>. /// </returns> public override string ToString() { return (String.Format("[function] {0}", _codeElement.get_Prototype( (int) (vsCMPrototype.vsCMPrototypeType | vsCMPrototype.vsCMPrototypeParamNames | vsCMPrototype.vsCMPrototypeFullname | vsCMPrototype.vsCMPrototypeParamTypes)))); }
public string GetMethodCall(CodeFunction codeFunction) { string result = codeFunction.get_Prototype(Convert.ToInt32(vsCMPrototype.vsCMPrototypeParamNames)); result = result.Replace("ByVal ", string.Empty); result = result.Replace("ByRef ", string.Empty); result = result.Replace(" )", ")"); return(result); }
/// <summary> /// Returns an identifier to use for a unique CodeElement. /// </summary> /// <param name="element">The CodeElement to ID.</param> /// <returns>A string that identifies the element.</returns> /// <remarks> /// Each language has limitations when creating a 'unique' identifier. /// If the language is VB, a method identifier may not actually /// remain unique, because VB creates the identifier based on the original /// method signature and never updates it if the signature changes. /// For example, if a method is copied and pasted to create a similar method, the new /// method initially has the same signature as the old one and thus VB's ElementID /// will return the same identifier for the clone as it returned for the copied method. /// If the language is C#, the code element throws and exception when accessing the /// ElementID, so the function prototype is used here to generate an ID instead. /// </remarks> public static string GetUniqueElementId(CodeElement element) { string strElementID = null; if (element == null) { throw new ArgumentNullException("element"); } try { // VB will return an ElementID for the element. if (element.Language == CodeModelLanguageConstants.vsCMLanguageVB) { CodeElement2 codeElement2 = element as CodeElement2; if (codeElement2 != null) { strElementID = codeElement2.ElementID; } } // For non-VB languages, construct an ID from the best available signature. if (strElementID == null) { switch (element.Kind) { case vsCMElement.vsCMElementFunction: CodeFunction codeFunction = ((CodeFunction)element); strElementID = codeFunction.get_Prototype((int)vsCMPrototype.vsCMPrototypeParamTypes); break; default: strElementID = element.FullName; break; } } } catch (Exception) { strElementID = element.Name; } return(strElementID); }
/// <summary> /// Returns a CodeElement's documentation comment if it has /// one, otherwise returns relevant information from the prototype. /// </summary> /// <param name="element">A CodeElement object.</param> /// <returns>A string representing the element's definition.</returns> public static string GetPrototypeFromCMElement(CodeElement element) { System.Xml.XmlDocument docComment = new System.Xml.XmlDocument(); try { if (element == null) { throw new ArgumentNullException("element"); } switch (element.Kind) { case vsCMElement.vsCMElementFunction: CodeFunction codeFunction = ((CodeFunction)element); if (!string.IsNullOrEmpty(codeFunction.DocComment)) { docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeFunction.DocComment)); System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary"); if (node != null) { return(String.Format("{0}\n{1}", node.InnerText.Trim(), codeFunction.get_Prototype( (int)vsCMPrototype.vsCMPrototypeType | (int)vsCMPrototype.vsCMPrototypeParamNames | (int)vsCMPrototype.vsCMPrototypeParamTypes))); } else { return(string.Empty); } } else { return(codeFunction.get_Prototype((int)vsCMPrototype.vsCMPrototypeType | (int)vsCMPrototype.vsCMPrototypeParamNames | (int)vsCMPrototype.vsCMPrototypeParamTypes)); } case vsCMElement.vsCMElementProperty: CodeProperty codeProperty = ((CodeProperty)element); if (!string.IsNullOrEmpty(codeProperty.DocComment)) { docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeProperty.DocComment)); System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary"); if (node != null) { return(String.Format("{0}\n{1}", node.InnerText.Trim(), codeProperty.get_Prototype((int)vsCMPrototype.vsCMPrototypeType | (int)vsCMPrototype.vsCMPrototypeParamNames | (int)vsCMPrototype.vsCMPrototypeParamTypes))); } else { return(string.Empty); } } else { return(codeProperty.get_Prototype((int)vsCMPrototype.vsCMPrototypeType | (int)vsCMPrototype.vsCMPrototypeParamNames | (int)vsCMPrototype.vsCMPrototypeParamTypes)); } case vsCMElement.vsCMElementVariable: CodeVariable codeVariable = ((CodeVariable)element); return(codeVariable.get_Prototype((int)vsCMPrototype.vsCMPrototypeType)); case vsCMElement.vsCMElementEvent: CodeEvent codeEvent = ((CodeEvent)element); if (!string.IsNullOrEmpty(codeEvent.DocComment)) { docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeEvent.DocComment)); System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary"); if (node != null) { return(String.Format("{0}\n{1}", node.InnerText.Trim(), codeEvent.get_Prototype((int)vsCMPrototype.vsCMPrototypeType | (int)vsCMPrototype.vsCMPrototypeParamNames | (int)vsCMPrototype.vsCMPrototypeParamTypes))); } else { return(string.Empty); } } else { return(codeEvent.get_Prototype((int)vsCMPrototype.vsCMPrototypeType | (int)vsCMPrototype.vsCMPrototypeParamNames | (int)vsCMPrototype.vsCMPrototypeParamTypes)); } case vsCMElement.vsCMElementDelegate: CodeDelegate codeDelegate = ((CodeDelegate)element); if (!string.IsNullOrEmpty(codeDelegate.DocComment)) { docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeDelegate.DocComment)); System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary"); if (node != null) { return(String.Format("{0}\n{1}", node.InnerText.Trim(), codeDelegate.get_Prototype((int)vsCMPrototype.vsCMPrototypeType | (int)vsCMPrototype.vsCMPrototypeParamNames | (int)vsCMPrototype.vsCMPrototypeParamTypes))); } else { return(string.Empty); } } else { return(codeDelegate.get_Prototype((int)vsCMPrototype.vsCMPrototypeType | (int)vsCMPrototype.vsCMPrototypeParamNames | (int)vsCMPrototype.vsCMPrototypeParamTypes)); } case vsCMElement.vsCMElementClass: CodeClass codeClass = ((CodeClass)element); if (!string.IsNullOrEmpty(codeClass.DocComment)) { docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeClass.DocComment)); System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary"); if (node != null) { return(node.InnerText.Trim()); } else { return(string.Empty); } } else { return(string.Empty); } //nemerle variant type and variant options case vsCMElement.vsCMElementUnion: CodeClass codeVariant = ((CodeClass)element); if (!string.IsNullOrEmpty(codeVariant.DocComment)) { docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeVariant.DocComment)); System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary"); if (node != null) { return(node.InnerText.Trim()); } else { return(string.Empty); } } else { return(string.Empty); } case vsCMElement.vsCMElementStruct: CodeStruct codeStruct = ((CodeStruct)element); if (!string.IsNullOrEmpty(codeStruct.DocComment)) { docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeStruct.DocComment)); System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary"); if (node != null) { return(node.InnerText.Trim()); } else { return(string.Empty); } } else { return(string.Empty); } case vsCMElement.vsCMElementInterface: CodeInterface codeInterface = ((CodeInterface)element); if (!string.IsNullOrEmpty(codeInterface.DocComment)) { docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeInterface.DocComment)); System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary"); if (node != null) { return(node.InnerText.Trim()); } else { return(string.Empty); } } else { return(string.Empty); } default: return(string.Empty); } } catch { return(string.Empty); } }
/// <summary> /// Returns a CodeElement's display name for use in TreeViews. /// </summary> /// <param name="element">The CodeElement whose display name is needed.</param> /// <returns>The element's display string.</returns> /// <remarks> /// For methods, this is the function prototype; /// for other elements, it is simply the Name. /// </remarks> public static string GetDisplayNameFromCMElement(CodeElement element) { string strName = null; if (element == null) { throw new ArgumentNullException("element"); } try { if (CodeModelHelpers.IsGeneric(element, out strName)) { Debug.Assert(strName != null); } else { switch (element.Kind) { case vsCMElement.vsCMElementFunction: CodeFunction codeFunction = ((CodeFunction)element); if (element is CodeDomCodeFunction) { strName = codeFunction.get_Prototype((int)vsCMPrototype.vsCMPrototypeParamTypes | (int)vsCMPrototype.vsCMPrototypeType); } else { strName = codeFunction.get_Prototype((int)vsCMPrototype.vsCMPrototypeParamTypes); } break; case vsCMElement.vsCMElementVariable: CodeDomCodeVariable codeTypeVariable = element as CodeDomCodeVariable; if (codeTypeVariable != null) { strName = codeTypeVariable.get_Prototype((int)(int)vsCMPrototype.vsCMPrototypeType); } else { strName = element.Name; } break; case vsCMElement.vsCMElementProperty: CodeDomCodeProperty codeTypeProperty = element as CodeDomCodeProperty; if (codeTypeProperty != null) { strName = codeTypeProperty.get_Prototype((int)(int)vsCMPrototype.vsCMPrototypeType); } else { strName = element.Name; } break; default: strName = element.Name; break; } } } catch { strName = element.Name; } return(strName); }