I've been trying to understand what is wrong with my animation and I still haven't figure it out. I think it should be really straight forward, but there is probably something I'm missing, even after reading lot of examples and documentation.
My problem comes originally form the fact that on the iPhone, you cannot resize layers automatically (with the view). The documentation says otherwise but there is no autoresizeMask for the layer in the SDKs. So I decided to make …
我正在寻找谁来定制属性的序列化.我觉得这很简单,但我无法达到我想要的方式.
所以这是一个简单的例子:
类定义:
Class MyClass
{
[XmlAttribute("myAttribute")]
public int[] MyProperty { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想要的Xml结果:
<MyClass myAttribute="1 2 3... N" />
Run Code Online (Sandbox Code Playgroud)
我做的唯一工作就是放置[XmlIgnore]属性并使用一些执行转换的代码创建另一个属性.
所以,我的问题是,有没有比创建新房产更好的方法?也许你可以创建某种类型的TypeConverter,这样串行器就可以使用它?
另外,我尝试使用Type属性但没有成功.(总是得到例外).但是从我读过的内容来看,它已经定义了数据类型.
[XmlAttribute("myAttribute", typeof(MyConverter))]
public int[] MyProperty { get; set; }
Run Code Online (Sandbox Code Playgroud)
另一个有趣的方式是这样的:
[XmlAttribute("myAttribute")]
[XmlConverter(typeof(MyConverter))]
public int[] MyProperty { get; set; }
Run Code Online (Sandbox Code Playgroud)
谢谢.
编辑由于没有提供像我一样的解决方案,我最终决定选择"IXmlSerializable"解决方案.
我一直试图找到一种使用 XmlReader/XmlWriter 编写 XML 的简单方法。我真的不喜欢使用接口“IXmlSerializable”,但我对我的某些数据类别无选择。
无论如何,我想做的很简单:
private MyClass myObject;
public void WriteXml(XmlWriter writer)
{
writer.WriteObject(myObject); // <-- this method doesn't exists
}
Run Code Online (Sandbox Code Playgroud)
所以,我找到了 2 个解决方法:
我还没有测试第二个,但我认为它可能会起作用(不确定,因为 ReadValue 结果)。
那么我的问题是:我错过了什么重要的东西还是唯一的方法?或者有没有更好的方法来处理?
谢谢。