当匿名类型属性是函数参数时,我想在函数内部创建一个匿名类型。
例如,对于函数: 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;
}