我希望在函数内创建一个匿名类型,其中匿名类型的属性是函数参数。
例如,对于函数: private bool CreatePerson(string FirstName, string LasName, int Age, int height);
我将拥有一个具有属性FirstName,LasName,Age和height的匿名类型。函数参数的值将是匿名类型属性的值。
例如,对于函数: private bool CreatePerson(string FirstName, string LasName, int Age, int height);
我将拥有一个具有属性FirstName,LasName,Age和height的匿名类型。函数参数的值将是匿名类型属性的值。
private bool CreatePerson(string FirstName, string LasName, int Age, int height)
{
// Get this method parameters
MethodBase currentMethod = MethodBase.GetCurrentMethod();
ParameterInfo[] parametersInfo = currentMethod.GetParameters();
// create an object of the parameters from the function.
foreach (ParameterInfo paramInfo in parametersInfo)
{
// add a property with the name of the parameter to an anonymous object and insert its value to the property.
// WHAT DO I DO HERE?
....
}
return true;
}