C# , how to create object instance by using expression
-
I'm trying to using expression to create object instance, but i got an error 'System.Reflection.TargetParameterCountException'. my code is bellow , and i don't know what's the problem, please help. using BenchmarkDotNet.Attributes; using FastExpressionCompiler.LightExpression; using FastMember; using System; using System.Collections.Concurrent; using System.Diagnostics; using System.Reflection; using System.Threading.Tasks; using static FastExpressionCompiler.LightExpression.ExpressionCompiler; namespace ConsoleApp2 { public class Program { static void Main(string[] args) { TestExpressionCreate(); TestActivatorCreate(); //var summary = BenchmarkRunner.Run(); Console.ReadLine(); } #region [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] public class FieldAttribute : Attribute { private bool _isSizeExtracted; private string _size; public FieldAttribute(string dataType = null) { if (!string.IsNullOrWhiteSpace(dataType)) { DataType = dataType.ToLower(); } } public int? Index { get; set; } public string FieldName { get; set; } public bool HasDefaultValue { get; set; } public string DataType { get; set; } internal string Size { get { if (string.IsNullOrWhiteSpace(DataType)) return null; if (!_isSizeExtracted) { _isSizeExtracted = true; var i = DataType.IndexOf('('); if (i > 0) { var j = DataType.IndexOf(')', i); if (j > 0) { //_size = DataType[(i + 1)..j]; } } } return _size; } } } internal class TableInfo { } internal class FieldInfoBase { internal int Index { get; set; } internal string FieldName { get; set; } internal bool HasDefaultValue