/// <summary> /// Extracts the corresponding value from the SemWeb results for a member access projection. /// </summary> /// <param name="vb">The SemWeb results.</param> /// <returns>the value that was extracted (and converted) from the results.</returns> private object ExtractMemberAccess(SparqlResult vb) { // work out if the SelectExpression really is a member access var ue = (SelectExpression).Arguments[1] as UnaryExpression; if (ue == null) { throw new ArgumentException("incompatible expression type"); } var le = ue.Operand as LambdaExpression; if (le == null) { throw new LinqToRdfException("Incompatible expression type found when building ontology projection"); } if (le.Body is MemberExpression) { // work out which member is being queried on var memberExpression = (MemberExpression)le.Body; MemberInfo memberInfo = memberExpression.Member; // get its name and use that as a key into the results //string vVal = vb[memberInfo.Name].ToString(); // convert the result from XSDT format to .NET types if (!vb.HasValue(memberInfo.Name)) { return(null); } var tc = new XsdtTypeConverter(); return(tc.Parse(vb[memberInfo.Name])); //return tc.Parse(vVal); } return(null); }
/// <summary> /// stores the result from a SemWeb result into a <see cref="PropertyInfo"/> doing whatever conversions are required. /// </summary> /// <param name="semwebBindings">The incoming result from semweb.</param> /// <param name="obj">The object instance on wqhich the property is to be set</param> /// <param name="propertyInfo">The <see cref="PropertyInfo"/> identifying the property to be populated with the value stored in <see cref="semwebBindings"/>.</param> public static void PopulateProperty(SparqlResult semwebBindings, object obj, PropertyInfo propertyInfo) { if (semwebBindings.HasValue(propertyInfo.Name)) { if (semwebBindings[propertyInfo.Name] == null) { return; } var tc = new XsdtTypeConverter(); object x = tc.Parse(semwebBindings[propertyInfo.Name]); if (x is IConvertible) { propertyInfo.SetValue(obj, Convert.ChangeType(x, propertyInfo.PropertyType), null); } else // if it's not convertible, it could be because the type is an MS XSDT type rather than a .NET primitive if (x.GetType().Namespace == "System.Runtime.Remoting.Metadata.W3cXsd2001") { switch (x.GetType().Name) { case "SoapDate": var d = (SoapDate)x; propertyInfo.SetValue(obj, Convert.ChangeType(d.Value, propertyInfo.PropertyType), null); break; default: break; } } else if (propertyInfo.PropertyType == typeof(string)) { propertyInfo.SetValue(obj, x.ToString(), null); } } }
/// <summary> /// Initializes a new instance of the <see cref="QueryFactory{T}"/> class. /// </summary> /// <param name="queryType">the <see cref="LinqToRdf.QueryType"/> of the query.</param> /// <param name="context">The <see cref="IRdfContext"/> data context that will track results, connections and instances.</param> public QueryFactory(LinqQueryMethod queryType, IRdfContext context) { QueryType = queryType; DataContext = context; TypeTranslator = new XsdtTypeConverter(); }