public void RoundtripSerialize() { var original = ConstructorDefinition.CreateDefinition(GetConstructorForString()); var copy = AssertExtensions.RoundTripSerialize(original); Assert.AreEqual(original, copy); }
public void CreateWithClass() { var obj = ConstructorDefinition.CreateDefinition(GetConstructorForString()); var constructor = GetConstructorForString(); Assert.That( obj.Parameters, Is.EquivalentTo(constructor.GetParameters().Select(p => ParameterDefinition.CreateDefinition(p)))); Assert.AreEqual(TypeIdentity.CreateDefinition(constructor.DeclaringType), obj.DeclaringType); }
public void Create() { var obj = ConstructorBasedImportDefinition.CreateDefinition( "A", TypeIdentity.CreateDefinition(typeof(char[])), ImportCardinality.ExactlyOne, CreationPolicy.NonShared, GetConstructorForString().GetParameters().First()); var constructor = GetConstructorForString(); var parameter = constructor.GetParameters().First(); Assert.AreEqual("A", obj.ContractName); Assert.AreEqual(TypeIdentity.CreateDefinition(typeof(char[])), obj.RequiredTypeIdentity); Assert.AreEqual(ImportCardinality.ExactlyOne, obj.Cardinality); Assert.IsFalse(obj.IsRecomposable); Assert.IsTrue(obj.IsPrerequisite); Assert.AreEqual(ConstructorDefinition.CreateDefinition(constructor), obj.Constructor); Assert.AreEqual(TypeIdentity.CreateDefinition(typeof(string)), obj.DeclaringType); Assert.AreEqual(ParameterDefinition.CreateDefinition(parameter), obj.Parameter); }
/// <summary> /// Creates a new instance of the <see cref="ConstructorBasedImportDefinition"/> class based /// on the given <see cref="ParameterInfo"/>. /// </summary> /// <param name="contractName">The contract name that is used to identify the current import.</param> /// <param name="requiredTypeIdentity">The type identity of the export type expected.</param> /// <param name="cardinality"> /// One of the enumeration values that indicates the cardinality of the export object required by the import definition. /// </param> /// <param name="creationPolicy"> /// A value that indicates that the importer requires a specific creation policy for the exports used to satisfy this import. /// </param> /// <param name="parameter">The method for which the current object stores the serialized data.</param> /// <param name="identityGenerator">The function that creates type identities.</param> /// <returns>The serialized definition for the given parameter.</returns> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="parameter"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="identityGenerator"/> is <see langword="null" />. /// </exception> public static ConstructorBasedImportDefinition CreateDefinition( string contractName, TypeIdentity requiredTypeIdentity, ImportCardinality cardinality, CreationPolicy creationPolicy, ParameterInfo parameter, Func <Type, TypeIdentity> identityGenerator) { { Lokad.Enforce.Argument(() => parameter); Lokad.Enforce.Argument(() => identityGenerator); } return(new ConstructorBasedImportDefinition( contractName, requiredTypeIdentity, cardinality, creationPolicy, identityGenerator(parameter.Member.DeclaringType), ConstructorDefinition.CreateDefinition(parameter.Member as ConstructorInfo, identityGenerator), ParameterDefinition.CreateDefinition(parameter, identityGenerator))); }