/// <summary>Instantiate a bean that models the part under question.</summary> /// <remarks>Instantiate a bean that models the part under question.</remarks> /// <param name="version">- the version code</param> /// <param name="type">- the part type</param> /// <returns>an instance of a bean that represents the part type</returns> public virtual object InstantiateMessagePartBean(VersionNumber version, string type, Interaction interaction) { try { Type partClass = MessageBeanRegistry.GetInstance().GetMessagePartClass(version, type); if (partClass == null) { throw CreateMarshallingException("Did not find", version, type); } else { if (!ClassUtil.IsGeneric(partClass)) { this.log.Debug("Instantiating bean: " + partClass.FullName); return(System.Activator.CreateInstance(partClass)); } else { this.log.Debug("Instantiating parameterized bean: " + partClass.FullName); return(GenericClassUtil.Instantiate(partClass, CreateParameterMap(interaction, version))); } } } catch (MemberAccessException e) { throw CreateMarshallingException("Error instantiating", version, type, e); } catch (Exception e) { throw CreateMarshallingException("Error instantiating", version, type, e); } }
public void ShouldInstantiateListFromDictionary() { Type t = typeof(List <>); IDictionary <String, Type> dictionary = new Dictionary <String, Type>(); dictionary.Add("T", typeof(String)); Object o = GenericClassUtil.Instantiate(typeof(List <>), dictionary); Assert.AreEqual("System.Collections.Generic.List`1[System.String]", o.GetType().ToString(), "type"); }
public void ShouldInstantiateListOfLists() { List <TemplateArgument> arguments = new List <TemplateArgument>(); List <TemplateArgument> subArguments = new List <TemplateArgument>(); subArguments.Add(new TemplateArgument(typeof(String), new List <TemplateArgument>())); arguments.Add(new TemplateArgument(typeof(List <>), subArguments)); Object o = GenericClassUtil.Instantiate(typeof(List <>), arguments); Assert.AreEqual("System.Collections.Generic.List`1[System.Collections.Generic.List`1[System.String]]", o.GetType().ToString(), "type"); }
public void ShouldInstantiateList() { Type t = typeof(List <>); foreach (Type argument in t.GetGenericArguments()) { Console.WriteLine(argument.Name); } List <TemplateArgument> arguments = new List <TemplateArgument>(); arguments.Add(new TemplateArgument(typeof(String), new List <TemplateArgument>())); Object o = GenericClassUtil.Instantiate(typeof(List <>), arguments); Assert.AreEqual("System.Collections.Generic.List`1[System.String]", o.GetType().ToString(), "type"); }