Пример #1
0
        internal void Parse(INode n, XsdtType x)
        {
            switch (n.NodeType)
            {
            case NodeType.Uri:
                x.NetType      = typeof(Uri);
                x.ValuePart    = n.ToString();
                x.XsdtTypeName = XsdtPrimitiveDataType.XsdtAnyUri;
                ConvertValueToNet(x);
                break;

            case NodeType.Literal:
                ILiteralNode lit = (ILiteralNode)n;

                x.XsdtTypeName = XsdtPrimitiveDataType.XsdtUnknown;
                x.ValuePart    = lit.Value;

                if (lit.DataType != null)
                {
                    if (lit.DataType.ToString().StartsWith(NamespaceMapper.XMLSCHEMA))
                    {
                        x.TypePart = lit.DataType.ToString().Substring(NamespaceMapper.XMLSCHEMA.Length);
                    }
                    else
                    {
                        x.TypePart = "string";
                    }
                }
                else
                {
                    if (TurtleSpecsHelper.IsValidPlainLiteral(lit.Value))
                    {
                        if (TurtleSpecsHelper.IsValidInteger(lit.Value))
                        {
                            x.TypePart = "integer";
                        }
                        else if (TurtleSpecsHelper.IsValidDecimal(lit.Value))
                        {
                            x.TypePart = "decimal";
                        }
                        else if (TurtleSpecsHelper.IsValidDouble(lit.Value))
                        {
                            x.TypePart = "double";
                        }
                        else
                        {
                            x.TypePart = "boolean";
                        }
                    }
                    else
                    {
                        x.TypePart = "string";
                    }
                }

                foreach (int i in Enum.GetValues(typeof(XsdtPrimitiveDataType)))
                {
                    var           result = (XsdtPrimitiveDataType)i;
                    XsdtAttribute attr   = GetXsdtAttrFor(result);
                    if (attr.TypeUri == x.TypePart)
                    {
                        x.XsdtTypeName = result;
                    }
                }

                if (TypeLookup.ContainsKey(x.XsdtTypeName))
                {
                    x.NetType = TypeLookup[x.XsdtTypeName];
                }
                else
                {
                    throw new LinqToRdfException("XsdtTypeConverter does not know how to convert the XML Schema Datatype " + x.TypePart);
                }

                ConvertValueToNet(x);
                break;

            default:
                throw new LinqToRdfException("XsdtTypeConverter can only convert URI and Literal Nodes");
            }
        }
Пример #2
0
 public string GetXsdtDateRepresentationFor(DateTime d, XsdtPrimitiveDataType dt, XsdtAttribute attr)
 {
     // TODO: the time zone offset needs to be returned from somewhere...
     return(d.ToString("yyyy-MM-ddTHH:mm:sszzz"));
 }
Пример #3
0
 internal string GetStringRepresentationFor <T>(T obj, XsdtPrimitiveDataType dt, XsdtAttribute attr)
 {
     return(obj.ToString());
 }
Пример #4
0
        public object Get(Type t, object obj)
        {
            //PORT: Convert this just to use SparqlFormatter instead?

            string result              = "";
            XsdtPrimitiveDataType dt   = GetDataType(t);
            XsdtAttribute         attr = GetXsdtAttrFor(dt);

            //if (dt == XsdtPrimitiveDataType.XsdtUnknown)
            //{
            //    return this._formatter.Format(this._g.CreateLiteralNode(obj.ToString()));
            //}
            //else
            //{
            //    XsdtAttribute attr = GetXsdtAttrFor(dt);

            //}

            if (dt == XsdtPrimitiveDataType.XsdtUnknown)
            {
                if (t == typeof(char))
                {
                    return("\"" + obj + "\"");
                }
                else if (attr.IsQuoted)
                {
                    return("\"" + obj + "\"");
                }
                else
                {
                    return(obj.ToString());
                }
            }
            switch (t.FullName)
            {
            case "System.DateTime":
                result = GetXsdtDateRepresentationFor((DateTime)obj, dt, attr);
                break;

            case "System.Byte[]":
                result = Encoding.ASCII.GetString((Byte[])obj);
                break;

            default:
                result = GetStringRepresentationFor(obj, dt, attr);
                break;
            }

            if (attr.IsQuoted)
            {
                result = "\"" + result + "\"";
            }
            string xsdTypeSuffix;

            if (dt != XsdtPrimitiveDataType.XsdtInt && dt != XsdtPrimitiveDataType.XsdtString)
            {
                xsdTypeSuffix = "^^xsd:" + attr.TypeUri;
            }
            else
            {
                xsdTypeSuffix = "";
            }
            return(result + xsdTypeSuffix);
        }