私は、WPFのDependencyPropertyおよびDependencyObjectシステムと同様の設定をしています。私の特性は一般的です。 BucketPropertyには、すべてのBucketPropertiesを追跡する静的なGlobalIndex(BucketPropertyBaseで定義)があります。バケットには、どのタイプのBucketPropertiesもたくさん持つことができます。バケットは、これらのBucketPropertiesの実際の値を保存して取得します...今、私の質問は、これらの値の格納に対処する方法と、それらを取得するときに型キャストを使用するペナルティは何ですか?私は現在、単純なオブジェクトとしてプロパティ値を保存するBucketEntriesの配列を使用しています。これらの値を保存して返す良い方法はありますか?一般的な値を格納するときのC#のtypecastingとboxing/unboxingのパフォーマンスのペナルティ
は下にsimpliefiedバージョンです:
public class BucketProperty<T> : BucketPropertyBase
{
}
public class Bucket
{
private BucketEntry[] _bucketEntries;
public void SaveValue<T>(BucketProperty<T> property, T value)
{
SaveBucketEntry(property.GlobalIndex, value)
}
public T GetValue<T>(BucketProperty<T> property)
{
return (T)FindBucketEntry(property.GlobalIndex).Value;
}
}
public class BucketEntry
{
private object _value;
private uint _index;
public BucketEntry(uint globalIndex, object value)
{
...
}
}