GetNamespacedType() 공개 정적인 메소드

Returns the namespaced type name (if neccessary)
public static GetNamespacedType ( SingleType st, string type = null ) : string
st SingleType This thing's SingleType
type string (optional) the type string
리턴 string
예제 #1
0
        public string GenerateRandomizationCode(SingleType st, int extraTabs = 0)
        {
            string leadingWhitespace = "";

            for (int i = 0; i < LEADING_WHITESPACE + extraTabs; i++)
            {
                leadingWhitespace += "    ";
            }

            // this happens  for each member of the outer message
            // after concluding, make sure part of the string is "currentIndex += <amount read while deserializing this thing>"
            // start of deserializing piece referred to by st is currentIndex (its value at time of call to this fn)"

            string pt = KnownStuff.GetNamespacedType(st);

            if (st.Const)
            {
                return("");
            }
            else if (!st.IsArray)
            {
                return(GenerateRandomizationCodeForOne(st.Type, st.Name, st, extraTabs));
            }

            string ret            = string.Format(@"
{0}//{1}", leadingWhitespace, st.Name);
            int    arraylength    = -1;
            string arraylengthstr = "arraylength";

            //If the object is an array, send each object to be processed individually, then add them to the string

            //handle fixed length fields?
            if (!string.IsNullOrEmpty(st.length) && int.TryParse(st.length, out arraylength) && arraylength != -1)
            {
                arraylengthstr = "" + arraylength;
            }
            else
            {
                ret += string.Format(@"
{0}arraylength = rand.Next(10);", leadingWhitespace);
            }
            ret += string.Format(@"
{0}if ({1} == null)
{0}    {1} = new {2}[{3}];
{0}else
{0}    Array.Resize(ref {1}, {3});", leadingWhitespace, st.Name, pt, arraylengthstr);

            ret += string.Format(@"
{0}for (int i=0;i<{1}.Length; i++) {{{2}
{0}}}", leadingWhitespace, st.Name, GenerateRandomizationCodeForOne(pt, st.Name + "[i]", st, extraTabs + 1));
            return(ret);
        }
예제 #2
0
        public string GenerateSerializationCode(SingleType st, int extraTabs = 0)
        {
            string leadingWhitespace = "";

            for (int i = 0; i < LEADING_WHITESPACE + extraTabs; i++)
            {
                leadingWhitespace += "    ";
            }
            if (st.Const)
            {
                return("");
            }
            if (!st.IsArray)
            {
                return(GenerateSerializationForOne(st.Type, st.Name, st, extraTabs));
            }

            int    arraylength  = -1;
            string ret          = string.Format(@"
{0}//{2}
{0}hasmetacomponents |= {1};", leadingWhitespace, st.meta.ToString().ToLower(), st.Name);
            string completetype = KnownStuff.GetNamespacedType(st);

            ret += string.Format(@"
{0}if ({1} == null)
{0}    {1} = new {2}[0];", leadingWhitespace, st.Name, completetype);
            if (string.IsNullOrEmpty(st.length) || !int.TryParse(st.length, out arraylength) || arraylength == -1)
            {
                ret += string.Format(@"
{0}pieces.Add(BitConverter.GetBytes({1}.Length));", leadingWhitespace, st.Name);
            }
            //special case arrays of bytes
            if (st.Type == "byte")
            {
                ret += string.Format(@"
{0}pieces.Add(({2}[]){1});", leadingWhitespace, st.Name, st.Type);
            }
            else
            {
                if (!st.IsPrimitve || (st.Type == "string") || (st.Type == "bool"))
                {
                    ret += string.Format(@"
{0}for (int i=0;i<{1}.Length; i++) {{{2}
{0}}}", leadingWhitespace, st.Name, GenerateSerializationForOne(st.Type, st.Name + "[i]", st, extraTabs + 1));
                }
                else
                {
                    ret += GenerateSerializationForOne(st.Type, st.Name + "[i]", st, extraTabs + 1, true);
                }
            }
            return(ret);
        }
예제 #3
0
        public static string Generate(SingleType members)
        {
            string mt = "xamla/unknown";
            string pt = KnownStuff.GetNamespacedType(members);

            if (members.meta)
            {
                string t = members.Type.Replace("Messages.", "");
                if (!t.Contains('.'))
                {
                    if (members.Definer != null)
                    {
                        t = members.Definer.Package + "." + t;
                    }
                    else
                    {
                        t = null;
                    }
                }
                if (t != null)
                {
                    mt = t.Replace(".", "/");
                }
                else
                {
                    members.meta = false;
                }
            }
            return(String.Format
                       ("\"{0}\", new MsgFieldInfo(\"{0}\", {1}, {2}, {3}, \"{4}\", {5}, \"{6}\", {7}, {8})",
                       members.Name.Replace("@", ""),
                       members.IsLiteral.ToString().ToLower(),
                       ("typeof(" + pt + ")"),
                       members.Static.ToString().ToLower(),
                       members.StaticValue.TrimStart('"').TrimEnd('"'),
                       //members.Type.Equals("string", StringComparison.InvariantCultureIgnoreCase) ? ("new String("+members.StaticValue+")") : ("\""+members.StaticValue+"\""),
                       members.IsArray.ToString().ToLower(),
                       members.length,
                       //FIX MEEEEEEEE
                       members.meta.ToString().ToLower(),
                       mt));
        }
예제 #4
0
        private string GenerateRandomizationCodeForOne(string type, string name, SingleType st, int extraTabs = 0)
        {
            string leadingWhitespace = "";

            for (int i = 0; i < LEADING_WHITESPACE + extraTabs; i++)
            {
                leadingWhitespace += "    ";
            }
            string pt = KnownStuff.GetNamespacedType(st);

            if (type == "Time" || type == "Duration")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = new {2}(new TimeData(
{0}        Convert.ToUInt32(rand.Next()),
{0}        Convert.ToUInt32(rand.Next())));", leadingWhitespace, name, pt));
            }
            else if (type == "TimeData")
            {
                return(string.Format(@"
{0}//{1}
{0}{1}.sec = Convert.ToUInt32(rand.Next());
{0}{1}.nsec  = Convert.ToUInt32(rand.Next());", leadingWhitespace, name));
            }
            else if (type == "byte")
            {
                return(string.Format(@"
{0}//{1}
{0}myByte = new byte[1];
{0}rand.NextBytes(myByte);
{0}{1}= myByte[0];", leadingWhitespace, name));
            }
            else if (type == "string")
            {
                return(string.Format(@"
{0}//{1}
{0}strlength = rand.Next(100) + 1;
{0}strbuf = new byte[strlength];
{0}rand.NextBytes(strbuf);  //fill the whole buffer with random bytes
{0}for (int __x__ = 0; __x__ < strlength; __x__++)
{0}    if (strbuf[__x__] == 0) //replace null chars with non-null random ones
{0}        strbuf[__x__] = (byte)(rand.Next(254) + 1);
{0}strbuf[strlength - 1] = 0; //null terminate
{0}{1} = Encoding.ASCII.GetString(strbuf);", leadingWhitespace, name));
            }
            else if (type == "bool")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = rand.Next(2) == 1;", leadingWhitespace, name));
            }
            else if (type == "int")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = rand.Next();", leadingWhitespace, name));
            }
            else if (type == "uint")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = (uint)rand.Next();", leadingWhitespace, name));
            }
            else if (type == "double")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = (rand.Next() + rand.NextDouble());", leadingWhitespace, name));
            }
            else if (type == "float" || type == "Float64" || type == "Single")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = (float)(rand.Next() + rand.NextDouble());", leadingWhitespace, name));
            }
            else if (type == "Int16" || type == "Short" || type == "short")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = (System.Int16)rand.Next(System.Int16.MaxValue + 1);", leadingWhitespace, name));
            }
            else if (type == "UInt16" || type == "ushort" || type == "UShort")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = (System.UInt16)rand.Next(System.UInt16.MaxValue + 1);", leadingWhitespace, name));
            }
            else if (type == "SByte" || type == "sbyte")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = (SByte)(rand.Next(255) - 127);", leadingWhitespace, name));
            }
            else if (type == "UInt64" || type == "ULong" || type == "ulong")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = (System.UInt64)((uint)(rand.Next() << 32)) | (uint)rand.Next();", leadingWhitespace, name));
            }
            else if (type == "Int64" || type == "Long" || type == "long")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = (System.Int64)(rand.Next() << 32) | rand.Next();", leadingWhitespace, name));
            }
            else if (type == "char")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = (char)(byte)(rand.Next(254) + 1);", leadingWhitespace, name));
            }
            else if (st.IsLiteral)
            {
                throw new ArgumentException($"{st.Type} is not supported");
            }
            else
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = new {2}();
{0}{1}.Randomize();", leadingWhitespace, name, pt));
            }
        }
예제 #5
0
        private string GenerateDeserializationForOne(string type, string name, SingleType st, int extraTabs = 0, bool special = false)
        {
            string leadingWhitespace = "";

            for (int i = 0; i < LEADING_WHITESPACE + extraTabs; i++)
            {
                leadingWhitespace += "    ";
            }
            string pt = KnownStuff.GetNamespacedType(st);

            if (type == "Time" || type == "Duration")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = new {2}(new TimeData(
{0}        BitConverter.ToUInt32(serializedMessage, currentIndex),
{0}        BitConverter.ToUInt32(serializedMessage, currentIndex+Marshal.SizeOf(typeof(System.Int32)))));
{0}currentIndex += 2*Marshal.SizeOf(typeof(System.Int32));", leadingWhitespace, name, pt));
            }
            else if (type == "TimeData")
            {
                return(string.Format(@"
{0}//{1}
{0}{1}.sec = BitConverter.ToUInt32(serializedMessage, currentIndex);
{0}currentIndex += Marshal.SizeOf(typeof(System.Int32));
{0}{1}.nsec  = BitConverter.ToUInt32(serializedMessage, currentIndex);
{0}currentIndex += Marshal.SizeOf(typeof(System.Int32));", leadingWhitespace, name));
            }
            else if (type == "byte")
            {
                return(string.Format(@"
{0}//{1}
{0}{1}=serializedMessage[currentIndex++];", leadingWhitespace, name));
            }
            else if (type == "string")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = """";
{0}piecesize = BitConverter.ToInt32(serializedMessage, currentIndex);
{0}currentIndex += 4;
{0}{1} = Encoding.ASCII.GetString(serializedMessage, currentIndex, piecesize);
{0}currentIndex += piecesize;", leadingWhitespace, name));
            }
            else if (type == "bool")
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = serializedMessage[currentIndex++]==1;", leadingWhitespace, name));
            }
            else if (st.IsLiteral && !special)
            {
                string ret = string.Format(@"
{0}//{2}
{0}piecesize = Marshal.SizeOf(typeof({1}));
{0}h = IntPtr.Zero;
{0}if (serializedMessage.Length - currentIndex != 0)
{0}{{
{0}    h = Marshal.AllocHGlobal(piecesize);
{0}    Marshal.Copy(serializedMessage, currentIndex, h, piecesize);
{0}}}
{0}if (h == IntPtr.Zero) throw new Exception(""Memory allocation failed"");
{0}{2} = ({1})Marshal.PtrToStructure(h, typeof({1}));
{0}Marshal.FreeHGlobal(h);
{0}currentIndex+= piecesize;", leadingWhitespace, pt, name);

                return(ret);
            }
            else if (st.IsLiteral && special)
            {
                string ret = string.Format(@"
// Start Xamla
{0}//{2}
{0}piecesize = Marshal.SizeOf(typeof({1})) * {2}.Length;
{0}if (currentIndex + piecesize > serializedMessage.Length) {{
{0}    throw new Exception(""Memory allocation failed: Ran out of bytes to read."");
{0}}}
{0}Buffer.BlockCopy(serializedMessage, currentIndex, {2}, 0, piecesize);
{0}currentIndex += piecesize;
// End Xamla
", leadingWhitespace, pt, name.Substring(0, name.Length - 3));

                return(ret);
            }
            else
            {
                return(string.Format(@"
{0}//{1}
{0}{1} = new {2}(serializedMessage, ref currentIndex);", leadingWhitespace, name, pt));
            }
        }
예제 #6
0
        public string GenerateDeserializationCode(SingleType st, int extraTabs = 0)
        {
            string leadingWhitespace = "";

            for (int i = 0; i < LEADING_WHITESPACE + extraTabs; i++)
            {
                leadingWhitespace += "    ";
            }
            // this happens  for each member of the outer message
            // after concluding, make sure part of the string is "currentIndex += <amount read while deserializing this thing>"
            // start of deserializing piece referred to by st is currentIndex (its value at time of call to this fn)"

            string pt = KnownStuff.GetNamespacedType(st);

            if (st.Const)
            {
                return("");
            }
            else if (!st.IsArray)
            {
                return(GenerateDeserializationForOne(st.Type, st.Name, st, extraTabs));
            }

            string ret            = string.Format(@"
{0}//{2}
{0}hasmetacomponents |= {1};", leadingWhitespace, st.meta.ToString().ToLower(), st.Name);
            int    arraylength    = -1;
            string arraylengthstr = "arraylength";

            //If the object is an array, send each object to be processed individually, then add them to the string

            //handle fixed length fields?
            if (!string.IsNullOrEmpty(st.length) && int.TryParse(st.length, out arraylength) && arraylength != -1)
            {
                arraylengthstr = "" + arraylength;
            }
            else
            {
                ret += string.Format(@"
{0}arraylength = BitConverter.ToInt32(serializedMessage, currentIndex);
{0}currentIndex += Marshal.SizeOf(typeof(System.Int32));", leadingWhitespace);
            }
            ret += string.Format(@"
{0}if ({1} == null)
{0}    {1} = new {2}[{3}];
{0}else
{0}    Array.Resize(ref {1}, {3});", leadingWhitespace, st.Name, pt, arraylengthstr);

            //special case arrays of bytes
            if (st.Type == "byte")
            {
                ret += string.Format(@"
{0}Array.Copy(serializedMessage, currentIndex, {1}, 0, {1}.Length);
{0}currentIndex += {1}.Length;", leadingWhitespace, st.Name);
            }
            else
            {
                if (!st.IsPrimitve || (st.Type == "string") || (st.Type == "bool"))
                {
                    ret += string.Format(@"
{0}for (int i=0;i<{1}.Length; i++) {{{2}
{0}}}", leadingWhitespace, st.Name, GenerateDeserializationForOne(pt, st.Name + "[i]", st, extraTabs + 1));
                }
                else
                {
                    ret += GenerateDeserializationForOne(pt, st.Name + "[i]", st, extraTabs + 1, true);
                }
            }
            return(ret);
        }
예제 #7
0
        private string GenerateSerializationForOne(string type, string name, SingleType st, int extraTabs = 0, bool special = false)
        {
            string leadingWhitespace = "";

            for (int i = 0; i < LEADING_WHITESPACE + extraTabs; i++)
            {
                leadingWhitespace += "    ";
            }
            type = KnownStuff.GetNamespacedType(st, type);
            if (type == "Time" || type == "Duration")
            {
                return(string.Format(@"
{0}//{1}
{0}pieces.Add(BitConverter.GetBytes({1}.data.sec));
{0}pieces.Add(BitConverter.GetBytes({1}.data.nsec));", leadingWhitespace, name));
            }
            else if (type == "TimeData")
            {
                return(string.Format(@"
{0}//{1}
{0}pieces.Add(BitConverter.GetBytes({1}.sec));
{0}pieces.Add(BitConverter.GetBytes({1}.nsec));", leadingWhitespace, name));
            }
            else if (type == "byte")
            {
                return(string.Format(@"
{0}//{1}
{0}pieces.Add(new[] {{ (byte){1} }});", leadingWhitespace, name));;
            }
            else if (type == "string")
            {
                return(string.Format(@"
{0}//{1}
{0}if ({1} == null)
{0}    {1} = """";
{0}scratch1 = Encoding.ASCII.GetBytes((string){1});
{0}thischunk = new byte[scratch1.Length + 4];
{0}scratch2 = BitConverter.GetBytes(scratch1.Length);
{0}Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length);
{0}Array.Copy(scratch2, thischunk, 4);
{0}pieces.Add(thischunk);", leadingWhitespace, name));
            }
            else if (type == "bool")
            {
                return(string.Format(@"
{0}//{1}
{0}thischunk = new byte[1];
{0}thischunk[0] = (byte) ((bool){1} ? 1 : 0 );
{0}pieces.Add(thischunk);", leadingWhitespace, name));
            }
            else if (st.IsLiteral && !special)
            {
                return(string.Format(@"
{0}//{1}
{0}scratch1 = new byte[Marshal.SizeOf(typeof({2}))];
{0}h = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
{0}Marshal.StructureToPtr({1}, h.AddrOfPinnedObject(), false);
{0}h.Free();
{0}pieces.Add(scratch1);", leadingWhitespace, name, type));
            }
            else if (st.IsLiteral && special)
            {
                return(string.Format(@"
// Start Xamla
{0}//{1}
{0}x__size = Marshal.SizeOf(typeof({2})) * {1}.Length;
{0}scratch1 = new byte[x__size];
{0}Buffer.BlockCopy({1}, 0, scratch1, 0, x__size);
{0}pieces.Add(scratch1);
// End Xamla
", leadingWhitespace, name.Substring(0, name.Length - 3), type));
            }
            else
            {
                return(string.Format(@"
{0}//{1}
{0}if ({1} == null)
{0}    {1} = new {2}();
{0}pieces.Add({1}.Serialize(true));", leadingWhitespace, name, type));
            }
        }
예제 #8
0
        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();
            }
        }
예제 #9
0
        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();
            }
        }
예제 #10
0
        public void refinalize(MsgFile parent, string REALTYPE)
        {
            bool isstatic = false;

            Type = REALTYPE;
            string name       = backup[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 < backup.Length; i++)
            {
                otherstuff += " " + backup[i];
            }
            if (otherstuff.Contains('='))
            {
                isstatic = true;
            }
            parent.resolve(this);
            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 = false;
                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().Replace("\"", "") + "\"";
                    }
                }
                else if (!Type.Equals("String"))
                {
                    wantsconstructor = true;
                }
                string prefix = "", suffix = "";
                if (isstatic)
                {
                    if (!Type.Equals("string", StringComparison.OrdinalIgnoreCase))
                    {
                        prefix = "const ";
                    }
                }
                if (otherstuff.Contains('='))
                {
                    if (wantsconstructor)
                    {
                        if (Type == "string")
                        {
                            suffix = " = \"\"";
                        }
                        else
                        {
                            suffix = " = new " + Type + "()";
                        }
                    }
                    else
                    {
                        suffix = KnownStuff.GetConstTypesAffix(Type);
                    }
                }
                string t = KnownStuff.GetNamespacedType(this, Type);
                output = lowestindent + "public " + prefix + t + " " + name + otherstuff + suffix + ";";
            }
            else
            {
                if (length.Length != 0)
                {
                    IsLiteral = true; //type != "string";
                }
                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 " + t + "[" + length + "];";
                }
                else
                {
                    output = lowestindent + "public " + "" + t + "[] " + name + otherstuff + ";";
                }
            }
            if (!KnownStuff.KnownTypes.ContainsKey(rostype))
            {
                meta = true;
            }
            Name = name.Length == 0 ? otherstuff.Split('=')[0].Trim() : name;
        }