public void Format( ) { TokenDictionary tokenDictionary = new TokenDictionary( ); string name, @namespace; if (GuerillaCs.SplitNamespaceFromFieldName(Value.Name, out name, out @namespace)) { this.Value.Name = tokenDictionary.GenerateValidToken(GuerillaCs.ToTypeName(name)); this.Namespace = GuerillaCs.ToTypeName(@namespace); } else { this.Value.Name = tokenDictionary.GenerateValidToken(GuerillaCs.ToTypeName(this.Value.Name)); } FormatFieldNames(tokenDictionary); foreach (var item in EnumDefinitions) { item.Format( ); } foreach (var item in ClassDefinitions) { item.Format( ); } }
protected string GenerateName(MemberAttributes attributes, TokenDictionary tokenDictionary, bool takeFirstMatch, params string[] nameStrings) { tokenDictionary = tokenDictionary ?? TokenDictionary; string validToken = null; foreach (var nameString in nameStrings) { var token = ConvertCaseFormating(attributes, nameString).ToAlphaNumericToken(); if (string.IsNullOrWhiteSpace(token)) { continue; } // this token is unused and not null or whitespace so return it if (!tokenDictionary.Contains(token)) { return(tokenDictionary.GenerateValidToken(token)); } // this token is a potential match but has a naming conflict // we only want the first potential match so once we assign to // validToken we never do it again if (validToken == null && tokenDictionary.Contains(token)) { if (takeFirstMatch) { return(tokenDictionary.GenerateValidToken(token)); } validToken = token; } } return (tokenDictionary.GenerateValidToken(!string.IsNullOrWhiteSpace(validToken) ? validToken : ConvertCaseFormating(attributes, "_invalid Name_"))); }
void FormatFieldNames(TokenDictionary tokenDictionary) { using (var code = new Microsoft.CSharp.CSharpCodeProvider( )) { foreach (var item in Fields) { var token = tokenDictionary.GenerateValidToken(GuerillaCs.ToMemberName(item.Value.Name)); item.Value.Name = token; } foreach (var item in Methods) { var token = tokenDictionary.GenerateValidToken(GuerillaCs.ToMemberName(item.ClassName)); item.ClassName = token; } foreach (var item in EnumDefinitions) { var token = tokenDictionary.GenerateValidToken(GuerillaCs.ToTypeName(item.Value.Name)); item.Value.Name = token; } } }