public BaseParameter MapDown(ParameterMetadata model, Type parameterModelType) { object parameterModel = Activator.CreateInstance(parameterModelType); PropertyInfo nameProperty = parameterModelType.GetProperty("Name"); PropertyInfo typeProperty = parameterModelType.GetProperty("Type", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); nameProperty?.SetValue(parameterModel, model.Name); if (model.Type != null) { typeProperty?.SetValue(parameterModel, typeProperty.PropertyType.Cast(MapperType.EmitBaseType(model.Type, typeProperty.PropertyType))); } return((BaseParameter)parameterModel); }
public BaseMethod MapDown(MethodMetadata model, Type methodModelType) { object methodModel = Activator.CreateInstance(methodModelType); PropertyInfo nameProperty = methodModelType.GetProperty("Name"); PropertyInfo extensionProperty = methodModelType.GetProperty("Extension"); PropertyInfo genericArgumentsProperty = methodModelType.GetProperty("GenericArguments", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); PropertyInfo modifiersProperty = methodModelType.GetProperty("Modifiers"); PropertyInfo parametersProperty = methodModelType.GetProperty("Parameters", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); PropertyInfo returnTypeProperty = methodModelType.GetProperty("ReturnType", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); nameProperty?.SetValue(methodModel, model.Name); extensionProperty?.SetValue(methodModel, model.Extension); if (model.GenericArguments != null) { genericArgumentsProperty?.SetValue(methodModel, Converter.ConvertList(genericArgumentsProperty.PropertyType.GetGenericArguments()[0], model.GenericArguments.Select(t => MapperType.EmitBaseType(t, genericArgumentsProperty.PropertyType.GetGenericArguments()[0])).ToList())); } modifiersProperty?.SetValue(methodModel, model.Modifiers); if (model.Parameters != null) { parametersProperty?.SetValue(methodModel, Converter.ConvertList(parametersProperty.PropertyType.GetGenericArguments()[0], model.Parameters.Select(p => new MapperParameter().MapDown(p, parametersProperty.PropertyType.GetGenericArguments()[0])).ToList())); } if (model.ReturnType != null) { returnTypeProperty?.SetValue(methodModel, returnTypeProperty.PropertyType.Cast(MapperType.EmitBaseType(model.ReturnType, returnTypeProperty.PropertyType))); } return((BaseMethod)methodModel); }