коробка с размером, определенным переполнением только частично

IMO, невозможно создать желаемый XML с помощью Serialization. Но вы можете использовать LINQ to XML для генерации желаемой схемы, например:

XDocument xDocument = new XDocument();
XElement rootNode = new XElement(typeof(Notes).Name);
foreach (var property in typeof(Notes).GetProperties())
{
   if (property.GetValue(a, null) == null)
   {
       property.SetValue(a, string.Empty, null);
   }
   XElement childNode = new XElement(property.Name, property.GetValue(a, null));
   rootNode.Add(childNode);
}
xDocument.Add(rootNode);
XmlWriterSettings xws = new XmlWriterSettings() { Indent=true };
using (XmlWriter writer = XmlWriter.Create("D:\\Sample.xml", xws))
{
    xDocument.Save(writer);
}

Основной улов in case your value is null, you should set it to empty string. Это будет force the closing tag to be generated. В случае, если значение равно нулю, закрывающий тег не создается.

3
задан Sylvain Attoumani 17 January 2019 в 11:24
поделиться

2 ответа

Если вы можете использовать Javascript ... Используйте решение @Temani Afif, если не можете

Array.from(document.querySelectorAll('.optionnal')).forEach(el => {
  // If the text of "Optionnal" is greater than 84, then ellipse it...
  el.innerText = el.innerText.length > 84 ? el.innerText.slice(0, 84) + '...' : el.innerText
})
.title {
  width : 250px;
  height : 70px;
  overflow : show;
  border : 1px solid black;
}
.stay {
  color : red;
}
<h3 class="title">
  <span class="optionnal" >This is a test</span>
  <span  class="stay"> I MUST STAY</span>
</h3>
<h3 class="title">
  <span class="optionnal">This is a test This is a test This is a test This is a testThis is a test This is a testThis is a test This is a testThis is a test This is a testThis is a test This is a testThis is a test This is a testThis is a test This is a test</span>
  <span class="stay"> I MUST STAY</span>
</h3>
<h3 class="title">
  <span class="optionnal">This is a test This is a test This is a test This is a testThis is a test This is a...</span>
  <span class="stay"> I MUST STAY</span>
</h3>

0
ответ дан Hammerbot 17 January 2019 в 11:24
поделиться

Вот хакерская идея , где вам нужно дублировать текст. Хитрость заключается в том, чтобы всегда располагать текст в правом нижнем углу контейнера, тогда у другого текста будут псевдоэлементы, создающие наложение, которое будет скрывать его, поэтому мы будем видеть позиционированный текст, только когда этот текст находится вне контейнера.

Чтобы лучше видеть фокус, измените белый цвет, чтобы понять, как наложение только скрывает позиционированный текст.

Текст «должен остаться» должен занимать одну строку, а 3 точки размещаются вручную в зависимости от длины текста

.title {
  width: 250px;
  height: 70px;
  overflow: hidden;
  position: relative;
  border: 1px solid black;
  display:inline-block;
  vertical-align:top;
  margin:5px 0;
}

.title::before {
  content: attr(data-text);
  position: absolute;
  bottom: 3px;
  right: 13px;
  color: red;
  background: #fff;
}
.title::after {
  content: '... ';
  position: absolute;
  bottom: 3px;
  right: 130px;
  color: #000;
  background: #fff;
  padding: 0 3px;
}

.stay {
  color: red;
  position: relative;
  z-index:1;
  background: #fff;
  display:inline-block;
}

.stay::before {
  content: "";
  position: absolute;
  z-index:1;
  top: 100%;
  height: 100vh;
  left: -50vw;
  right: -50vw;
  background: #fff;
}

.stay::after {
  content: "";
  position: absolute;
  z-index:1;
  left: 100%;
  width: 100vw;
  top:0;
  bottom: -50vh;
  background: #fff;
}
[111 ]

0
ответ дан Temani Afif 17 January 2019 в 11:24
поделиться