示例#1
0
        /// <summary>
        /// Takes an array of string values, and converts it to the proper value type for
        /// this instance's Generic Type
        /// </summary>
        /// <param name="ValueParams">The string value's to convert, and set the
        /// Value of this instance to.
        /// </param>
        public override void SetValue(Token token, int objectLevel = 0)
        {
            Type PropertyType = typeof(T);

            // ===
            // DONOT use this ObjectProperties TOKEN! breaks collections!
            TokenArgs tokenArgs = token.TokenArgs;

            // ===

            // Check for ConFileObjects
            if (typeof(ConFileObject).IsAssignableFrom(PropertyType))
            {
                // define vars
                ConFileObject obj = (ConFileObject)(object)Value;

                // Load a new object if we are undefined
                if (obj == null)
                {
                    // Is this a defined object?
                    string name = tokenArgs.Arguments.Last();
                    //var type = ScriptEngine.GetTemplateType(PropertyType);

                    // Check for the object in this properties owner's Scope
                    if (Token.File.Scope.ContainsObject(name, PropertyType))
                    {
                        obj      = Token.File.Scope.GetObject(name, PropertyType, Token);
                        Argument = new ValueInfo <T>((T)(object)obj);
                    }
                    else
                    {
                        string error = $"ObjectProperty \"{Name}\" requires an existing object that is not defined!";
                        throw new Exception(error);
                    }
                }
                else
                {
                    // Let the child class parse itself
                    obj.Parse(token, ++objectLevel);
                    Argument = new ValueInfo <T>((T)(object)obj);
                }
            }
            else if (PropertyType.IsGenericType)
            {
                // Check for Generic types, we don't support these!
                throw new Exception($"Invalid Generic Type found \"{PropertyType}\"");
            }
            else
            {
                // Since we are not an array property, make sure we didnt get
                // an array passed in the con file
                if (tokenArgs.Arguments.Length > 1)
                {
                    throw new Exception($"Expecting single value, but got an Array for \"{Name}\"");
                }

                // Since we are not an array, extract our only value
                Argument = new ValueInfo <T>(ConvertValue <T>(tokenArgs.Arguments[0], PropertyType));
            }
        }
示例#2
0
        /// <summary>
        /// Attempts to fetch a <see cref="ConFileObject"/>, using the
        /// provided <see cref="ScopeOptions"/>
        /// </summary>
        /// <param name="token"></param>
        internal ConFileObject GetObject(Token token)
        {
            // Pull info
            try
            {
                TokenArgs tokenArgs = token.TokenArgs;
                string    name      = token.TokenArgs.Arguments.Last();

                // Create our Objects key
                var type = tokenArgs.ReferenceType;
                var key  = new Tuple <string, ReferenceType>(name, type);
                return(GetObject(key, token));
            }
            catch
            {
                throw;
            }
        }