Esempio n. 1
0
        private int BuildAutoProperty(int index, WrapperObject contentObject, WrapperObject parentObject)
        {
            index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index);
            WrapperObject setObject = new WrapperObject("SET");
            WrapperObject getObject = new WrapperObject("GET");

            contentObject.CopyData(getObject);
            contentObject.CopyData(setObject);

            string compVariableName = "_" + char.ToLower(contentObject.WrapperName[0]).ToString() + contentObject.WrapperName.Substring(1);
            string holdOlderName    = contentObject.WrapperName;

            if (!parentObject.GetKeys().Contains(compVariableName))
            {
                contentObject.WrapperName = compVariableName;
                contentObject.UpdateStringValue("ACCESS_MOD", "private");
                parentObject.Value.Add(contentObject);
            }

            WrapperString valueType  = setObject.GetValue("VALUE_TYPE") as WrapperString;
            WrapperObject parameters = new WrapperObject("PARAMETERS");
            WrapperObject parameter  = new WrapperObject($"PARAMETER_1");

            parameter.Value.Add(new WrapperString("VALUE_TYPE", valueType.Value));
            parameter.Value.Add(new WrapperString("PARAM_NAME", "value"));
            setObject.UpdateStringValue("VALUE_TYPE", "void");
            parameters.Value.Add(parameter);
            setObject.Value.Add(parameters);

            if (this.TokenList[index] == "get")
            {
                index = this.BuildAuxMethod(index, getObject, compVariableName);
                index = this.BuildAuxMethod(index, setObject, compVariableName);
            }
            else if (this.TokenList[index] == "set")
            {
                index = this.BuildAuxMethod(index, setObject, compVariableName);
                index = this.BuildAuxMethod(index, getObject, compVariableName);
            }
            else
            {
                throw new Exception("This auto property needs an explicet get and set keywords.");
            }

            index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index);
            getObject.WrapperName = $"Get{holdOlderName}";
            setObject.WrapperName = $"Set{holdOlderName}";
            parentObject.Value.Add(getObject);
            parentObject.Value.Add(setObject);
            this._autoPropertyList.Add(holdOlderName);
            this._autoPropertyList.Add($"this.{holdOlderName}");

            return(index);
        }