public string ToString(bool pretty = false) { var sb = new StringBuilder(); //sb.Add(@"<?xml version=""1.0"" encoding=""utf-8""?>", pretty); var currentDepth = -1; // start at the same indenting as the <?xml..?> decalration Action <IXmlElement> recurse = null; recurse = e => { currentDepth++; if (e is CDataElement) { sb.Add("<![CDATA[ " + e.Value + " ]]>", pretty, currentDepth--); return; } var xe = e as XmlElement; if (xe == null) { return; } if (xe.Value == null && xe.Children.Count == 0) { sb.Add("<" + xe.Name + GetAttributes(xe) + " />", pretty, currentDepth); } else { // we keep text values on the same line, so only make it pretty if we don't have a value sb.Add("<" + xe.Name + GetAttributes(xe) + ">", pretty && xe.Value == null, currentDepth); if (xe.Value != null) { sb.Add(e.Value); } else { foreach (var child in xe.Children) { recurse(child); } } sb.Add("</" + xe.Name + ">", pretty, xe.Value != null ? 0 : currentDepth); } currentDepth--; }; recurse(RootElement); return(pretty ? sb.ToString().Trim() : sb.ToString().Replace("\t", "")); }
/// <summary> /// 创建一个返回值注解 /// </summary> /// <param name="_returnStruct">返回值结构体</param> /// <returns></returns> private string CreateReturnDoc(TransClass.ReturnStruct _returnStruct) { StringBuilder _returnDoc = new StringBuilder(); _returnDoc.Add($"---@return {_returnStruct._ReturnType} {_returnStruct._ReturnDoc}"); return(_returnDoc.GetString()); }
/// <summary> /// 创建一个参数注解 /// </summary> /// <param name="_paramStruct">参数结构体</param> /// <returns></returns> private string CreateParamDoc(TransClass.ParamStruct _paramStruct) { StringBuilder _paramDoc = new StringBuilder(); _paramDoc.Add($"---@param {_paramStruct._Param} {_paramStruct._Type} {_paramStruct._Doc}"); return(_paramDoc.GetString()); }
public static FilePathResult GetJavaScriptResource(this Assembly resourceAssembly, string controllerName, string resourceName) { var cachedJavaScriptFile = string.Format("~/{0}/Resources/{1}/{2}.{3}.js", WebAppConfig.AppCacheDirectory, controllerName, resourceName, System.Threading.Thread.CurrentThread.CurrentUICulture.Name); var physicalPath = HttpContext.Current.Server.MapPath(cachedJavaScriptFile); if (!File.Exists(physicalPath)) { var requestedType = resourceAssembly.GetTypes().SingleOrDefault(x => x.FullName.EndsWith(controllerName + "." + resourceName)); if (requestedType == null) { throw new FileNotFoundException(); } var sb = new StringBuilder(); sb.Add("if (typeof Views == 'undefined')"); sb.Add(" window.Views = Views = {};"); sb.Add("if (typeof Views.{0} == 'undefined')", controllerName); sb.Add(" window.Views.{0} = Views.{0} = {{}};", controllerName); sb.Add("if (typeof Views.{0}.{1} == 'undefined')", controllerName, resourceName); sb.Add(" window.Views.{0}.{1} = Views.{0}.{1} = ", controllerName, resourceName); sb.Add(" {"); var properties = requestedType.GetProperties(); for (var i = 0; i < properties.Length; i++) { if (properties[i].CanRead) { sb.Add(" {0} : {1}{2}", properties[i].Name, properties[i].GetValue(null, null).ToEscapeString(), ((i == properties.Length - 1) ? "" : ",")); } } sb.Add(" };"); sb.Add("var {1} = Views.{0}.{1};", controllerName, resourceName); WriteFileContent(physicalPath, sb.ToString()); } else { #if DEBUG File.Delete(physicalPath); #endif } return new FilePathResult(cachedJavaScriptFile, "application/x-javascript"); }
public string ToString(bool pretty = false) { var sb = new StringBuilder(); //sb.Add(@"<?xml version=""1.0"" encoding=""utf-8""?>", pretty); var currentDepth = -1; // start at the same indenting as the <?xml..?> decalration Action<IXmlElement> recurse = null; recurse = e => { currentDepth++; if (e is CDataElement) { sb.Add("<![CDATA[ " + e.Value + " ]]>", pretty, currentDepth--); return; } var xe = e as XmlElement; if (xe == null) return; if (xe.Value == null && xe.Children.Count == 0) { sb.Add("<" + xe.Name + GetAttributes(xe) + " />", pretty, currentDepth); } else { // we keep text values on the same line, so only make it pretty if we don't have a value sb.Add("<" + xe.Name + GetAttributes(xe) + ">", pretty && xe.Value == null, currentDepth); if (xe.Value != null) sb.Add(e.Value); else foreach (var child in xe.Children) recurse(child); sb.Add("</" + xe.Name + ">", pretty, xe.Value != null ? 0 : currentDepth); } currentDepth--; }; recurse(RootElement); return pretty ? sb.ToString().Trim() : sb.ToString().Replace("\t", ""); }
private void Create(string targetControlId) { var script = new StringBuilder(); script.AppendFormat("{0} = window.{0} = popupMenu('{0}'", Id); if (MinWidth > 0) script.AppendFormat(", {0}", MinWidth); script.Add(");"); foreach (var mi in Items) { mi.PrepareScript(this, script); } script.Add(); HiggsScriptManager.InsertScript("_" + targetControlId, "_" + Id, script.ToString()); }
public override ToString() { StringBuilding formattedOpenDays = new StringBuilder(); //od is an object of type of single element in OpenDays collection foreach (OpenDay od in OpenDays) { formattedOpenDays.Add(od.ToString()); } return(formattedOpenDays.ToString()); }
/// <summary> /// 创建一个类的注解 /// </summary> /// <param name="_classStruct">类结构体</param> /// <returns></returns> private string CreateClassDoc(TransClass.ClassStruct _classStruct) { StringBuilder _classDoc = new StringBuilder(); _classDoc.Add($"{_classStruct._ParentModule} = {_classStruct._ParentModule} or {{}}"); _classDoc.NewLine($"---@class {_classStruct._Class} : {_classStruct._InheritedClass}"); _classDoc.NewLine($"local {_classStruct._Class} = {{}}"); _classDoc.NewLine($"{_classStruct._ParentModule}.{_classStruct._Class} = {_classStruct._Class}"); _classDoc.NewLine($"return {_classStruct._Class}"); int line = _classDoc.FindLine($"{_classStruct._ParentModule}.{_classStruct._Class} = {_classStruct._Class}"); _classDoc.MoveCursor(line); _classDoc.NewLine(); return(_classDoc.ToString()); }
public string Start(TransClass.ClassStruct _classStruct) { className = _classStruct._Class; StringBuilder sb = new StringBuilder(CreateClassDoc(_classStruct)); if (_classStruct._Functions != null) { foreach (var function in _classStruct._Functions) { sb.Add(CreateFunctionDoc(function)); sb.MoveCursor(sb.GetLinesCount() - 1); } } return(sb.GetString()); }
public int UniqueMorseRepresentations(string[] words) { string[] morse = new string[] { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." }; HashSet <string> rep = new HashSet <string>(); foreach (var word in words) { var builder = new StringBuilder(); foreach (var c in word) { builder.Add(morse[c - 'a']); } rep.Add(builder.ToString()); } return(rep.Count()); }
public override string ToString() { var sb = new StringBuilder(); sb.Add("<div {0} class='RibbonGroup'>", !String.IsNullOrEmpty(Id) ? "id='" + Id + "'" : string.Empty); sb.Add("<div class='content'>"); foreach(var c in Controls.Where(x => x.IsVisible)) { sb.Add(c.ToString()); } sb.Add("</div>"); sb.Add("<div class='GroupName'>{0}</div>", Title); sb.Add("</div>"); return sb.ToString(); }
/// <summary> /// 解析一个方法的注释,并把方法信息装箱到_ClassStruct /// </summary> /// <param name="docs"></param> /// <returns></returns> void AnalyticalFunction(List <Dictionary <string, string> > docs) { FunctionStruct fs = new FunctionStruct(); foreach (var item in docs) { //这是一个方法 if (item.ContainsValue(functionKey)) { string[] line = item.Keys.First().Split(spaseKey, StringSplitOptions.None); string functionName = line[1]; string functionClass = line[0].Split(new string[] { "=#" }, StringSplitOptions.None)[1].Replace("]", ""); if (functionClass == _classStruct._Class) { fs._Function = functionName; } } else if (item.ContainsValue(functionDocKey)) { fs._Doc += item.Keys.First(); } //这是一个参数 else if (item.ContainsValue(paramKey)) { string key = item.Keys.First(); if (!IsIgnoreKey(key)) { int index = key.IndexOf(" "); if (index == -1) { index = key.Length; } string[] keyData = key.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); StringBuilder sb = new StringBuilder(); for (int i = 0; i < keyData.Length - 1; i++) { sb.Add(keyData[i]).Add(" "); } string paramType = sb.GetString().Trim(' ').Trim('#'); string paramName = keyData[keyData.Length - 1].Trim(' ').Trim('#'); //key.Substring(index, key.Length - index).Trim(' '); ParamStruct ps; if (fs._Params == null) { fs._Params = new List <ParamStruct>(); } if (fs._Params.Exists(x => x._Param == paramName)) { ps = fs._Params.Find(x => x._Param == paramName); fs._Params.Remove(ps); } else { ps = new ParamStruct(); ps._Param = paramName; } ps._Type = paramType; fs._Params.Add(ps); } } //这是一个参数的注释 else if (item.ContainsValue(paramDocKey)) { string key = item.Keys.First(); int index = key.IndexOf(" "); if (index == -1) { index = key.Length; } string paramName = key.Substring(0, index).Trim(' '); string paramDoc = key.Substring(index, key.Length - index).Trim(' '); ParamStruct ps; if (fs._Params == null) { fs._Params = new List <ParamStruct>(); } if (fs._Params.Exists(x => x._Param == paramName)) { ps = fs._Params.Find(x => x._Param == paramName); fs._Params.Remove(ps); } else { ps = new ParamStruct(); ps._Param = paramName; } ps._Doc = paramDoc; fs._Params.Add(ps); } //这是一个返回值 else if (item.ContainsValue(returnKey)) { fs._Return._ReturnType = item.Keys.First().Split(new string[] { "#" }, StringSplitOptions.None)[0]; } } if (_classStruct._Functions == null) { _classStruct._Functions = new List <FunctionStruct>(); } _classStruct._Functions.Add(fs); }
public static MvcHtmlString Create(int runningScriptDelay = 0) { var sb = new StringBuilder(); if (RequiredScript != null) { foreach (var scriptPath in RequiredScript) { sb.Add("<script type=\"text/javascript\" src=\"{0}\"></script>", VirtualPathUtility.ToAbsolute(scriptPath, HttpContext.Current.Request.ApplicationPath)); } RequiredScript = new List<string>(); } if (RequiredStyleSheet != null) { foreach (var styleSheetPath in RequiredStyleSheet) { sb.Add("<link rel=\"Stylesheet\" href=\"{0}\">", VirtualPathUtility.ToAbsolute(styleSheetPath, HttpContext.Current.Request.ApplicationPath)); } RequiredStyleSheet = new List<string>(); } sb.Add(); var oldLength = sb.Length; var hasScript = false; sb.Add("<script type=\"text/javascript\">"); sb.Add("$(function()"); sb.Add("{"); if (runningScriptDelay > 0) { sb.Add("setTimeout(function()"); sb.Add("{"); } if (Script != null) { if (Script.Length > 0) { sb.Add(Script.ToString()); Script = null; hasScript = true; } } if (GroupingScripts != null && GroupingScripts.Count > 0) { foreach (var script in GroupingScripts.OrderBy(x => x.Key)) { sb.Add(script.Value.ToString()); } GroupingScripts = null; hasScript = true; } if(runningScriptDelay > 0) { sb.Add("}}, {0});", runningScriptDelay.ToString()); } sb.Add("});"); sb.Add("</script>"); if(!hasScript) { sb = sb.Remove(oldLength, sb.Length - oldLength); } SerializedType = null; return new MvcHtmlString(sb.ToString()); }
// ReSharper restore MethodOverloadWithOptionalParameter // ReSharper disable MethodOverloadWithOptionalParameter public static void AddScript(string groupName, string script, params object[] args) { if (GroupingScripts == null) GroupingScripts = new Dictionary<string, StringBuilder>(); if (GroupingScripts.ContainsKey(groupName)) { GroupingScripts[groupName].Add(script, args); } else { var sb = new StringBuilder(); sb.Add(script, args); GroupingScripts.Add(groupName, sb); } }
public string GetXaml() { //var regionalSettings = SPContext.Current.Web.CurrentUser.RegionalSettings ?? SPContext.Current.Web.RegionalSettings; //var cultureInfo = new CultureInfo((int)regionalSettings.LocaleId); var valueformatstring = PropChartShowYaxisValuesAsCurrency ? "C" : "#,0.##" + (PropChartShowYaxisValuesAsPercentage ? "%" : ""); var xaml = new StringBuilder(); xaml.Add("<vc:Chart xmlns:vc=\"clr-namespace:Visifire.Charts;assembly=SLVisifire.Charts\" BorderThickness=\"0\" Watermark=\"False\" Theme=\"Theme2\" View3D=\"{0}\" ColorSet=\"{1}\" Height=\"150\">", PropChartView3D, PropChartSelectedPaletteNameSafe); xaml.Add("<vc:Chart.Titles>"); xaml.Add("<vc:Title Text=\"{0}\"/>", HttpUtility.HtmlEncode(PropChartTitle)); xaml.Add("</vc:Chart.Titles>"); xaml.Add("<vc:Chart.Legends><vc:Legend Enabled=\"{0}\" /></vc:Chart.Legends>", ShouldShowLegend() ? "True" : "False"); xaml.Add("<vc:Chart.AxesX>"); xaml.Add("<vc:Axis Title=\"{0}\" ScrollBarScale=\"1\">", PropChartShowSeriesLabels ? HttpUtility.HtmlEncode(PropChartXaxisFieldLabel) : ""); xaml.Add("<vc:Axis.Grids><vc:ChartGrid Enabled=\"{0}\" /></vc:Axis.Grids>", PropChartShowGridlines ? "True" : "False"); xaml.Add("</vc:Axis>"); xaml.Add("</vc:Chart.AxesX>"); xaml.Add("<vc:Chart.AxesY>"); xaml.Add("<vc:Axis Title=\"{0}\" ValueFormatString=\"{1}\" >", HttpUtility.HtmlEncode(GetYAxisTitle()), valueformatstring); xaml.Add("<vc:Axis.Grids><vc:ChartGrid Enabled=\"{0}\" /></vc:Axis.Grids>", PropChartShowGridlines ? "True" : "False"); xaml.Add("</vc:Axis>"); xaml.Add("</vc:Chart.AxesY>"); xaml.Add("<vc:Chart.Series>"); foreach (VfChartSeries vfChartSeries in _series) { if (!IsBubbleChart()) { xaml.Add("<vc:DataSeries LegendText=\"{0}\" RenderAs=\"{1}\" >", HttpUtility.HtmlEncode(vfChartSeries.SeriesName), PropChartMainStyleSafe); } else { xaml.Add("<vc:DataSeries LegendText=\"{0}\" RenderAs=\"{1}\" ShowInLegend=\"false\" >", HttpUtility.HtmlEncode(vfChartSeries.SeriesName), PropChartMainStyleSafe); } xaml.Add("<vc:DataSeries.DataPoints>"); if (!IsBubbleChart()) { SortChart(vfChartSeries); } foreach (VfPoint point in vfChartSeries.GetRange(0, vfChartSeries.Count)) { if (PointShouldBeDisplayed(point)) { if (IsBubbleChart()) { if (ShouldShowLegend()) { xaml.Add("<vc:DataPoint XValue=\"{0}\" YValue=\"{1}\" ZValue=\"{2}\" ToolTipText=\"{3}\" Color=\"{4}\" ShowInLegend=\"{5}\" LegendText=\"{6}\" />", point.XAxisValue, point.YValue, point.ZValue, GetBubbleToolTipText(point), point.DataPointColorAsString, point.ShowInLegend, point.LegendText); } else { xaml.Add("<vc:DataPoint XValue=\"{0}\" YValue=\"{1}\" ZValue=\"{2}\" ToolTipText=\"{3}\" />", point.XAxisValue, point.YValue, point.ZValue, GetBubbleToolTipText(point)); } } else { xaml.Add("<vc:DataPoint AxisXLabel=\"{0}\" YValue=\"{1}\"/>", HttpUtility.HtmlEncode(point.XAxisLabel), point.YValue); } } } xaml.Add("</vc:DataSeries.DataPoints>"); xaml.Add("</vc:DataSeries>"); } xaml.Add("</vc:Chart.Series>"); xaml.Add("</vc:Chart>"); return(xaml.ToString()); }