private static string CreatePrivateMember(string name, string type, string defaultvalue, string publicaccessmodifiers) { if (string.IsNullOrEmpty(defaultvalue)) { return(CreatePrivateMember(name, type)); } if (StringUtility.OneOfNullOrEmpty(name, type)) { return(string.Empty); } string template = Template.Resources.CodeSnippetResources.PrivateMember; if (StringUtility.Contains(publicaccessmodifiers, ContainsMode.AtLeastOneOf, StringComparison.Ordinal, "static", "stat", "sta")) { template = Template.Resources.CodeSnippetResources.PrivateStaticMember; } name = name.Trim(); type = type.Trim(); string nameU = StringUtility.SetCase(name, CaseMode.FirstLetterToUpper); string nameL = StringUtility.SetCase(name, CaseMode.FirstLetterToLower); return(string.Format(template, type, nameL, nameU, defaultvalue)); }
/// <summary> /// Returns a value indicating whether the specified <paramref name="values"/> occurs within the <paramref name="source"/> object. /// </summary> /// <param name="source">The <see cref="String"/> to seek.</param> /// <param name="comparison">One of the enumeration values that specifies the rules to use in the comparison.</param> /// <param name="values">The <see cref="char"/> sequence to search within <paramref name="source"/>.</param> /// <returns> /// <c>true</c> if the <paramref name="values"/> parameter occurs within the <paramref name="source"/>, or if value is the empty string (""); otherwise, <c>false</c>. /// </returns> public static bool ContainsAny(this string source, StringComparison comparison, params char[] values) { return(StringUtility.Contains(source, comparison, values)); }
/// <summary> /// Returns a value indicating whether any of the specified <paramref name="values"/> occurs within the <paramref name="source"/>. /// </summary> /// <param name="source">The <see cref="String"/> to seek.</param> /// <param name="values">The <see cref="String"/> sequence to search within <paramref name="source"/>.</param> /// <returns> /// <c>true</c> if any of the <paramref name="values"/> occurs within the <paramref name="source"/>, or if value is the empty string (""); otherwise, <c>false</c>. /// </returns> /// <remarks>This method performs an ordinal (case-insensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.</remarks> public static bool ContainsAny(this string source, params string[] values) { return(StringUtility.Contains(source, values)); }
/// <summary> /// Returns a value indicating whether the specified <paramref name="value"/> occurs within the <paramref name="source"/>. /// </summary> /// <param name="source">The <see cref="String"/> to seek.</param> /// <param name="value">The <see cref="char"/> to search within <paramref name="source"/>.</param> /// <returns> /// <c>true</c> if the <paramref name="value"/> parameter occurs within the <paramref name="source"/>, or if value is the empty string (""); otherwise, <c>false</c>. /// </returns> /// <remarks>This method performs an ordinal (case-insensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.</remarks> public static bool ContainsAny(this string source, char value) { return(StringUtility.Contains(source, value)); }
/// <summary> /// Returns a value indicating whether the specified <paramref name="value"/> occurs within the <paramref name="source"/>. /// </summary> /// <param name="source">The <see cref="String"/> to seek.</param> /// <param name="value">The <see cref="String"/> to search within <paramref name="source"/>.</param> /// <param name="comparison">One of the enumeration values that specifies the rules to use in the comparison.</param> /// <returns> /// <c>true</c> if the <paramref name="value"/> parameter occurs within the <paramref name="source"/>, or if value is the empty string (""); otherwise, <c>false</c>. /// </returns> public static bool ContainsAny(this string source, string value, StringComparison comparison) { return(StringUtility.Contains(source, comparison, value)); }
/// <summary> /// ClassName:InheretedClassName,Interfaces /// PropertyType;PropertyName;DefaultValue;AccessModifiers|Options /// PropertyType;PropertyName; /// PropertyType;PropertyName;DefaultValue; /// PropertyType;PropertyName;DefaultValue;AccessModifiers; /// PropertyType;PropertyName|Options /// /// Options: /// constructor con, tostring, serializable ser, region reg, publiconly pub, method met, getteronly get /// /// person /// string;name|serializable ser constructor con region reg tostring getteronly /// </summary> /// <param name="propertydefinitions"></param> /// <returns></returns> public static string CreateClass(string propertydefinitions) { if (string.IsNullOrEmpty(propertydefinitions)) { return(string.Empty); } StringBuilder sbClassDeclaration = new StringBuilder(); StringBuilder sbPrivate = new StringBuilder(); StringBuilder sbPublic = new StringBuilder(); StringBuilder sbParams = new StringBuilder(); StringBuilder sbParamAssigns = new StringBuilder(); StringBuilder sbUsing = new StringBuilder(); StringBuilder sbEventDelegates = new StringBuilder(); StringBuilder sbEventDeclarations = new StringBuilder(); StringBuilder sbEventArgumentClasses = new StringBuilder(); StringBuilder sbEventRaises = new StringBuilder(); sbUsing.AppendFormat(Template.Resources.CodeSnippetResources.UsingLine, "System"); List <string> toStringList = new List <string>(); string[] items = new string[0]; string[] lines = StringUtility.Lines(propertydefinitions); lines = StringArrayUtility.RemoveEmpties(lines); if (lines.Length <= 1) { return(string.Empty); } bool usingadded = false; for (int ii = 1; ii < lines.Length; ii++) { string line = lines[ii]; items = StringUtility.SplitEscaped(line, '|', '"'); string options = StringArrayUtility.ArrayValue(items, 1); items = StringUtility.SplitEscaped(items[0], ';', '"'); string type = StringArrayUtility.ArrayValue(items, 0).Trim(); string name = StringUtility.CamelCaseUpper(StringArrayUtility.ArrayValue(items, 1).Trim()); string defaultvalue = StringArrayUtility.ArrayValue(items, 2); string accessmodifiers = StringArrayUtility.ArrayValue(items, 3); string comment = StringArrayUtility.ArrayValue(items, 4); bool publiconly = StringUtility.Contains(options, ContainsMode.AtLeastOneOf, StringComparison.OrdinalIgnoreCase, "publiconly", "pub"); if (type.Equals("event")) { // public delegate void BrowserFileClickEventHandler(object sender, BrowserClickEventArgs ce); sbEventDelegates.Append(CreateEventDelegate(name, items)); sbEventDeclarations.Append(CreateEventDeclaration(name, items)); if (HasEventArgumentParams(items)) { sbEventArgumentClasses.Append(CreateEventArgumentClass(name, items)); } sbEventRaises.Append(CreateRaiseEvent(name, items)); } if (!type.Equals("event")) { // Constructor if (StringUtility.Contains(options, ContainsMode.AtLeastOneOf, StringComparison.OrdinalIgnoreCase, "constructor", "con")) { sbParams.Append(type); sbParams.Append(StringUtility._SPACE); sbParams.Append("p"); sbParams.Append(StringUtility.CamelCaseUpper(name)); sbParams.Append(","); if (publiconly == false) { sbParamAssigns.Append(StringUtility.CamelCaseLower(name)); } else { sbParamAssigns.Append(StringUtility.CamelCaseUpper(name)); } sbParamAssigns.Append(" = "); sbParamAssigns.Append("p"); sbParamAssigns.Append(StringUtility.CamelCaseUpper(name)); sbParamAssigns.Append(";"); sbParamAssigns.Append(StringUtility._CRLF); } if (StringUtility.Contains(options, ContainsMode.All, StringComparison.OrdinalIgnoreCase, "tostring")) { if (publiconly == false) { toStringList.Add(StringUtility.CamelCaseLower(name)); } else { toStringList.Add(StringUtility.CamelCaseUpper(name)); } } if (StringUtility.Contains(options, ContainsMode.AtLeastOneOf, StringComparison.OrdinalIgnoreCase, "serializable", "ser")) { if (usingadded == false) { sbUsing.AppendFormat(Template.Resources.CodeSnippetResources.UsingLine, "System.Xml.Serialization"); usingadded = true; } } if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(type)) { if (publiconly == false) { sbPrivate.Append(CreatePrivateMember(name, type, defaultvalue, accessmodifiers)); sbPrivate.Append(StringUtility._CRLF); } sbPublic.Append(CreateProperty(name, type, accessmodifiers, comment, StringUtility.Contains(options, ContainsMode.AtLeastOneOf, StringComparison.OrdinalIgnoreCase, "region", "reg"), StringUtility.Contains(options, ContainsMode.AtLeastOneOf, StringComparison.OrdinalIgnoreCase, "serializable", "ser"), StringUtility.Contains(options, ContainsMode.AtLeastOneOf, StringComparison.OrdinalIgnoreCase, "getteronly", "get"), StringUtility.Contains(options, ContainsMode.AtLeastOneOf, StringComparison.OrdinalIgnoreCase, "method", "met"), publiconly )); sbPublic.Append(StringUtility._CRLF); sbPublic.Append(StringUtility._CRLF); } } } items = lines[0].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); string classname = items[0].Trim(); string inheretedClassName = string.Empty; string parameters = sbParams.ToString(); parameters = StringUtility.TrimEndByLength(parameters, 1); string constructor = string.Empty; if (!string.IsNullOrEmpty(parameters)) { constructor = string.Format(Template.Resources.CodeSnippetResources.Constructor, classname, parameters, StringUtility.TabIndent(StringUtility.TrimEndByLength(sbParamAssigns.ToString(), 2), 3), StringUtility._TAB); } sbClassDeclaration.Append(classname); if (items.Length > 1) { items = items[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); inheretedClassName = items[0]; sbClassDeclaration.Append(" : "); sbClassDeclaration.Append(inheretedClassName); for (int ii = 1; ii < items.Length; ii++) { sbClassDeclaration.Append(" , "); sbClassDeclaration.Append(items[ii]); } } string toString = Template.Resources.CodeSnippetResources.DefaultToString; if (toStringList.Count > 0) { StringBuilder sbToString = new StringBuilder(); sbToString.Append("return string.Format(\""); for (int ii = 0; ii < toStringList.Count; ii++) { sbToString.Append("{"); sbToString.Append(ii.ToString()); sbToString.Append("}"); } sbToString.Append("\""); sbToString.Append(","); for (int ii = 0; ii < toStringList.Count; ii++) { sbToString.Append(toStringList[ii]); if (ii < toStringList.Count - 1) { sbToString.Append(","); } } sbToString.Append(");"); toString = sbToString.ToString(); } string pri = sbPrivate.ToString(); string pub = sbPublic.ToString(); string result = string.Format(Template.Resources.CodeSnippetResources.Class, sbClassDeclaration.ToString(), // 0 StringUtility.TabIndent(pri, 2), // 1 StringUtility.TabIndent(pub, 2), // 2 classname, // 3 StringUtility._TAB, // 4 constructor, // 5 toString, // 6 sbUsing.ToString(), //7 StringUtility.TabIndent(sbEventDelegates.ToString(), 1), // 8 StringUtility.TabIndent(sbEventDeclarations.ToString(), 2), // 9 StringUtility.TabIndent(sbEventArgumentClasses.ToString(), 1), // 10 StringUtility.TabIndent(sbEventRaises.ToString(), 2) // 11 ); return(StringUtility.RemoveDuplicateEmptyLines(result, true)); }
public void StringUtility_Contains_1() { Assert.IsTrue(StringUtility.Contains("Again", 'a')); Assert.IsFalse(StringUtility.Contains(string.Empty, 'a')); Assert.IsFalse(StringUtility.Contains("Other", 'a')); }