internal CompilerClass(TsonStringNode assemblyNode, Assembly assembly, Type type, Type interfaceType) { this.Assembly = assembly; this.Type = type; this.Interface = interfaceType; this.Instance = Activator.CreateInstance(this.Type); compilerParameters = new Dictionary <string, AttributedProperty>(); targetParameters = new Dictionary <string, AttributedProperty>(); foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { if (propertyInfo.Name == "Target") { this.TargetProperty = propertyInfo; } else if (propertyInfo.Name == "Context") { this.ContextProperty = propertyInfo; } else if (propertyInfo.Name == "Extensions") { this.ExtensionsProperty = propertyInfo; } else { object[] attributes = propertyInfo.GetCustomAttributes(typeof(ContentCompilerParameterAttribute), true); ContentCompilerParameterAttribute attribute; if (attributes.Length == 1) { attribute = (ContentCompilerParameterAttribute)attributes[0]; } else { continue; } if (!(propertyInfo.CanRead && propertyInfo.CanWrite)) { throw new ContentFileException( assemblyNode, "Settings property '{0}' on '{1}' compiler must be read/write".CultureFormat(propertyInfo.Name, this.Name)); } var property = new AttributedProperty(attribute, propertyInfo); if (attribute.ForCompiler) { compilerParameters.Add(propertyInfo.Name, property); } else { targetParameters.Add(propertyInfo.Name, property); } } } }
internal CompilerClass(TsonStringNode assemblyNode, Assembly assembly, Type type, Type interfaceType) { this.Assembly = assembly; this.Type = type; this.Interface = interfaceType; this.Instance = Activator.CreateInstance(this.Type); compilerParameters = new Dictionary<string, AttributedProperty>(); targetParameters = new Dictionary<string, AttributedProperty>(); foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { if (propertyInfo.Name == "Target") { this.TargetProperty = propertyInfo; } else if (propertyInfo.Name == "Context") { this.ContextProperty = propertyInfo; } else if (propertyInfo.Name == "Extensions") { this.ExtensionsProperty = propertyInfo; } else { object[] attributes = propertyInfo.GetCustomAttributes(typeof(ContentCompilerParameterAttribute), true); ContentCompilerParameterAttribute attribute; if (attributes.Length == 1) attribute = (ContentCompilerParameterAttribute)attributes[0]; else continue; if (!(propertyInfo.CanRead && propertyInfo.CanWrite)) throw new ContentFileException( assemblyNode, "Settings property '{0}' on '{1}' compiler must be read/write".CultureFormat(propertyInfo.Name, this.Name)); var property = new AttributedProperty(attribute, propertyInfo); if (attribute.ForCompiler) compilerParameters.Add(propertyInfo.Name, property); else targetParameters.Add(propertyInfo.Name, property); } } }
private TsonObjectNode ParseObject() { TsonToken token = tokenizer.Next(); if (!token.IsLeftCurlyBrace) throw new TsonParseException(token, "Expected a '{'"); var node = new TsonObjectNode() { Token = token }; token = tokenizer.Next(); if (token.IsRightCurlyBrace) return node; while (true) { if (!token.IsString) throw new TsonParseException(token, "Expected a string"); TsonStringNode key = new TsonStringNode(token.Data as string); token = tokenizer.Next(); if (!token.IsColon) throw new TsonParseException(token, "Expected a ':'"); TsonNode value = ParseValueArrayOrObject(); node.Add(key, value); token = tokenizer.Next(); if (token.IsComma) { token = tokenizer.Next(); continue; } else if (token.IsRightCurlyBrace) break; else throw new TsonParseException(token, "Expected a '}'"); } return node; }
private TsonNode ParseValue() { var token = tokenizer.Next(); if (!token.IsString) throw new TsonParseException(token, "Expected a string"); TsonStringNode stringNode = new TsonStringNode((string)token.Data) { Token = token }; // See if we can more strongly type the node if (stringNode.IsQuoted) return stringNode; if (stringNode.Value == "null") return new TsonNullNode() { Token = token }; if (stringNode.Value == "true") return new TsonBooleanNode(true) { Token = token }; if (stringNode.Value == "false") return new TsonBooleanNode(false) { Token = token }; double n; if (Double.TryParse(stringNode.Value, out n)) return new TsonNumberNode(n) { Token = token }; return stringNode; }
private TsonObjectNode ParseRootObject() { TsonToken token = tokenizer.Next(); bool hasLeftBrace = false; var node = new TsonObjectNode() { Token = token }; if (token.IsLeftCurlyBrace) { hasLeftBrace = true; token = tokenizer.Next(); if (token.IsRightCurlyBrace) return node; } else if (token.IsEnd) { return node; } while (true) { if (!token.IsString) throw new TsonParseException(token, "Expected a string"); TsonStringNode key = new TsonStringNode(token.Data as string) { Token = token }; token = tokenizer.Next(); if (!token.IsColon) throw new TsonParseException(token, "Expected a ':'"); TsonNode value = ParseValueArrayOrObject(); node.Add(key, value); token = tokenizer.Next(); if (token.IsComma) { token = tokenizer.Next(); continue; } else if (token.IsRightCurlyBrace) { if (!hasLeftBrace) throw new TsonParseException(token, "Root object did not have a '{' to match '}'"); break; } else if (token.IsEnd) { if (hasLeftBrace) throw new TsonParseException(token, "Expected '}'"); break; } else throw new TsonParseException(token, "Expected ',' or EOF" + (hasLeftBrace ? ", or '}'" : "")); } return node; }
protected override TsonNode VisitString(TsonStringNode node) { string s = node.Value.ToString() .Replace("\"", "\\\"") .Replace("\\", "\\\\") .Replace("/", "\\/") .Replace("\b", "\\b") .Replace("\f", "\\f") .Replace("\n", "\\n") .Replace("\r", "\\r") .Replace("\t", "\\t"); sb.AppendFormat("\"{0}\"", s); return node; }
public CompilerSetting(TsonStringNode name, TsonObjectNode parameters, List <ContentFileV4.CompilerExtension> extensions) { Name = name; Parameters = parameters; CompilerExtensions = extensions; }
protected override TsonNode VisitString(TsonStringNode node) { if (node.IsQuoted) sb.AppendFormat("\"{0}\"", node.Value.ToString()); else sb.Append(node.Value.ToString()); return node; }
protected override TsonNode VisitString(TsonStringNode node) { string s = node.Value.ToString() .Replace("\"", """) .Replace("'", "'") .Replace("&", "&") .Replace("<", "<") .Replace(">", ">") .Replace("\b", "") .Replace("\f", "") .Replace("\n", "
") .Replace("\r", "
") .Replace("\t", "	"); sb.AppendFormat("\"{0}\"", s); return node; }
protected override TsonNode VisitString(TsonStringNode node) { action(node); return node; }
protected virtual TsonNode VisitString(TsonStringNode node) { return node; }