ISet没有被序列化C#

时间:2017-09-25 16:17:43

标签: c# c#-4.0

我有一个类,在它的顶部我设置了标志[Audit],然后允许将对象的内容写出到文本以供审计。但是,此类的一个属性是ISet Some类,并且此对象的内容未被写出。它不会引发错误。

[Audit]设置如下,我只是想知道是否需要在这里调整其他东西,或者不能写出ISet内容:

   [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, Inherited = true]
   public sealed class Audit:Attribute
   {}

Attribute是System Namespace中的类。

1 个答案:

答案 0 :(得分:1)

序列化和var acc = document.getElementsByClassName("js-collapse"); var i; for (i = 0; i < acc.length; i++) { acc[i].onclick = function() { this.classList.toggle("active"); var panel = this.nextElementSibling; if (panel.style.maxHeight){ panel.style.maxHeight = null; } else { panel.style.maxHeight = panel.scrollHeight + "px"; } } }

存在已知问题

如果查看CollectionDataContractCriticalHelper()的代码,您会看到以下内容

@import url('https://fonts.googleapis.com/icon?family=Material+Icons');

* {
	margin: 0;
	padding: 0;
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
}

.float-right {
  float: right;
}

.c-accordion.js-collapse.active .material-icons.float-right{
-webkit-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-o-transform: rotate(180deg);
transform: rotate(180deg);
transition: all .3s ease;
}

.c-menu {
  margin: 0;
  padding: 0;
  width: 300px;
  border-top: 1px solid #CBCBCB;
  border-left: 1px solid #CBCBCB;
  border-right: 1px solid #CBCBCB;
}
.c-accordion {
  list-style-type: none;
  background-color: #eee;
  color: #444;
  cursor: pointer;
  padding: 5px;
  width: 100%;
  border: none;
  border-bottom: 1px solid #CBCBCB;
  text-align: left;
  outline: none;
  font-size: 15px;
  transition: 0.4s;
}
ul.c-accordion.active, ul.c-accordion:hover {
  background-color: #ddd;
}
.c-submenu {
  list-style: none;
  margin: 0;
  padding: 0;
}
.c-submenu li {
  border-bottom: 1px solid #CBCBCB;
  padding: 5px;
  cursor: pointer;
}
.c-submenu li:hover {
  background-color: orange;
}
.c-panel {
  background-color: white;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
}

您会看到<ul class='c-menu'> <ul class="c-accordion">Section 1</ul> <ul class="c-accordion js-collapse">Section 2<i class="material-icons float-right">keyboard_arrow_down</i></ul> <ul class="c-submenu c-panel"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> </ul> <ul class="c-accordion">Section 3</ul> </ul>丢失。微软知道这个问题,但不打算在不久的将来修复它:

DataContractSerializer cannot serialize System.Collections.Generic.ISet even if it derives from IEnumerable