Exemplo n.º 1
0
        public NamespaceMetadata MapUp(BaseNamespace model)
        {
            NamespaceMetadata namespaceModel = new NamespaceMetadata();

            namespaceModel.Name = model.Name;
            Type         type          = model.GetType();
            PropertyInfo typesProperty = type.GetProperty("Types",
                                                          BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            List <BaseType> types = (List <BaseType>)Converter.ConvertList(typeof(BaseType), (IList)typesProperty?.GetValue(model));

            if (types != null)
            {
                namespaceModel.Types = types.Select(n => MapperType.EmitType(n)).ToList();
            }
            return(namespaceModel);
        }
Exemplo n.º 2
0
        public ParameterMetadata MapUp(BaseParameter model)
        {
            ParameterMetadata parameterModel = new ParameterMetadata();

            parameterModel.Name = model.Name;
            Type         type         = model.GetType();
            PropertyInfo typeProperty = type.GetProperty("Type",
                                                         BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            BaseType typeModel = (BaseType)typeProperty?.GetValue(model);

            if (typeModel != null)
            {
                parameterModel.Type = MapperType.EmitType(typeModel);
            }
            return(parameterModel);
        }
Exemplo n.º 3
0
        public MethodMetadata MapUp(BaseMethod model)
        {
            MethodMetadata methodModel = new MethodMetadata();

            methodModel.Name      = model.Name;
            methodModel.Extension = model.Extension;
            Type         type = model.GetType();
            PropertyInfo genericArgumentsProperty = type.GetProperty("GenericArguments",
                                                                     BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (genericArgumentsProperty?.GetValue(model) != null)
            {
                List <BaseType> genericArguments =
                    (List <BaseType>)Converter.ConvertList(typeof(BaseType),
                                                           (IList)genericArgumentsProperty?.GetValue(model));
                methodModel.GenericArguments =
                    genericArguments.Select(g => MapperType.EmitType(g)).ToList();
            }

            methodModel.Modifiers = model.Modifiers;

            PropertyInfo parametersProperty = type.GetProperty("Parameters",
                                                               BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (parametersProperty?.GetValue(model) != null)
            {
                List <BaseParameter> parameters =
                    (List <BaseParameter>)Converter.ConvertList(typeof(BaseParameter),
                                                                (IList)parametersProperty?.GetValue(model));

                methodModel.Parameters = parameters
                                         .Select(p => new MapperParameter().MapUp(p)).ToList();
            }

            PropertyInfo returnTypeProperty = type.GetProperty("ReturnType",
                                                               BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            BaseType returnType = (BaseType)returnTypeProperty?.GetValue(model);

            if (returnType != null)
            {
                methodModel.ReturnType = MapperType.EmitType(returnType);
            }
            return(methodModel);
        }