Beispiel #1
0
        protected virtual TsonNode Visit(TsonNode node)
        {
            if (node == null)
                return node;

            switch (node.NodeType)
            {
            case TsonNodeType.String:
                return this.VisitString((TsonStringNode)node);
            case TsonNodeType.Number:
                return this.VisitNumber((TsonNumberNode)node);
            case TsonNodeType.Boolean:
                return this.VisitBoolean((TsonBooleanNode)node);
            case TsonNodeType.Null:
                return this.VisitNull((TsonNullNode)node);
            case TsonNodeType.Array:
                return this.VisitArray((TsonArrayNodeBase)node);
            case TsonNodeType.Object:
                {
                    if (!visitedRoot)
                    {
                        node = this.VisitRootObject((TsonObjectNodeBase)node);
                        visitedRoot = true;
                        return node;
                    }
                    else
                        return this.VisitObject((TsonObjectNodeBase)node);
                }
            default:
                throw new NotSupportedException();
            }
        }
        public void SetItemValue(TsonNode node)
        {
            // NOTE: This assumes an indexer that can accept an arbitrary index and still work
            // Not List<> for example.
            var itemPropInfo = PropertyType.GetProperty("Item");

            if (itemPropInfo == null)
                return;

            try
            {
                itemPropInfo.SetValue(this.GetPropertyValue(), node, new object[] { (object)this.Index });
            }
            catch (Exception e)
            {
                throw new TsonFormatException(node.Token,
                    String.Format("Cannot set array property", PropertyInfo.Name), e);
            }
        }
 public ContentFileException(TsonNode node, string message, Exception innerException)
     : base(message, innerException)
 {
     ErrorLocation = node.Token.Location;
 }
 public ContentFileException(TsonNode node, Exception innerException)
     : base("", innerException)
 {
     ErrorLocation = node.Token.Location;
 }
 public ContentFileException(TsonNode node)
     : base()
 {
     ErrorLocation = node.Token.Location;
 }
 public CompactNodeVisitor(TsonNode node)
 {
     this.node = node;
 }
Beispiel #7
0
 public ContentFileException(TsonNode node, string message, Exception innerException)
     : base(message, innerException)
 {
     ErrorLocation = node.Token.Location;
 }
        private void ApplyParameters(
            TsonNode parentNode,
            string compilerName,
            object instance,
            Dictionary <string, AttributedProperty> attrProps,
            TsonObjectNode parameterNode)
        {
            HashSet <string> required =
                new HashSet <string>(
                    from s in attrProps
                    where s.Value.Attribute.Optional == false
                    select s.Key);

            foreach (var keyValue in parameterNode.KeyValues)
            {
                var keyNode   = keyValue.Key;
                var valueNode = keyValue.Value;
                AttributedProperty attrProp;

                attrProps.TryGetValue(keyNode.Value, out attrProp);

                if (attrProp == null)
                {
                    WriteWarning("Supplied parameter '{0}' is not applicable to the '{1}' compiler".CultureFormat(keyNode.Value, compilerName));
                    continue;
                }

                PropertyInfo propertyInfo = attrProp.Property;

                if (!propertyInfo.CanWrite)
                {
                    throw new ContentFileException(parentNode, "Unable to write to the '{0}' property of '{1}' compiler".CultureFormat(keyNode.Value, compilerName));
                }

                object obj = null;

                if (propertyInfo.PropertyType == typeof(double))
                {
                    var numberNode = valueNode as TsonNumberNode;

                    if (numberNode == null)
                    {
                        throw new ContentFileException(valueNode, "TSON node for '{0}' is not a number".CultureFormat(keyNode.Value));
                    }

                    obj = numberNode.Value;
                }
                else if (propertyInfo.PropertyType == typeof(string))
                {
                    var numberNode = valueNode as TsonStringNode;

                    if (numberNode == null)
                    {
                        throw new ContentFileException(valueNode, "TSON node for '{0}' is not a string".CultureFormat(keyNode.Value));
                    }

                    obj = numberNode.Value;
                }
                else if (propertyInfo.PropertyType == typeof(bool))
                {
                    obj = ((TsonBooleanNode)valueNode).Value;
                }
                else
                {
                    throw new ContentFileException(
                              parameterNode,
                              "Setting '{0}' parameter for compiler '{1}' must be bool, double or string".CultureFormat(keyNode.Value, compilerName));
                }

                try
                {
                    propertyInfo.SetValue(instance, obj, null);
                }
                catch (Exception e)
                {
                    throw new ContentFileException(keyValue.Key, "Error setting compiler property", e);
                }

                required.Remove(keyNode.Value);
            }

            if (required.Count != 0)
            {
                throw new ContentFileException(
                          parentNode,
                          "Required parameter '{0}' of compiler '{1}' was not set".CultureFormat(required.First(), compilerName));
            }
        }
Beispiel #9
0
 public ContentFileException(TsonNode node) : base()
 {
     ErrorLocation = node.Token.Location;
 }
 public ToPrettyTsonNodeVisitor(TsonNode rootNode, string indentChars = "  ")
 {
     this.rootNode = rootNode;
     this.indentChars = indentChars;
     this.indent = String.Empty;
 }
Beispiel #11
0
 public XmlTsonNodeVisitor(TsonNode rootNode)
 {
     this.rootNode = rootNode;
 }
Beispiel #12
0
        // NOTE: Use for creating the token/offset arrays
        private string GetTokenOffsetInfo(TsonNode node)
        {
            StringBuilder sb = new StringBuilder();

            new CallbackTsonNodeVisitor((n) =>
            {
                if (sb.Length > 0)
                    sb.Append(", ");

                sb.AppendFormat("{{ TsonNodeType.{0}, {1} }}",
                    n.NodeType.ToString(), n.Token.Location.Offset.ToString());
            }).VisitAll(node);

            return sb.ToString();
        }
 public void VisitAll(TsonNode node)
 {
     Visit(node);
 }
Beispiel #14
0
 public ToJsvTsonNodeVisitor(TsonNode node)
 {
     this.node = node;
 }
Beispiel #15
0
 public void SetPropertyValue(TsonNode node)
 {
     try
     {
         this.PropertyInfo.SetValue(Instance, node);
     }
     catch (Exception e)
     {
         throw new TsonFormatException(node.Token,
             String.Format("Cannot set non-array property {0}", PropertyInfo.Name), e);
     }
 }
 public ToJsonTsonNodeVisitor(TsonNode rootNode, string indentChars = "  ")
 {
     this.rootNode = rootNode;
 }
Beispiel #17
0
 public ContentFileException(TsonNode node, Exception innerException)
     : base("", innerException)
 {
     ErrorLocation = node.Token.Location;
 }