Exemple #1
0
    public CSProperty(string rawContent, CSEntity parent) : base(rawContent, parent)
    {
        string[] splitContent     = rawContent.Split(' ', '=');
        int      hasVisibilityKey = 0;

        for (int i = 0; i < splitContent.Length; i++)
        {
            if (CSParsingTool.IsVisibilityKeyword(splitContent[i]))
            {
                hasVisibilityKey = 1;
                this.visibility  = splitContent[i];
            }
        }
        if (hasVisibilityKey == 0)
        {
            this.visibility = "public";
        }
        this.type = splitContent[hasVisibilityKey];
        this.name = splitContent[hasVisibilityKey + 1].Replace(";", "");
        int equalIndex = rawContent.IndexOf('=');

        if (equalIndex != -1)
        {
            string rawInitializer = rawContent.Substring(equalIndex + 1);
            this.initializer = rawInitializer.Trim();
        }
    }
Exemple #2
0
    override public string writeAsTypescript()
    {
        string output = this.Indent();

        output += this.visibility + " " + this.name + "(";
        for (int i = 0; i < this.parameters.Count; i++)
        {
            output += this.parameters[i].name + " : " + CSParsingTool.TypescriptTypeFromCSharpType(this.parameters[i].type);
            if (i < this.parameters.Count - 1)
            {
                output += ", ";
            }
        }
        output += ") : " + this.returnType;
        output += " {";
        if (this.children.Count == 0)
        {
            output += "}\n";
        }
        else
        {
            output += "\n";
            this.children.ForEach(
                (c) => {
                output += c.writeAsTypescript();
            }
                );
            output += this.Indent() + "}\n";
        }
        return(output);
    }
Exemple #3
0
 public CSClass(string rawContent, CSEntity parent) : base(rawContent, parent)
 {
     string[] splitContent = rawContent.Split(' ');
     for (int i = 0; i < splitContent.Length; i++)
     {
         if (splitContent[i] == "class")
         {
             if (i + 1 < splitContent.Length)
             {
                 this.name = splitContent[i + 1];
             }
         }
         else if (CSParsingTool.IsVisibilityKeyword(splitContent[i]))
         {
             this.visibility = splitContent[i];
         }
         else if (splitContent[i] == ":")
         {
             if (i + 1 < splitContent.Length)
             {
                 this.baseName = splitContent[i + 1];
             }
         }
     }
 }
    public static List <string> ParseOperation(string rawOperation)
    {
        List <string> splitOperation = new List <string>();
        string        buffer         = "";

        CSParsingTool.ReadOperation(splitOperation, rawOperation, buffer, 0);
        Debug.Log(splitOperation.Count);
        return(splitOperation);
    }
Exemple #5
0
    override public string writeAsTypescript()
    {
        string output = this.Indent();

        output += this.visibility + " " + this.name + " : " + CSParsingTool.TypescriptTypeFromCSharpType(this.type);
        if (this.initializer != null)
        {
            output += " = " + CSParsingTool.CleanOperation(this.initializer);
        }
        output += ";\n";
        return(output);
    }
    // So far only a quick test, need some parsing structure.
    public static string CleanOperation(string rawOperation)
    {
        Debug.Log(rawOperation);
        List <string> splitOperation = CSParsingTool.ParseOperation(rawOperation);

        CSParsingTool.CleanOperationFloats(splitOperation);
        string output = "";

        splitOperation.ForEach(
            (e) => {
            output += e + " ";
        }
            );
        return(output.Trim());
    }
Exemple #7
0
    override public string writeAsTypescript()
    {
        string output = this.Indent();

        output += "class " + this.name;
        if (this.baseName != null)
        {
            output += " extends " + CSParsingTool.TypescriptTypeFromCSharpType(this.baseName);
        }
        output += " {\n";
        this.children.ForEach(
            (c) => {
            output += c.writeAsTypescript();
        }
            );
        output += this.Indent() + "}\n";
        return(output);
    }
    private static void ReadOperation(List <string> splitOperation, string rawOperation, string buffer, int index)
    {
        if (index >= rawOperation.Length)
        {
            return;
        }
        char read = rawOperation[index++];

        if (read == ' ' || read == '+' || read == ';')
        {
            if (!CSParsingTool.IsNullOrEmptyOrBlank(buffer))
            {
                splitOperation.Add(buffer.Trim());
                buffer = "";
            }
        }
        buffer += read;
        CSParsingTool.ReadOperation(splitOperation, rawOperation, buffer, index);
    }
Exemple #9
0
    public CSMethod(string rawContent, CSEntity parent) : base(rawContent, parent)
    {
        string[] splitContent     = rawContent.Split(' ');
        int      hasVisibilityKey = 0;

        for (int i = 0; i < splitContent.Length; i++)
        {
            if (CSParsingTool.IsVisibilityKeyword(splitContent[i]))
            {
                hasVisibilityKey = 1;
                this.visibility  = splitContent[i];
            }
        }
        if (hasVisibilityKey == 0)
        {
            this.visibility = "public";
        }
        this.returnType = splitContent[hasVisibilityKey];
        this.name       = splitContent[hasVisibilityKey + 1].Replace("(", "");
        int    startParametersIndex = rawContent.IndexOf('(');
        int    endParametersIndex   = rawContent.LastIndexOf(')');
        int    lengthParameters     = endParametersIndex - startParametersIndex + 1;
        string rawParameters        = rawContent.Substring(startParametersIndex, lengthParameters);

        rawParameters = rawParameters.Replace("(", "");
        rawParameters = rawParameters.Replace(")", "");
        string[] splitParameters = rawParameters.Split(',');
        for (int i = 0; i < splitParameters.Length; i++)
        {
            splitParameters[i] = splitParameters[i].Trim();
            string[] splitParameter = splitParameters[i].Split(' ');
            if (splitParameter.Length >= 2)
            {
                this.parameters.Add(
                    new CSParameter(
                        splitParameter[0],
                        splitParameter[splitParameter.Length - 1]
                        )
                    );
            }
        }
    }