static string CSText(this CodeFunction codeFunction, CSTextPart cstp) { const string sEnter = @"CodeSite.EnterMethod({0}""{1}{2}""); try {{ "; const string sExit = @"}} finally {{ CodeSite.ExitMethod({0}""{1}{2}""); }} "; const string sCatch = @"}} catch (Exception ex) when (ex.SendCodeSite()) {{ throw; "; string sClass = string.Empty; if (codeFunction.IsShared) { CodeElement ce = codeFunction.Parent as CodeElement; if (ce.Kind == vsCMElement.vsCMElementClass || ce.Kind == vsCMElement.vsCMElementStruct) { sClass = string.Format(@"""{0}."" + ", ce.Name); } } else { sClass = "this, "; } var sProperty = codeFunction.GetSetName(); if (sProperty != null) { sProperty = "/" + sProperty; } switch (cstp) { case CSTextPart.Enter: return(string.Format(sEnter, sClass, codeFunction.Name, sProperty)); case CSTextPart.Catch: return(string.Format(sCatch)); case CSTextPart.Exit: return(string.Format(sExit, sClass, codeFunction.Name, sProperty)); default: return(string.Empty); } }
public CodeElementViewModel(CodeElement codeElement) { CodeElement = codeElement; Name = Guid.NewGuid().ToString(); if (CodeElement == null) { return; } Name = CodeElement.Name; if (CodeElement.Kind == vsCMElement.vsCMElementProperty && CodeElement is CodeProperty codeProperty) { if (codeProperty.Getter != null) { LoadChild((CodeElement)codeProperty.Getter); } if (codeProperty.Setter != null) { LoadChild((CodeElement)codeProperty.Setter); } } else if (CodeElement.Children != null) { LoadChildren(CodeElement.Children); } if (IsCodeFunction) { if (CodeFunction.MustImplement || !(CodeFunction.HasBody() || CodeFunction.HasExpressionBody())) { CodeElement = null; return;//跳过抽象方法和没有主体的方法 } Name = CodeFunction.GetSetName() ?? Name; ExistsCodeSite = CodeFunction.ExistsCodeSite(); //IsChecked = ExistsCodeSite; } }