public void CorrectSignatureMatches() { WindsorContainer container = new WindsorContainer("../Castle.Windsor.Tests/ModelBuilders/methodusage1.xml"); Assert.IsTrue(container.Kernel.HasComponent("comp1")); IHandler handler = container.Kernel.GetHandler("comp1"); ComponentModel model = handler.ComponentModel; Assert.IsNotNull(model.MethodMetaModels); Assert.AreEqual(3, model.MethodMetaModels.Count); Type target = typeof(Component1); MethodInfo method = target.GetMethod("Save", new Type[0]); Assert.IsTrue(model.MethodMetaModels.MethodInfo2Model.Contains(method)); MethodMetaModel metaModel = (MethodMetaModel)model.MethodMetaModels.MethodInfo2Model[method]; Assert.AreEqual("1", metaModel.ConfigNode.Attributes["myattribute"]); method = target.GetMethod("Save", new Type[] { typeof(String) }); Assert.IsTrue(model.MethodMetaModels.MethodInfo2Model.Contains(method)); metaModel = (MethodMetaModel)model.MethodMetaModels.MethodInfo2Model[method]; Assert.AreEqual("2", metaModel.ConfigNode.Attributes["myattribute"]); method = target.GetMethod("Save", new Type[] { typeof(String), typeof(String) }); Assert.IsTrue(model.MethodMetaModels.MethodInfo2Model.Contains(method)); metaModel = (MethodMetaModel)model.MethodMetaModels.MethodInfo2Model[method]; Assert.AreEqual("3", metaModel.ConfigNode.Attributes["myattribute"]); }
private void RegisterMethodsForFastAccess(MethodInfo[] methods, String signature, MethodMetaModel metaModel, ComponentModel model) { foreach (MethodInfo method in methods) { if (signature != null && signature.Length != 0) { model.MethodMetaModels.MethodInfo2Model[method] = metaModel; } else { if (!model.MethodMetaModels.MethodInfo2Model.Contains(method)) { model.MethodMetaModels.MethodInfo2Model[method] = metaModel; } } } }
public virtual void ProcessModel(IKernel kernel, ComponentModel model) { if (model.Configuration == null || model.Implementation == null) { return; } IConfiguration methodsNode = model.Configuration.Children["methods"]; if (methodsNode == null) { return; } EnsureHasReferenceToConverter(kernel); foreach (IConfiguration methodNode in methodsNode.Children) { String name = methodNode.Name; if ("method".Equals(name)) { name = methodNode.Attributes["name"]; } AssertNameIsNotNull(name, model); MethodMetaModel metaModel = new MethodMetaModel(methodNode); model.MethodMetaModels.Add(metaModel); String signature = methodNode.Attributes["signature"]; MethodInfo[] methods = GetMethods(model.Implementation, name, signature); RegisterMethodsForFastAccess(methods, signature, metaModel, model); } }
/// <summary> /// Processes the meta information available on /// the component configuration. (overrides MethodMetaInspector.ProcessMeta) /// </summary> /// <param name="model">The model.</param> /// <param name="methods">The methods.</param> /// <param name="metaModel">The meta model.</param> protected override void ProcessMeta(ComponentModel model, IList <MethodInfo> methods, MethodMetaModel metaModel) { metaStore.CreateMetaFromConfig(model.Implementation, methods, metaModel.ConfigNode); }
public virtual void ProcessModel(IKernel kernel, ComponentModel model) { if (model == null) { throw new ArgumentNullException("model"); } if (model.Configuration == null || model.Implementation == null) { return; } var methodsNode = model.Configuration.Children[ObtainNodeName()]; if (methodsNode == null) { return; } EnsureHasReferenceToConverter(kernel); foreach (var methodNode in methodsNode.Children) { var name = methodNode.Name; if ("method".Equals(name)) { name = methodNode.Attributes["name"]; } AssertNameIsNotNull(name, model); var metaModel = new MethodMetaModel(methodNode); if (IsValidMeta(model, metaModel)) { if (ShouldUseMetaModel) { // model.MethodMetaModels.Add( metaModel ); } var signature = methodNode.Attributes["signature"]; var methods = GetMethods(model.Implementation, name, signature); if (methods.Count == 0) { var message = String.Format("The class {0} has tried to expose configuration for " + "a method named {1} which could not be found.", model.Implementation.FullName, name); throw new Exception(message); } ProcessMeta(model, methods, metaModel); if (ShouldUseMetaModel) { // RegisterMethodsForFastAccess(methods, signature, metaModel, model); } } } }
protected virtual void ProcessMeta(ComponentModel model, IList <MethodInfo> methods, MethodMetaModel metaModel) { }
protected virtual bool IsValidMeta(ComponentModel model, MethodMetaModel metaModel) { return(true); }
/// <summary> /// Processes the meta information available on /// the component configuration. (overrides MethodMetaInspector.ProcessMeta) /// </summary> /// <param name="model">The model.</param> /// <param name="methods">The methods.</param> /// <param name="metaModel">The meta model.</param> protected override void ProcessMeta(ComponentModel model, IList<MethodInfo> methods, MethodMetaModel metaModel) { metaStore.CreateMetaFromConfig(model.Implementation, methods, metaModel.ConfigNode); }