public static GetConstTypesAffix ( string type ) : string | ||
type | string | |
return | string |
public void Finalize(MsgFile parent, string[] s, bool isliteral) { backup = new string[s.Length]; Array.Copy(s, backup, s.Length); bool isconst = false; IsLiteral = isliteral; string type = s[0]; string name = s[1]; string otherstuff = ""; if (name.Contains('=')) { string[] parts = name.Split('='); isconst = true; name = parts[0]; otherstuff = " = " + parts[1]; } if (name == parent.Name.Split(".").Last() || !MsgFileLocation.IsValidCSharpIdentifier(name) && name.Length > 0) { if (IsCSharpKeyword(name)) { name = "@" + name; } else if (MsgFileLocation.IsValidCSharpIdentifier(name) && name == parent.Name.Split(".").Last()) { name = "_" + name; } else { throw new ArgumentException(String.Format("Variable '{0}' from '{1}' is not a compatible C# identifier name\n\tAll variable names must conform to C# Language Specifications (refer to this StackOverflow answer: https://stackoverflow.com/a/950651/4036588)\n", name, parent.msgFileLocation.Path)); } } for (int i = 2; i < s.Length; i++) { otherstuff += " " + s[i]; } if (otherstuff.Contains('=')) { isconst = true; } if (!IsArray) { if (otherstuff.Contains('=') && type.Equals("string", StringComparison.CurrentCultureIgnoreCase)) { otherstuff = otherstuff.Replace("\\", "\\\\"); otherstuff = otherstuff.Replace("\"", "\\\""); string[] split = otherstuff.Split('='); otherstuff = split[0] + " = " + split[1].Trim() + ""; } if (otherstuff.Contains('=') && type == "bool") { otherstuff = otherstuff.Replace("0", "false").Replace("1", "true"); } if (otherstuff.Contains('=') && type == "byte") { otherstuff = otherstuff.Replace("-1", "255"); } Const = isconst; bool wantsconstructor = !KnownStuff.IsPrimitiveType(this); if (otherstuff.Contains("=")) { string[] chunks = otherstuff.Split('='); ConstValue = chunks[chunks.Length - 1].Trim(); if (type.Equals("string", StringComparison.OrdinalIgnoreCase)) { otherstuff = chunks[0] + " = \"" + chunks[1].Trim() + "\""; wantsconstructor = false; } } string prefix = "", suffix = ""; if (isconst) { // why can't strings be constants? //if (!type.Equals("string", StringComparison.OrdinalIgnoreCase)) //{ if (KnownStuff.IsPrimitiveType(this)) { prefix = "const "; } else { prefix = "static readonly "; } wantsconstructor = false; //} } string t = KnownStuff.GetNamespacedType(this, type); if (otherstuff.Contains('=')) { if (wantsconstructor) { if (type == "string") { suffix = " = \"\""; } else { suffix = " = new " + type + "()"; } } else { suffix = KnownStuff.GetConstTypesAffix(type); } } else { if (type == "string") { suffix = " = \"\""; } else if (wantsconstructor) { suffix = " = new " + prefix + t + "()"; } } output = lowestindent + "public " + prefix + t + " " + name + otherstuff + suffix + ";"; } else { if (length.Length > 0) { IsLiteral = true; } if (otherstuff.Contains('=')) { string[] split = otherstuff.Split('='); otherstuff = split[0] + " = (" + type + ")" + split[1]; } string t = KnownStuff.GetNamespacedType(this, type); if (length.Length > 0) { output = lowestindent + "public " + t + "[] " + name + otherstuff + " = new " + type + "[" + length + "];"; } else { output = lowestindent + "public " + "" + t + "[] " + name + otherstuff + ";"; } } Type = type; parent.resolve(this); if (!KnownStuff.KnownTypes.ContainsKey(rostype)) { meta = true; } Name = name.Length == 0 ? otherstuff.Trim() : name; if (Name.Contains('=')) { Name = Name.Substring(0, Name.IndexOf("=")).Trim(); } }
public void refinalize(MsgsFile parent, string REALTYPE) { bool isconst = false; string type = REALTYPE; string name = backup[1]; string otherstuff = ""; if (name.Contains('=')) { string[] parts = name.Split('='); isconst = true; name = parts[0]; otherstuff = " = " + parts[1]; } for (int i = 2; i < backup.Length; i++) { otherstuff += " " + backup[i]; } if (otherstuff.Contains('=')) { isconst = true; } parent.resolve(Package, ref type); if (!IsArray) { if (otherstuff.Contains('=') && type.Equals("string", StringComparison.CurrentCultureIgnoreCase)) { otherstuff = otherstuff.Replace("\\", "\\\\"); otherstuff = otherstuff.Replace("\"", "\\\""); string[] split = otherstuff.Split('='); otherstuff = split[0] + " = \"" + split[1].Trim() + "\""; } if (otherstuff.Contains('=') && type == "bool") { otherstuff = otherstuff.Replace("0", "false").Replace("1", "true"); } if (otherstuff.Contains('=') && type == "byte") { otherstuff = otherstuff.Replace("-1", "255"); } Const = isconst; bool wantsconstructor = false; if (otherstuff.Contains("=")) { string[] chunks = otherstuff.Split('='); ConstValue = chunks[chunks.Length - 1].Trim(); if (type.Equals("string", StringComparison.InvariantCultureIgnoreCase)) { otherstuff = chunks[0] + " = new String(\"" + chunks[1].Trim().Replace("\"", "") + "\")"; } } else if (!type.Equals("String")) { wantsconstructor = true; } string prefix = "", suffix = ""; if (isconst) { if (!type.Equals("string", StringComparison.InvariantCultureIgnoreCase)) { prefix = "const "; } } if (otherstuff.Contains('=')) { if (wantsconstructor) { if (type == "string") { suffix = " = \"\""; } else { suffix = " = new " + type + "()"; } } else { suffix = KnownStuff.GetConstTypesAffix(type); } } output = lowestindent + "public " + prefix + type + " " + name + otherstuff + suffix + ";"; } else { if (length.Length != 0) { IsLiteral = type != "string"; } if (otherstuff.Contains('=')) { string[] split = otherstuff.Split('='); otherstuff = split[0] + " = (" + type + ")" + split[1]; } if (length.Length != 0) { output = lowestindent + "public " + type + "[] " + name + otherstuff + " = new " + type + "[" + length + "];"; } else { output = lowestindent + "public " + "" + type + "[] " + name + otherstuff + ";"; } } Type = type; if (!KnownStuff.KnownTypes.ContainsKey(rostype)) { meta = true; } Name = name.Length == 0 ? otherstuff.Split('=')[0].Trim() : name; }
public void Finalize(MsgFile parent, string[] s, bool isliteral) { backup = new string[s.Length]; Array.Copy(s, backup, s.Length); bool isstatic = false; IsLiteral = isliteral; string type = s[0]; string name = s[1]; string otherstuff = ""; if (name.Contains('=')) { string[] parts = name.Split('='); isstatic = true; name = parts[0]; otherstuff = " = " + parts[1]; } if (IsCSharpKeyword(name)) { name = "@" + name; } for (int i = 2; i < s.Length; i++) { otherstuff += " " + s[i]; } if (otherstuff.Contains('=')) { isstatic = true; } if (!IsArray) { if (otherstuff.Contains('=') && type.Equals("string", StringComparison.CurrentCultureIgnoreCase)) { otherstuff = otherstuff.Replace("\\", "\\\\"); otherstuff = otherstuff.Replace("\"", "\\\""); string[] split = otherstuff.Split('='); otherstuff = split[0] + " = " + split[1].Trim() + ""; } if (otherstuff.Contains('=') && type == "bool") { otherstuff = otherstuff.Replace("0", "false").Replace("1", "true"); } if (otherstuff.Contains('=') && type == "byte") { otherstuff = otherstuff.Replace("-1", "255"); } Static = isstatic; bool wantsconstructor = true; if (otherstuff.Contains("=")) { string[] chunks = otherstuff.Split('='); StaticValue = chunks[chunks.Length - 1].Trim(); if (type.Equals("string", StringComparison.OrdinalIgnoreCase)) { otherstuff = chunks[0] + " = \"" + chunks[1].Trim() + "\""; wantsconstructor = false; } } string prefix = "", suffix = ""; if (isstatic) { if (!type.Equals("string", StringComparison.OrdinalIgnoreCase)) { prefix = "static "; wantsconstructor = false; } } string t = KnownStuff.GetNamespacedType(this, type); if (otherstuff.Contains('=')) { if (wantsconstructor) { if (type == "string") { suffix = " = \"\""; } else { suffix = " = new " + type + "()"; } } else { suffix = KnownStuff.GetConstTypesAffix(type); } } else { if (type == "string") { suffix = " = \"\""; } else { suffix = " = new " + prefix + t + "()"; } } output = lowestindent + "public " + prefix + t + " " + name + otherstuff + suffix + ";"; } else { if (length.Length > 0) { IsLiteral = true; } if (otherstuff.Contains('=')) { string[] split = otherstuff.Split('='); otherstuff = split[0] + " = (" + type + ")" + split[1]; } string t = KnownStuff.GetNamespacedType(this, type); if (length.Length > 0) { output = lowestindent + "public " + t + "[] " + name + otherstuff + " = new " + type + "[" + length + "];"; } else { output = lowestindent + "public " + "" + t + "[] " + name + otherstuff + ";"; } } Type = type; parent.resolve(this); if (!KnownStuff.KnownTypes.ContainsKey(rostype)) { meta = true; } Name = name.Length == 0 ? otherstuff.Trim() : name; if (Name.Contains('=')) { Name = Name.Substring(0, Name.IndexOf("=")).Trim(); } }