public static string GetDefaultModuleName(Type[] selected, string solutionName) { StringDistance sd = new StringDistance(); string name = null; foreach (var item in selected) { if (name == null) { name = item.FullName.RemovePrefix(solutionName + ".Entities"); } else { int startName, rubbish; int length = sd.LongestCommonSubstring(name, item.FullName, out startName, out rubbish); name = name.Substring(startName, length); if (name.IsEmpty()) { return(null); } } } return(name.Trim('.')); }
public static string?GetDefaultModuleName(Type[] selected, string solutionName) { StringDistance sd = new StringDistance(); string?name = null; foreach (var item in selected) { if (name == null) { name = item.FullName !.RemovePrefix(solutionName + ".Entities"); } else { int length = sd.LongestCommonSubstring(name, item.FullName !, out int startName, out int rubbish); name = name.Substring(startName, length); if (name.IsEmpty()) { return(null); } } } if (name == null) { return(null); } if (name.Contains(".")) { return(name.Before(".").DefaultToNull() ?? name.After(".")); } return(name); }
public void LongestCommonSubstring() { Assert.Equal(3, d.LongestCommonSubstring("hallo", "halo")); Assert.Equal(4, d.LongestCommonSubstring("SupeMan", "SuperMan")); Assert.Equal(0, d.LongestCommonSubstring("aoa", "")); }
public void LongestCommonSubstring() { Assert.True(3 == _stringDistance.LongestCommonSubstring("hallo", "halo")); Assert.True(4 == _stringDistance.LongestCommonSubstring("SupeMan", "SuperMan")); Assert.True(0 == _stringDistance.LongestCommonSubstring("aoa", string.Empty)); }