private Term GenerateNonAcTermWithoutFieldMappings(object inputObject, TermDatabase termDatabase) { var type = inputObject.GetType(); var deconstructor = _nameAndTypeMappings.GetBestDeconstructorMethodForAcTerm(type); if (deconstructor == null) { return null; } var isExtensionMethod = deconstructor.IsDefined(typeof(ExtensionAttribute)); // Run deconstructor var parms = new object[deconstructor.GetParameters().Length]; if (isExtensionMethod) { parms[0] = inputObject; } deconstructor.Invoke(inputObject, parms); // Extract "out" parameter values var arguments = new List<Term>(); int startIndex = isExtensionMethod ? 1 : 0; for (int i = startIndex; i < parms.Length; i++) { arguments.Add(BuildTermForObject(parms[i], termDatabase)); } var termName = _nameAndTypeMappings.GetTermNameForType(type); var metaData = new Dictionary<TermMetaData, Term>(); return termDatabase.Writer.StoreNonAcTerm(termName, arguments.ToArray(), metaData); }
public void ShouldGetBestDeconstructorFromExtensionMethods() { // Arrange NameAndTypeMappings mappings = new NameAndTypeMappings(); // Act mappings.MapExtensionMethodDestructorsFromType(typeof(DateTimeExtensions)); var deconstructor = mappings.GetBestDeconstructorMethodForAcTerm(typeof(DateTime)); // Assert Assert.Equal(4, deconstructor.GetParameters().Length); }