示例#1
0
        public virtual string CreateValidIdentifier(string value)
        {
            ICodeGenerator cg = CreateGenerator();

            if (cg == null)
            {
                throw GetNotImplemented();
            }
            return(cg.CreateValidIdentifier(value));
        }
 public void TestCreateValidIdentifierNullArg()
 {
     gen.CreateValidIdentifier(null);
 }
示例#3
0
            public void ICodeGeneratorCreateValidIdentifier_Invoke_ReturnsExpected()
            {
                ICodeGenerator generator = this;

                Assert.Equal("validIdentifier", generator.CreateValidIdentifier(null));
            }
示例#4
0
 public string CreateValidIdentifier(string value)
 {
     return(_generator.CreateValidIdentifier(value));
 }
示例#5
0
		public static string MakeSafeName (string name, ICodeGenerator codeGen)
		{
			if (name == null || codeGen == null)
				throw new NullReferenceException ();

			name = codeGen.CreateValidIdentifier (name);

			return MakeSafeNameInternal (name);
		}
		public static string MakeSafeName (string name, ICodeGenerator codeGen)
		{
			if (name == null || codeGen == null)
				throw new NullReferenceException ();

			name = codeGen.CreateValidIdentifier (name);

			if (name.Length == 0)
				return "_";

			StringBuilder sb = null;
			if (!Char.IsLetter (name, 0) && name [0] != '_') {
				sb = new StringBuilder ();
				sb.Append ('_');
			}

			int start = 0;
			for (int i = 0; i < name.Length; i++) {
				if (!Char.IsLetterOrDigit (name, i)) {
					if (sb == null)
						sb = new StringBuilder ();
					sb.Append (name, start, i - start);
					sb.Append ('_');
					start = i + 1;
				}
			}

			if (sb != null) {
				sb.Append (name, start, name.Length - start);
				return sb.ToString ();
			}
			else
				return name;
		}