User: xtoff
Date: 2009/12/14 03:49 PM
Modified:
/InversionOfControl/trunk/src/Castle.MicroKernel/Context/
CreationContext.cs
/InversionOfControl/trunk/src/Castle.MicroKernel/Handlers/
AbstractHandler.cs
/InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Configuration/
DefaultConfigurationStore.cs
/InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Conversion/
DefaultConversionManager.cs
/InversionOfControl/trunk/src/Castle.Windsor/Configuration/Interpreters/XmlProcessor/
DefaultXmlProcessorEngine.cs
Log:
- applied patch from Simon Cropp (with changes) fixing IOC-ISSUE-171 - Remove
usages of HybridDictionary for silverlight support
File Changes:
Directory:
/InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Configuration/
=====================================================================================
File [modified]: DefaultConfigurationStore.cs
Delta lines: +1 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Conversion/DefaultConversionManager.cs
2009-12-14 22:41:59 UTC (rev 6422)
+++
InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Conversion/DefaultConversionManager.cs
2009-12-14 22:49:36 UTC (rev 6423)
@@ -17,6 +17,7 @@
using System;
using System.Collections;
using System.Threading;
+
using Castle.Core;
using Castle.Core.Configuration;
Directory: /InversionOfControl/trunk/src/Castle.MicroKernel/Context/
====================================================================
File [modified]: CreationContext.cs
Delta lines: +3 -3
===================================================================
--- InversionOfControl/trunk/src/Castle.MicroKernel/Handlers/AbstractHandler.cs
2009-12-14 22:41:59 UTC (rev 6422)
+++ InversionOfControl/trunk/src/Castle.MicroKernel/Handlers/AbstractHandler.cs
2009-12-14 22:49:36 UTC (rev 6423)
@@ -17,9 +17,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
- using System.Collections.Specialized;
using System.Diagnostics;
using System.Text;
+
using Castle.Core;
using Castle.MicroKernel.Lifestyle;
@@ -161,7 +161,7 @@
{
if (customParameters == null)
{
- customParameters = new HybridDictionary(true);
+ customParameters = new
Dictionary<string,object>(StringComparer.InvariantCultureIgnoreCase);
}
customParameters[key] = value;
@@ -696,7 +696,7 @@
private void InitializeCustomDependencies()
{
- customParameters = new HybridDictionary(true);
+ customParameters = new
Dictionary<string,object>(StringComparer.InvariantCultureIgnoreCase);
foreach (DictionaryEntry customParameter in
model.CustomDependencies)
Directory:
/InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Conversion/
==================================================================================
File [modified]: DefaultConversionManager.cs
Delta lines: +52 -35
===================================================================
---
InversionOfControl/trunk/src/Castle.Windsor/Configuration/Interpreters/XmlProcessor/DefaultXmlProcessorEngine.cs
2009-12-14 22:41:59 UTC (rev 6422)
+++
InversionOfControl/trunk/src/Castle.Windsor/Configuration/Interpreters/XmlProcessor/DefaultXmlProcessorEngine.cs
2009-12-14 22:49:36 UTC (rev 6423)
@@ -15,25 +15,24 @@
namespace Castle.Windsor.Configuration.Interpreters.XmlProcessor
{
using System;
- using System.Collections;
- using System.Collections.Specialized;
+ using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Xml;
+ using Castle.Core.Resource;
using Castle.MicroKernel.SubSystems.Resource;
- using Castle.Core.Resource;
+ using
Castle.Windsor.Configuration.Interpreters.XmlProcessor.ElementProcessors;
- using ElementProcessors;
-
public class DefaultXmlProcessorEngine : IXmlProcessorEngine
{
private readonly Regex flagPattern = new Regex(@"^(\w|_)+$");
- private readonly IDictionary properties = new
HybridDictionary();
- private readonly IDictionary flags = new HybridDictionary();
- private readonly Stack resourceStack = new Stack();
- private readonly Hashtable nodeProcessors = new Hashtable();
+ private readonly IDictionary<string, XmlElement> properties =
new Dictionary<string, XmlElement>();
+ private readonly IDictionary<string, bool> flags = new
Dictionary<string, bool>();
+ private readonly Stack<IResource> resourceStack = new
Stack<IResource>();
+ private readonly IDictionary<XmlNodeType, IDictionary<string,
IXmlNodeProcessor>> nodeProcessors =
+ new Dictionary<XmlNodeType, IDictionary<string,
IXmlNodeProcessor>>();
private readonly IXmlNodeProcessor defaultElementProcessor;
- private IResourceSubSystem resourceSubSystem;
+ private readonly IResourceSubSystem resourceSubSystem;
/// <summary>
/// Initializes a new instance of the <see
cref="DefaultXmlProcessorEngine"/> class.
@@ -59,7 +58,7 @@
{
if (typeof(IXmlNodeProcessor).IsAssignableFrom(type))
{
- IXmlNodeProcessor processor =
Activator.CreateInstance(type) as IXmlNodeProcessor;
+ var processor = Activator.CreateInstance(type)
as IXmlNodeProcessor;
foreach(XmlNodeType nodeType in
processor.AcceptNodeTypes)
{
@@ -102,20 +101,19 @@
private IXmlNodeProcessor GetProcessor(XmlNode node)
{
- IXmlNodeProcessor processor = null;
- IDictionary processors = nodeProcessors[node.NodeType]
as IDictionary;
+ IDictionary<string, IXmlNodeProcessor> processors;
+ if (!nodeProcessors.TryGetValue(node.NodeType, out
processors))
+ {
+ return null;
+ }
- if (processors != null)
+ // sometimes nodes with the same name will not accept a
processor
+ IXmlNodeProcessor processor;
+ if (!processors.TryGetValue(node.Name, out processor)
|| !processor.Accept(node))
{
- processor = processors[node.Name] as
IXmlNodeProcessor;
-
- // sometimes nodes with the same name will not
accept a processor
- if (processor == null ||
!processor.Accept(node))
+ if (node.NodeType == XmlNodeType.Element)
{
- if (node.NodeType ==
XmlNodeType.Element)
- {
- processor =
defaultElementProcessor;
- }
+ processor = defaultElementProcessor;
}
}
@@ -124,23 +122,24 @@
private void RegisterProcessor(XmlNodeType type,
IXmlNodeProcessor processor)
{
- if (!nodeProcessors.Contains(type))
+ IDictionary<string, IXmlNodeProcessor> typeProcessors;
+ if (!nodeProcessors.TryGetValue(type,out
typeProcessors))
{
- nodeProcessors[type] = new Hashtable();
+ typeProcessors = new Dictionary<string,
IXmlNodeProcessor>();
+ nodeProcessors[type] = typeProcessors;
}
- IDictionary typeProcessors =
(IDictionary)nodeProcessors[type];
-
- if (typeProcessors.Contains(processor.Name))
+ if (typeProcessors.ContainsKey(processor.Name))
{
throw new XmlProcessorException("There is
already a processor register for {0} with name {1} ", type, processor.Name);
}
+
typeProcessors.Add(processor.Name, processor);
}
public bool HasFlag(string flag)
{
- return flags.Contains(GetCanonicalFlagName(flag));
+ return flags.ContainsKey(GetCanonicalFlagName(flag));
}
public void AddFlag(string flag)
@@ -170,19 +169,33 @@
public IResource GetResource(String uri)
{
- IResource resource = resourceStack.Count > 0 ?
resourceStack.Peek() as IResource : null;
+ IResource resource;
+ if (resourceStack.Count > 0)
+ {
+ resource = resourceStack.Peek();
+ }
+ else
+ {
+ resource = null;
+ }
if (uri.IndexOf(Uri.SchemeDelimiter) != -1)
{
- return resource == null ?
resourceSubSystem.CreateResource(uri) :
- resourceSubSystem.CreateResource(uri,
resource.FileBasePath);
+ if (resource == null)
+ {
+ return
resourceSubSystem.CreateResource(uri);
+ }
+
+ return resourceSubSystem.CreateResource(uri,
resource.FileBasePath);
}
+
+ // NOTE: what if resource is null at this point?
if (resourceStack.Count > 0)
{
return resource.CreateRelative(uri);
}
- throw new XmlProcessorException("Cannot get relative
resource '" + uri + "', resource stack is empty");
+ throw new XmlProcessorException("Cannot get relative
resource '" + uri + "', resource stack is empty");
}
public void AddProperty(XmlElement content)
@@ -192,14 +205,18 @@
public bool HasProperty(String name)
{
- return properties.Contains(name);
+ return properties.ContainsKey(name);
}
public XmlElement GetProperty(string key)
{
- XmlElement prop = properties[key] as XmlElement;
+ XmlElement property;
+ if (!properties.TryGetValue(key, out property))
+ {
+ return null;
+ }
- return prop == null ? null : prop.CloneNode(true) as
XmlElement;
+ return property.CloneNode(true) as XmlElement;
}
Directory: /InversionOfControl/trunk/src/Castle.MicroKernel/Handlers/
=====================================================================
File [modified]: AbstractHandler.cs
Delta lines: +22 -24
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Configuration/DefaultConfigurationStore.cs
2009-12-14 22:41:59 UTC (rev 6422)
+++
InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Configuration/DefaultConfigurationStore.cs
2009-12-14 22:49:36 UTC (rev 6423)
@@ -15,8 +15,8 @@
namespace Castle.MicroKernel.SubSystems.Configuration
{
using System;
- using System.Collections;
- using System.Collections.Specialized;
+ using System.Collections.Generic;
+ using System.Linq;
using System.Runtime.CompilerServices;
using Castle.Core.Configuration;
@@ -32,14 +32,10 @@
[Serializable]
public class DefaultConfigurationStore : AbstractSubSystem,
IConfigurationStore
{
- private readonly IDictionary childContainers = new
HybridDictionary();
- private readonly IDictionary facilities = new
HybridDictionary();
- private readonly IDictionary components = new
HybridDictionary();
- private readonly IDictionary bootstrapcomponents = new
HybridDictionary();
- private readonly ArrayList childContainersList = new
ArrayList();
- private readonly ArrayList facilitiesList = new ArrayList();
- private readonly ArrayList componentsList = new ArrayList();
- private readonly ArrayList bootstrapComponentsList = new
ArrayList();
+ private readonly IDictionary<string, IConfiguration>
childContainers = new Dictionary<string, IConfiguration>();
+ private readonly IDictionary<string, IConfiguration> facilities
= new Dictionary<string, IConfiguration>();
+ private readonly IDictionary<string, IConfiguration> components
= new Dictionary<string, IConfiguration>();
+ private readonly IDictionary<string, IConfiguration>
bootstrapcomponents = new Dictionary<string, IConfiguration>();
/// <summary>
/// Initializes a new instance of the <see
cref="DefaultConfigurationStore"/> class.
@@ -56,8 +52,6 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public void AddFacilityConfiguration(String key, IConfiguration
config)
{
- facilitiesList.Add(config);
-
facilities[key] = config;
}
@@ -69,8 +63,6 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public void AddComponentConfiguration(String key,
IConfiguration config)
{
- componentsList.Add(config);
-
components[key] = config;
}
@@ -91,8 +83,6 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public void AddChildContainerConfiguration(String key,
IConfiguration config)
{
- childContainersList.Add(config);
-
childContainers[key] = config;
}
@@ -106,7 +96,9 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public IConfiguration GetFacilityConfiguration(String key)
{
- return facilities[key] as IConfiguration;
+ IConfiguration value;
+ facilities.TryGetValue(key, out value);
+ return value;
}
/// <summary>
@@ -119,7 +111,9 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public IConfiguration GetChildContainerConfiguration(String key)
{
- return childContainers[key] as IConfiguration;
+ IConfiguration value;
+ childContainers.TryGetValue(key, out value);
+ return value;
}
/// <summary>
@@ -132,7 +126,9 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public IConfiguration GetComponentConfiguration(String key)
{
- return components[key] as IConfiguration;
+ IConfiguration value;
+ components.TryGetValue(key, out value);
+ return value;
}
/// <summary>
@@ -145,7 +141,9 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public IConfiguration GetBootstrapComponentConfiguration(string
key)
{
- return bootstrapcomponents[key] as IConfiguration;
+ IConfiguration value;
+ bootstrapcomponents.TryGetValue(key, out value);
+ return value;
}
/// <summary>
@@ -155,7 +153,7 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public IConfiguration[] GetFacilities()
{
- return (IConfiguration[])
facilitiesList.ToArray(typeof(IConfiguration));
+ return facilities.Values.ToArray();
}
/// <summary>
@@ -165,7 +163,7 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public IConfiguration[] GetBootstrapComponents()
{
- return (IConfiguration[])
bootstrapComponentsList.ToArray(typeof(IConfiguration));
+ return bootstrapcomponents.Values.ToArray();
}
/// <summary>
@@ -175,7 +173,7 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public IConfiguration[] GetConfigurationForChildContainers()
{
- return (IConfiguration[])
childContainersList.ToArray(typeof(IConfiguration));
+ return childContainers.Values.ToArray();
}
/// <summary>
@@ -185,7 +183,7 @@
[MethodImpl(MethodImplOptions.Synchronized)]
public IConfiguration[] GetComponents()
{
- return (IConfiguration[])
componentsList.ToArray(typeof(IConfiguration));
+ return components.Values.ToArray();
}
Directory:
/InversionOfControl/trunk/src/Castle.Windsor/Configuration/Interpreters/XmlProcessor/
================================================================================================
File [modified]: DefaultXmlProcessorEngine.cs
Delta lines: +0 -0
===================================================================
--
You received this message because you are subscribed to the Google Groups
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-commits?hl=en.