private IEnumerable <T> MapInvocation(IInvocationStatement invocation, IClass source, CodeFirstMetadata parent) { var newItems = new List <T>(); if (invocation == null) { return(newItems); } if (source == null) { return(newItems); } var name = invocation.MethodName; // English language convention used here if (name.StartsWith("Add")) { name = name.SubstringAfter("Add"); var plural = Pluralizer.Pluralize(name); var current = source; if (current != null) { var property = GetPropertyUseBase(plural, ref current); if (property != null) { var newItem = Activator.CreateInstance <T>(); newItem.Parent = parent; SetNewItemProperties(newItem, invocation); newItems.Add(newItem); } } } return(newItems); }
/// <summary> /// Gets the dataset from SQL using ADO.NET. /// </summary> /// <param name="connection">The connection.</param> /// <param name="sql">The SQL.</param> /// <param name="setName">Name of the set.</param> /// <returns></returns> private static DataSet getDataSetFromSql(string connection, string sql, string tableName) { //SqlConnection con = new SqlConnection(connection); //SqlCommand cmd = new SqlCommand(sql, con); DataSet ds = new DataSet(Pluralizer.ToPlural(tableName)); using (SqlConnection cn = new SqlConnection(connection)) { using (SqlCommand cm = new SqlCommand(sql, cn)) { SqlDataAdapter adapter = new SqlDataAdapter(cm); cn.Open(); adapter.Fill(ds, tableName); adapter.Dispose(); } } /* * try { * con.Open(); * * } finally { * con.Close(); * cmd.Dispose(); * adapter.Dispose(); * } */ return(ds); }
private FluentDefinitionOrUpdateStage FirstDefintionStage(IOrderedEnumerable <FluentModelParentRefMemberVariable> parentRefMemberVariables) { var pVariables = parentRefMemberVariables .Where(pref => !pref.ParentRefName.Equals(this.FluentMethodGroup.LocalNameInPascalCase, StringComparison.OrdinalIgnoreCase)); string ancestorWitherSuffix = Pluralizer.Singularize(FluentMethodGroup.ParentFluentMethodGroup.JavaInterfaceName); FluentDefinitionOrUpdateStage stage = new FluentDefinitionOrUpdateStage(this.resourceName, $"With{ancestorWitherSuffix}"); List <string> paramTypes = new List <string>(); List <string> declarations = new List <string>(); StringBuilder setParentRefLocalParams = new StringBuilder(); List <string> commentFor = new List <string>(); foreach (var parentRefVar in pVariables) { commentFor.Add(parentRefVar.VariableName); declarations.Add($"{parentRefVar.VariableTypeName} {parentRefVar.VariableName}"); paramTypes.Add(parentRefVar.VariableTypeName); setParentRefLocalParams.AppendLine($"{parentRefVar.VariableAccessor} = {parentRefVar.VariableName};"); } string methodName = $"withExisting{ancestorWitherSuffix}"; string methodParameterDecl = string.Join(", ", declarations); stage.Methods.Add(new FluentDefinitionOrUpdateStageMethod(methodName, methodParameterDecl, string.Join("_", paramTypes)) { CommentFor = String.Join(", ", commentFor), Body = setParentRefLocalParams.ToString() }); return(stage); }
public EntityFileProcessor(Pluralizer pluralizer) { _pluralizer = pluralizer; _entityTypeNameDictionary = new ConcurrentDictionary <string, string>(); _entityDirectory = Path.Combine(DirectoryPath, "Entities"); _contextDirectory = Path.Combine(DirectoryPath, "Context"); }
private void GameObjectViewer_Load(object sender, EventArgs e) { //mono won't be able to do this so ignore it if (Type.GetType("Mono.Runtime") == null) { PInvoke.SetWindowTheme(goTree.Handle, "explorer", null); } //plurServ = PluralizationService.CreateService(new CultureInfo("en-US")); //assuming most of the time the fields are english plurServ = new Pluralizer(new CultureInfo("en-US")); valueGrid.PropertySort = PropertySort.Categorized; if (componentInfo == null) { string baseName = baseField["m_Name"].GetValue().AsString(); TreeNode node = goTree.Nodes.Add(baseName); if (!baseField["m_IsActive"].GetValue().AsBool()) { node.ForeColor = Color.DarkRed; } node.Tag = baseField; RecursiveChildSearch(node, baseField); GetSelectedNodeData(); } else { TreeNode node = goTree.Nodes.Add("[Unknown GameObject]"); node.Tag = null; Width = 700; GetSelectedNodeData(); } }
private static IEnumerable <string> GenerateCsharpSource(string xmlContent, string @namespace = null, AccessorType accessorType = AccessorType.Public) { IPluralize pluralizer = new Pluralizer(); var result = new List <string>(); var hasNamespace = !string.IsNullOrEmpty(@namespace); var list = Parse(xmlContent, accessorType); list.Reverse(); // From child to parent foreach (var item in list) { var sb = new StringBuilder(); sb.AppendLine($"{(!hasNamespace ? Tabs(0) : Tabs(1))}{GetAccessor(accessorType)} class {item.CsharpName}"); sb.AppendLine($"{(!hasNamespace ? Tabs(0) : Tabs(1))}{{"); foreach (var mem in item.Members) { if (mem.IsList) { var plMemName = pluralizer.Pluralize(mem.CsharpName); sb.AppendLine($"{(!hasNamespace ? Tabs(1) : Tabs(2))}{GetAccessor(accessorType)} List<{mem.Type}> {plMemName} {{ get; set; }}"); } else { sb.AppendLine($"{(!hasNamespace ? Tabs(1) : Tabs(2))}{GetAccessor(accessorType)} {mem.Type} {mem.CsharpName} {{ get; set; }}"); } } sb.AppendLine($"{(!hasNamespace ? Tabs(0) : Tabs(1))}}}"); result.Add(sb.ToString()); } return(result); }
public void IsSingularShouldCheckNormalWords() { var plurally = new Pluralizer(); Assert.Equal(true, plurally.IsSingular("test")); Assert.Equal(false, plurally.IsSingular("tests")); }
public void SingularizeShouldCheckSpecialWords() { var plurally = new Pluralizer(); Assert.Equal("brother", plurally.Singularize("brothers")); Assert.Equal("brother", plurally.Singularize("brethren")); }
ContentTypeGroupResponseItem GetItem(ContentTypeGroupDescriptor contentTypeGroup) { var name = contentTypeGroup.Type.GetCustomAttribute <DisplayAttribute>()?.Name ?? contentTypeGroup.Type.Name; string pluralName; if (name.Contains(':') && !contentTypeGroup.Id.Contains(':')) { var nameSplit = name.Split(':'); name = nameSplit.First(); pluralName = nameSplit.Last(); } else { if (name.Length >= 2 && name.StartsWith('I') && char.IsUpper(name[1])) { name = name.Substring(1); } name = Humanizer.Humanize(name); pluralName = Pluralizer.Pluralize(name); } var item = new ContentTypeGroupResponseItem { Id = contentTypeGroup.Id, Name = name, LowerCaseName = name.Substring(0, 1).ToLower() + name.Substring(1), PluralName = pluralName, LowerCasePluralName = pluralName.Substring(0, 1).ToLower() + pluralName.Substring(1), ContentTypes = ContentTypeGroupMatcher.GetContentTypesFor(contentTypeGroup.Id).Select(t => t.Id).ToList().AsReadOnly(), }; return(item); }
private ODataClient GetODataClient(IAdapterTransaction transaction = null) { ODataClient client; var adapterTransaction = transaction as ODataAdapterTransaction; if (adapterTransaction != null) { client = new ODataClient(adapterTransaction.Batch); } else { client = new ODataClient(_urlBase); } var adapterPluralizer = Database.GetPluralizer(); if (adapterPluralizer != null) { var clientPluralizer = new Pluralizer(adapterPluralizer.IsPlural, adapterPluralizer.IsSingular, adapterPluralizer.Pluralize, adapterPluralizer.Singularize); ODataClient.SetPluralizer(clientPluralizer); } return(client); }
private static IRecord CreateRecord(object item, System.Collections.Generic.IList <string> aliases) { System.Collections.ICollection collection = item as System.Collections.ICollection; if (collection != null) { System.Collections.Generic.List <object> list = collection.Cast <object>().ToList <object>(); if (aliases != null && aliases.Count != list.Count) { aliases = null; } if (list.Count != 1) { int counter = 0; DictionaryRecord record = new DictionaryRecord(); list.ForEach(delegate(object obj) { record.SetValue((aliases != null) ? aliases[counter++] : ("Value" + ++counter), obj); }); return(record); } if (aliases != null) { aliases[0] = Pluralizer.ToSingular(aliases[0]); } item = list[0]; } if (aliases == null || aliases.Count != 1) { return(RecordBase.CreateRecord(item)); } return(RecordBase.CreateRecord(item, aliases[0])); }
private void AddManyToManyMirrorProperties(ClassModel c) { var pluralizer = new Pluralizer(); var properties = new List <Property>(c.Properties); foreach (var property in properties) { if (!property.IsManyToMany) { continue; } Property referenceProperty = property.Class.Properties.FirstOrDefault(p => p.Class == c); if (referenceProperty == null) { referenceProperty = new Property { Name = c.Name.Plural, BuiltInType = BuiltInType.Object, Class = c, IsCollection = true, IsManyToMany = true, IsServerOnly = true, Noun = c.Name }; property.Class.Properties.Add(referenceProperty); } referenceProperty.MirrorProperty = property; property.MirrorProperty = referenceProperty; } }
public SelectTests(Northwind northwind) { this.northwind = northwind; IPluralize pluralize = new Pluralizer(); Jaunty.TableNameMapper += type => pluralize.Pluralize(type.Name); }
private void ExtendModel(ClassModel model, JObject item) { var pluralizer = new Pluralizer(); foreach (var property in item.Properties()) { var propertyName = property.Name.Capitalize(); if (model.Properties.All(p => p.Name != propertyName)) { var prop = new Property { Name = propertyName, BuiltInType = ConvertType(property.Value.Type), IsCollection = property.Value.Type == JTokenType.Array }; if (prop.IsCollection) { prop.Noun = pluralizer.Singularize(propertyName); prop.Noun.Plural = propertyName; } if (prop.BuiltInType == BuiltInType.Object) { prop.Class = Parse(property, out bool m2m); prop.IsManyToMany = m2m; if (prop.IsCollection) { prop.IsServerOnly = true; } } model.Properties.Add(prop); } } }
public void SingularizeShouldRemoveSFromNormalWords() { var plurally = new Pluralizer(); Assert.Equal("Test", plurally.Singularize("Tests")); Assert.Equal("test", plurally.Singularize("testS")); }
private void ImportData <T>(T modelType, string rootPath) { if (db.GetCollection <T>((modelType as Type).Name).EstimatedDocumentCount() == 0) { var options = new { WriteIndented = true, }; Pluralizer pluralizer = new Pluralizer(); var fileName = pluralizer.Pluralize((modelType as Type).Name); var path = Path.Combine(rootPath, "Data", "Test", $"{fileName}.json"); if (File.Exists(path)) { var command = $" /d Beauty /c {fileName} /file {path} /mode:merge --jsonArray"; var p = Process.Start("mongoimport", command); p.StartInfo.FileName = "mongoimport.exe"; p.StartInfo.Arguments = command; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.OutputDataReceived += (sender, args) => Console.WriteLine("received output: {0}", args.Data); p.Start(); p.BeginOutputReadLine(); } } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Pluralizer p = new Pluralizer(); Console.WriteLine(p.Singularize("Yellow LEDs")); Console.WriteLine(p.Singularize("breadboard headers")); Console.WriteLine(p.Singularize("volt regulators")); HashSet <string> hs = "these are some tags" .ToLowerInvariant() .Split(' ', StringSplitOptions.RemoveEmptyEntries) .Select(tag => p.Singularize(tag.Trim())) .ToHashSet <string>(); Console.WriteLine("HS1: " + string.Join(",", hs)); HashSet <string> hs2 = "" .ToLowerInvariant() .Split(' ', StringSplitOptions.RemoveEmptyEntries) .Select(tag => p.Singularize(tag.Trim())) .ToHashSet <string>(); Console.WriteLine("HS2: " + string.Join(",", hs2)); }
public void CanPluralizeStatusLowerCase() { // Act var result = new Pluralizer().Pluralize("status"); // Assert Assert.AreEqual("statuses", result); }
private static string GetDtoPlaceholder(AppNode queryNode) { var dtoPlaceholder = GetQueryBaseName(queryNode, trimList: true); dtoPlaceholder = new Pluralizer().Singularize(dtoPlaceholder); dtoPlaceholder = $"{dtoPlaceholder}Dto"; return(dtoPlaceholder); }
public void CanPluralizePeople() { // Act var result = new Pluralizer().Pluralize("People"); // Assert Assert.AreEqual("People", result); }
public void CanPluralizeWordWithSpaceAndUpperCase() { // Act var result = new Pluralizer().Pluralize("Fun CourseStatus"); // Assert Assert.AreEqual("Fun CourseStatuses", result); }
public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance) { string typeName = instance.EntityType.Name; IPluralize pluralizer = new Pluralizer(); instance.Table(pluralizer.Pluralize(typeName)); }
public void Issue221(string word, string expectedResult) { // Act var result = new Pluralizer().Singularize(word); // Assert Assert.That(result, Is.EqualTo(expectedResult)); }
public void IsSingularShouldCheckSpecialWords() { var plurally = new Pluralizer(); Assert.Equal(true, plurally.IsSingular("Brother")); Assert.Equal(false, plurally.IsSingular("brethren")); Assert.Equal(false, plurally.IsSingular("brothers")); }
public void CanPluralizePascalCaseCompoundWords(string word, string expectedResult) { // Act var result = new Pluralizer().Pluralize(word); // Assert Assert.That(result, Is.EqualTo(expectedResult)); }
public void CanSingularizeGames() { // Act var result = new Pluralizer().Singularize("Games"); // Assert Assert.AreEqual("Game", result); }
public void CanSingularizeUninflectedWord(string word) { // Act var result = new Pluralizer().Singularize(word); // Assert Assert.That(result, Is.EqualTo(word)); }
public void CanPluralizeGame() { // Act var result = new Pluralizer().Pluralize("Game"); // Assert Assert.AreEqual("Games", result); }
public bool TryGetPluralizer(string name, out Pluralizer pluralizer) { if (_overlay.TryGetPluralizer(name, out pluralizer)) { return(true); } return(_defaults.TryGetPluralizer(name, out pluralizer)); }
public void CanSingularizeCourseStatuses() { // Act var result = new Pluralizer().Singularize("CourseStatuses"); // Assert Assert.AreEqual("CourseStatus", result); }