コード例 #1
0
 public NumberFormatAttribute(SchemaNumberType numberType)
 {
     this.NumberType = numberType;
 }
コード例 #2
0
ファイル: Schema.cs プロジェクト: Tkachov/sdf
        /// <summary>
        ///     Create new SDF Schema from given SDF representation.
        /// </summary>
        /// <param name="schema">SDF representation of a schema.</param>
        public Schema(SDF schema)
        {
            var n = schema as Node;

            if (n == null || !n.Name.Equals("schema"))
            {
                throw new InvalidDataException("Schema must be a (schema) node.");
            }

            // built-ins
            _builtinTypes["node"]    = new SchemaSimpleNodeType();
            _builtinTypes["string"]  = new SchemaStringType();
            _builtinTypes["boolean"] = _builtinTypes["bool"] = new SchemaBooleanType();
            _builtinTypes["number"]  = new SchemaNumberType();
            _builtinTypes["null"]    = new SchemaNullType();

            _topElement = MakeElement(n.Attributes["top-element"]);

            // read user-defined types
            foreach (var type in n.Children)
            {
                var t  = MakeType(type);
                var nt = t as SchemaNodeType;
                if (nt != null)
                {
                    _types[nt.Name] = nt;
                }
                else
                {
                    var lt = t as SchemaLiteralType;
                    if (lt != null)
                    {
                        _types[lt.Name] = lt;
                    }
                    else
                    {
                        throw new InvalidDataException("User-defined type must be either node-type or literal-type.");
                    }
                }
            }

            // add built-ins
            foreach (var schemaBuiltinType in _builtinTypes)
            {
                _types[schemaBuiltinType.Key] = schemaBuiltinType.Value;
            }

            // verify all types have a description
            VerifyElement(_topElement);
            foreach (var schemaType in _types)
            {
                if (schemaType.Value is SchemaBuiltinType)
                {
                    continue;
                }

                if (schemaType.Value is SchemaLiteralType)
                {
                    continue;                     // can only reference a built-in
                }

                var t = schemaType.Value as SchemaNodeType;
                VerifyElement(t.Children);
                foreach (var attribute in t.Attributes)
                {
                    VerifyElement(attribute.Element);
                }
            }

            ErrorMessage = null;
        }