/// <summary> /// Gets an <see cref="ElementInit"/> from its representation. /// </summary> /// <param name="elementInitRepresentation">The representation of the <see cref="ElementInit"/>.</param> /// <returns> /// The <see cref="ElementInit"/>. /// </returns> public static ElementInit FromRepresentation( this ElementInitRepresentation elementInitRepresentation) { if (elementInitRepresentation == null) { throw new ArgumentNullException(nameof(elementInitRepresentation)); } var type = elementInitRepresentation.Type.ResolveFromLoadedTypes(); var addMethod = type.GetMethods().Single(_ => _.ToRepresentation().Equals(elementInitRepresentation.AddMethod)); var arguments = elementInitRepresentation.Arguments.FromRepresentation(); var result = Expression.ElementInit(addMethod, arguments); return(result); }
/// <summary> /// Gets the representation of the specified <see cref="ElementInit"/>. /// </summary> /// <param name="elementInit">The <see cref="ElementInit"/>.</param> /// <returns> /// The representation of the specified <see cref="ElementInit"/>. /// </returns> public static ElementInitRepresentation ToRepresentation( this ElementInit elementInit) { if (elementInit == null) { throw new ArgumentNullException(nameof(elementInit)); } var type = elementInit.AddMethod.DeclaringType.ToRepresentation(); var addMethodRepresentation = elementInit.AddMethod.ToRepresentation(); var arguments = elementInit.Arguments.ToRepresentation(); var result = new ElementInitRepresentation(type, addMethodRepresentation, arguments); return(result); }