开发者

Enumerate through a DictionaryAdapter passed to OnFlushDirty

开发者 https://www.devze.com 2023-03-19 02:50 出处:网络
I am attempting to use the OnFlushDirty method of a Castle.ActiveRecord object in order to implement generic auditing of changes:

I am attempting to use the OnFlushDirty method of a Castle.ActiveRecord object in order to implement generic auditing of changes:

protected override bool OnFlushDirty(object id, 
                                     IDictionary previousState, 
                                     IDictionary currentState, 
                                     NHibernate.Type.IType[] types
                                    )

On execution, OnFlushDirty is passed a Castle.ActiveRecord.Framework.DictionaryAdapter for each of the previousState and currentState parameters.

Unfortunately DictionaryAdapter开发者_JS百科 does not support the GetEnumerator() method, throwing a NotSupportedException.

  1. Should I be expecting a DictionaryAdapter to be passed into OnFlushDirty in the first place?; and
  2. Assuming I should, how can I enumerate through the Key/Value pairs within the DictionaryAdapter in order to compare previous and current states for auditing?


The DictionaryAdapter includes a Key collection which can be enumerated normally with the Key then being applied to retrieve its Value.

Sample solution code:

foreach (var entry in currentState.Keys)
{
    Console.WriteLine(currentState[entry]);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消