我会尝试解释这个问题:
1-从服务器端,我得到了一个名为Document的类,它从类Node扩展(几个类从Node扩展)。
2-从rest API,我得到了一个服务,它发送作为响应Node对象(Document或其他从Node扩展的内容)。休息输出真的是发送所有信息(文档等...)。
3-当到达休息客户端时,我得到Node类(没问题,直到这里一切顺利)。
if (node.GetType() == typeof(Document))
{
// never goes into
var doc = (Document)node;
}
if (node is Document)
{
// never goes into
var doc = (Document)node;
}
4-当我查找Node是Document的类型时,问题就出现了,答案总是错误的。
在有人回答我之前是不可能的(我对java和php完全一样没有问题)。我没有找到密钥(在java中,例如那里有一些注释对它有帮助@XmlSeeAlso({Document.class,Folder.class,Record.class,Mail.class}))。
我不知道是否可以使用restcharp执行此操作,或者我必须继续执行更低级别的实现。任何线索或帮助都表示赞赏。
这里有一些代码:
// Query result List
public class QueryResultList
{
public List<QueryResult> queryResults { get; set; }
}
// Query Result
public class QueryResult
{
public Node node { get; set; }
}
// Class Node
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Xml.Serialization;
namespace com.openkm.sdk4csharp.bean
{
public class Node
{
private static long serialVersionUID = 1L;
public static String AUTHOR = "okm:author";
public static String NAME = "okm:name";
public DateTime created { get; set; }
public String path { get; set; }
public String author { get; set; }
public int permissions { get; set; }
public String uuid { get; set; }
public bool subscribed { get; set; }
public long nodeClass { get; set; }
public List<String> subscriptors { get; set; }
public List<String> keywords { get; set; }
public List<Folder> categories { get; set; }
public List<Note> notes { get; set; }
//public String linkTarget { get; set; }
//public Version actualVersion { get; set; }
//public Boolean promotedAsRecord { get; set; }
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append("path=").Append(path);
sb.Append(", permissions=").Append(permissions);
sb.Append(", created=").Append(created == null ? null : created.GetDateTimeFormats());
sb.Append(", subscribed=").Append(subscribed);
sb.Append(", nodeClass=").Append(nodeClass);
sb.Append(", subscriptors=").Append(subscriptors);
sb.Append(", uuid=").Append(uuid);
sb.Append(", keywords=").Append(keywords);
sb.Append(", categories=").Append(categories);
sb.Append(", notes=").Append(notes);
// sb.Append(", linkTarget=").Append(linkTarget);
//sb.Append(", actualVersion=").Append(actualVersion);
//sb.Append(", promotedAsRecord=").Append(promotedAsRecord);
sb.Append("}");
return sb.ToString();
}
}
}
// Class Document
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace com.openkm.sdk4csharp.bean
{
public class Document:Node
{
private static long serialVersionUID = 1L;
public static String TYPE = "okm:document";
public static String CONTENT = "okm:content";
public static String CONTENT_TYPE = "okm:resource";
public static String SIZE = "okm:size";
public static String LANGUAGE = "okm:language";
public static String VERSION_COMMENT = "okm:versionComment";
public static String NAME = "okm:name";
public static String TEXT = "okm:text";
public static String TITLE = "okm:title";
public static String DESCRIPTION = "okm:description";
public String title { get; set; }
public String description { get; set; }
public String language { get; set; }
public DateTime lastModified { get; set; }
public String mimeType { get; set; }
public Boolean locked { get; set; }
public Boolean checkedOut { get; set; }
public Version actualVersion { get; set; }
public LockInfo lockInfo { get; set; }
public Boolean signed { get; set; }
public Boolean convertibleToPdf { get; set; }
public Boolean convertibleToSwf { get; set; }
public Boolean convertibleToDxf { get; set; }
public String cipherName { get; set; }
//public String annotations { get; set; }
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append("path=").Append(path);
sb.Append(", title=").Append(title);
sb.Append(", description=").Append(description);
sb.Append(", mimeType=").Append(mimeType);
sb.Append(", author=").Append(author);
sb.Append(", permissions=").Append(permissions);
sb.Append(", created=").Append(created == null ? null : created.GetDateTimeFormats());
sb.Append(", lastModified=").Append(lastModified == null ? null : lastModified.GetDateTimeFormats());
sb.Append(", keywords=").Append(keywords);
sb.Append(", categories=").Append(categories);
sb.Append(", locked=").Append(locked);
sb.Append(", lockInfo=").Append(lockInfo);
sb.Append(", subscribed=").Append(subscribed);
sb.Append(", subscriptors=").Append(subscriptors);
sb.Append(", uuid=").Append(uuid);
sb.Append(", convertibleToPdf=").Append(convertibleToPdf);
sb.Append(", convertibleToSwf=").Append(convertibleToSwf);
sb.Append(", convertibleToDxf=").Append(convertibleToDxf);
sb.Append(", cipherName=").Append(cipherName);
sb.Append(", notes=").Append(notes);
//sb.Append(", annotations=").Append(annotations);
sb.Append("}");
return sb.ToString();
}
}
}
QueryResultList ret = new QueryResultList();
IRestRequest request = new RestRequest(uriHelper.SEARCH_FIND_BY_CONTENT, Method.GET);
request.RequestFormat = DataFormat.Xml;
request.AddParameter("content", content, ParameterType.QueryString);
IRestClient client = getClient(url, user, password);
IRestResponse<QueryResultList> response = client.Execute<QueryResultList>(request);
// here when I iterate results -> node and try to cast to Document fails
...