Ejemplo 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>)Helper.ConvertList(typeof(BaseType), (IList)typesProperty?.GetValue(model));

            if (types != null)
            {
                namespaceModel.Types = types.Select(n => TypeMapper.EmitType(n)).ToList();
            }
            return(namespaceModel);
        }
Ejemplo 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 = TypeMapper.EmitType(typeModel);
            }
            return(parameterModel);
        }
        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>)Helper.ConvertList(typeof(BaseType),
                                                        (IList)genericArgumentsProperty?.GetValue(model));
                methodModel.GenericArguments =
                    genericArguments.Select(g => TypeMapper.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>)Helper.ConvertList(typeof(BaseParameter),
                                                             (IList)parametersProperty?.GetValue(model));

                methodModel.Parameters = parameters
                                         .Select(p => new ParameterMapper().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 = TypeMapper.EmitType(returnType);
            }
            return(methodModel);
        }