public static string HbmFileName(string someName) { if (string.IsNullOrWhiteSpace(someName)) { return(null); } someName = NfString.CapWords(someName, '.'); return($"{someName}.hbm.xml"); }
public static string ManyToOnePropertyName(string fullAssemblyQualTypeName, string[] fkColumnNames) { var fkPropertyType = new NfTypeName(fullAssemblyQualTypeName); var fkPropertyName = fkPropertyType.ClassName; fkColumnNames = fkColumnNames.Select(x => NfString.CapWords(NfString.ExtractLastWholeWord(x, '.'), null)).ToArray(); return(string.Format("{0}By{1}", fkPropertyName, string.Join("And", fkColumnNames))); }
public string GetDotNetPropertyName() { if (string.IsNullOrWhiteSpace(ParamName)) { return(null); } var cName = ParamName.StartsWith("@") ? ParamName.Substring(1, ParamName.Length - 1) : ParamName; cName = NfString.SafeDotNetIdentifier(cName); cName = NfString.CapWords(cName, null); if (GetSqlDataType() == SqlDbType.Bit && !cName.StartsWith("Is")) { cName = string.Format("Is{0}", cName); } if (cName.EndsWith("ID")) { cName = string.Format("{0}Id", cName.Substring(0, cName.Length - 2)); } return(cName); }
public static string ClassName(string name, string outputNamespace) { var asmQualifiedName = new StringBuilder(); if (name.Split(Shared.Core.NfSettings.DefaultTypeSeparator).Length > 1) { var nameParts = name.Split(Shared.Core.NfSettings.DefaultTypeSeparator); var actualClassName = nameParts[(nameParts.Length - 1)].Replace(" ", Globals.REPLACE_SPACE_WITH_SEQUENCE); nameParts[(nameParts.Length - 1)] = NfString.SafeDotNetTypeName(actualClassName); name = string.Join(Shared.Core.NfSettings.DefaultTypeSeparator.ToString(CultureInfo.InvariantCulture), nameParts); } //remove any chars not allowed in C# ids name = NfString.SafeDotNetTypeName(name); //capitalize first letter of whole word to avoid conflict with C# reserved words name = NfString.CapWords(name, Shared.Core.NfSettings.DefaultTypeSeparator); if (!String.IsNullOrWhiteSpace(outputNamespace)) { outputNamespace = NfString.CapWords(outputNamespace, Shared.Core.NfSettings.DefaultTypeSeparator); asmQualifiedName.AppendFormat("{0}{1}", outputNamespace, Shared.Core.NfSettings.DefaultTypeSeparator); } asmQualifiedName.Append(name); if (!String.IsNullOrWhiteSpace(outputNamespace)) { asmQualifiedName.AppendFormat(", {0}", NfReflect.DraftCscExeAsmName(outputNamespace)); } var typeName = new NfTypeName(asmQualifiedName.ToString()); if (!String.IsNullOrWhiteSpace(outputNamespace)) { return(typeName.AssemblyQualifiedName); } return(typeName.FullName); }
public static string PropertyName(string name, bool replaceInvalidsWithHexEsc = false) { name = NfString.ExtractLastWholeWord(name, Shared.Core.NfSettings.DefaultTypeSeparator); name = NfString.CapWords(name, null); return(NfString.SafeDotNetIdentifier(name, replaceInvalidsWithHexEsc)); }
/// <summary> /// Deals with various city name oddities /// (e.g. New York -> New York City; Winston Salem -> Winston-Salem) /// </summary> /// <param name="name"></param> /// <returns></returns> public static string FinesseCityName(string name) { name = name ?? ""; var workingName = name; var isHyphen = name.Contains("-"); //take hyphens out if (isHyphen) { workingName = workingName.Replace("-", " "); } workingName = NfString.CapWords(workingName.ToLower(), ' '); if (workingName == "New York") { return("New York City"); } if (workingName == "Winston Salem") { return("Winston-Salem"); } var isMcSomething = workingName.Split(' ').Any(p => p.ToLower().StartsWith("mc")) || name.ToLower().StartsWith("mc"); if (isMcSomething) { var bldr = new StringBuilder(); var flags = new[] { false, false }; foreach (var t in workingName.ToCharArray()) { if (t == 'M') { flags[0] = true; flags[1] = false; } if (flags[0] && t == 'c') { flags[1] = true; bldr.Append(t); continue; } if (flags.All(x => x)) { if (t == ' ') { continue; } bldr.Append(Char.ToUpper(t)); flags[0] = false; flags[1] = false; continue; } bldr.Append(t); } workingName = bldr.ToString(); } //put hyphens back if (isHyphen) { workingName = workingName.Replace(" ", "-"); } return(workingName); }
public static XElement HibernateConfigurationNode(string connectionString, string outputNamespace) { outputNamespace = NfString.CapWords(outputNamespace, Shared.Core.NfSettings.DefaultTypeSeparator); XNamespace hbmXmlNs = Globals.HBM_XML_NS; var hbmConfigNode = new XElement(hbmXmlNs + Nm.HIBERNATE_CONFIGURATION); var sessionFactoryNode = new XElement(Nm.SESSION_FACTORY); var propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.ConnectionProvider)) { Value = "NHibernate.Connection.DriverConnectionProvider" }; sessionFactoryNode.Add(propertyNode); propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.ConnectionDriver)) { Value = "NHibernate.Driver.SqlClientDriver" }; sessionFactoryNode.Add(propertyNode); propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.Dialect)) { Value = "NHibernate.Dialect.MsSql2008Dialect" }; sessionFactoryNode.Add(propertyNode); propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.ConnectionString)) { Value = connectionString }; sessionFactoryNode.Add(propertyNode); propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.Isolation)) { Value = "ReadCommitted" }; sessionFactoryNode.Add(propertyNode); propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.CommandTimeout)) { Value = "30" }; sessionFactoryNode.Add(propertyNode); propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.MaxFetchDepth)) { Value = "3" }; sessionFactoryNode.Add(propertyNode); var mappingNode = new XElement(Nm.MAPPING, new XAttribute(Nm.ASSEMBLY, NfReflect.DraftCscExeAsmName(outputNamespace))); sessionFactoryNode.Add(mappingNode); hbmConfigNode.Add(sessionFactoryNode); return(hbmConfigNode); }