Create an anonymous type from reflection ParamInfo[]

i want to create an anonymous type inside a function, when the anonymous type properties are the function parameters.

for example, for the function: private bool CreatePerson(string FirstName, string LasName, int Age, int height);

i will have an anonymous type with the properties: FirstName,LasName,Age and height. and the values of the function parameters will be the values of the anonymous type properties.

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;
    }
7
задан Rodniko 24 October 2010 в 12:50
поделиться