我想根据所有必需的信息创建AudioFormat
类的实例。如何实例具有只读属性的类
基本上,我有什么是
int
BitsPerSampleint
频道int
SamplesPerSecondWaveFormatType
WAVEFORMAT
的问题是,简单地使用类似
AudioFormat format = new AudioFormat();
format.BitsPerSample = BitsPerSample;
[...]
不起作用,因为Property or indexer 'System.Windows.Media.AudioFormat.BitsPerSample' cannot be assigned to -- it is read only
。
有没有简单的方法来创建这样一个对象?如果不是,我该怎么做才能创建它?使用继承,覆盖属性,以便他们有setter?创建对象的XML表示,然后反序列化它?使用其他一些丑陋的黑客(没有unsafe
:-))?
顺便说一句,这些是_properties_,而不是属性。 – SLaks 2011-04-17 19:15:00