ExtendedPropertiesDescriptor
using Castle.Core;
using Castle.Core.Internal;
using Castle.MicroKernel.Registration;
using System;
using System.Collections;
namespace Castle.MicroKernel.ModelBuilder.Descriptors
{
public class ExtendedPropertiesDescriptor : IComponentModelDescriptor
{
private readonly IDictionary dictionary;
private readonly Property[] properties;
public ExtendedPropertiesDescriptor(params Property[] properties)
{
this.properties = properties;
}
public ExtendedPropertiesDescriptor(IDictionary dictionary)
{
this.dictionary = dictionary;
}
public void BuildComponentModel(IKernel kernel, ComponentModel model)
{
}
public void ConfigureComponentModel(IKernel kernel, ComponentModel model)
{
if (dictionary != null) {
IDictionaryEnumerator enumerator = dictionary.GetEnumerator();
try {
while (enumerator.MoveNext()) {
DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator.Current;
model.ExtendedProperties[dictionaryEntry.Key] = dictionaryEntry.Value;
}
} finally {
(enumerator as IDisposable)?.Dispose();
}
}
if (properties != null)
properties.ForEach(delegate(Property p) {
model.ExtendedProperties[p.Key] = p.Value;
});
}
}
}