【发布时间】:2016-04-11 22:31:55
【问题描述】:
我正在从 XML 反序列化并遇到类冲突问题。
例如
在我的代码中,我将引用实际存在于Microsoft.SharePoint.Client.ContentType 中的ContentType 类或存在于Microsoft.SharePoint.Client.Web 中的Web 类。
例如
var parentCtType = (from c in rootWeb.ContentTypes
where c.Name.ToLower().Trim() == ctParent.ToLower().Trim()
select c).FirstOrDefault();
在我的 XML 中是这样写的:
<ContentTypes>
<ContentType Name="D Base Document Set" Parent="Document Set" Group="*D">
<ContentTypeSiteColumns>
<Sitecolumn DisplayName="Security" StaticName="SecurityClassification" Group="*DIAColumn" Type="TaxonomyFieldType" TermStore="D" TermSet="Security Classification" DefaultValue="UNCLASSIFIED" Required="TRUE" />
<Sitecolumn DisplayName="Enterprise" StaticName="Tax" Group="Enterprise Keywords Group" Type="TaxonomyFieldTypeMulti" TermStore="D" TermSet="N/A" />
</ContentTypeSiteColumns>
</ContentType>
<ContentType Name="D Base Document" Parent="Document" Description="The content type from which all other document content types will inherit." Group="*D">
<ContentTypeSiteColumns>
<Sitecolumn DisplayName="Security Classification" StaticName="SecurityClassification" Group="*D" Type="TaxonomyFieldType" TermStore="D" TermSet="Security" DefaultValue="UNCLASSIFIED" Required="TRUE" />
<Sitecolumn DisplayName="Enterprise" StaticName="Tax" Group="Enterprise" Type="TaxonomyFieldTypeMulti" TermStore="D" TermSet="N/A" />
<Sitecolumn DisplayName="Notes" StaticName="Notess" Description="For notes giving context to the document. Additional information can include URL link to another document." Group="*D" Type="Note" Required="FALSE" />
</ContentTypeSiteColumns>
</ContentType>
在我要反序列化的类中,我有一个名为 ContentType 和 Web 的类(很确定它已命名为 this,因为我使用该名称的元素从该 XML 反序列化)。
public class ContentType
{
[XmlAttribute]
public string Name;
[XmlAttribute]
public string Parent;
public List<Sitecolumn> ContentTypeSiteColumns;
}
所以上面的这个类必须被称为 ContentType(?) 因为这是我从 XML 反序列化到的。
我得到的错误是这样的:
Error 4 'testebby.ContentType' does not contain a definition for 'FieldLinks' and no extension method 'FieldLinks' accepting a first argument of type 'testebby.ContentType' could be found (are you missing a using directive or an assembly reference?)
如果我将要反序列化的类调用为不同的东西,例如 ContentTypeZ,但反序列化过程不起作用。
我该如何解决这个问题?希望有道理。
【问题讨论】:
标签: c# .net xml serialization