Пример #1
0
 public ParameterMetadata MapUp(BaseParameterMetadata model)
 {
     ParameterMetadata parameterModel = new ParameterMetadata();
     parameterModel.Name = model.Name;
     Type type = model.GetType();
     PropertyInfo typeProperty = type.GetProperty("Type", 
         BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
     BaseTypeMetadata typeModel = (BaseTypeMetadata)typeProperty?.GetValue(model);
     if (typeModel != null)
         parameterModel.Type = TypeModelMapper.EmitType(typeModel);
     return parameterModel;
 }
Пример #2
0
        public BaseParameterMetadata 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(TypeModelMapper.EmitBaseType(model.Type, typeProperty.PropertyType)));

            return (BaseParameterMetadata)parameterModel;
        }
Пример #3
0
        public NamespaceMetadata MapUp(BaseNamespaceMetadata 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 <BaseTypeMetadata> types = (List <BaseTypeMetadata>)HelperClass.ConvertList(typeof(BaseTypeMetadata), (IList)typesProperty?.GetValue(model));

            if (types != null)
            {
                namespaceModel.Types = types.Select(n => TypeModelMapper.EmitType(n)).ToList();
            }
            return(namespaceModel);
        }
Пример #4
0
        public PropertyModel MapUp(BasePropertyModel model)
        {
            PropertyModel propertyModel = new PropertyModel();

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

            if (typeModel != null)
            {
                propertyModel.Type = TypeModelMapper.EmitType(typeModel);
            }

            return(propertyModel);
        }
Пример #5
0
        public BasePropertyModel MapDown(PropertyModel model, Type propertyModelType)
        {
            object       propertyModel = Activator.CreateInstance(propertyModelType);
            PropertyInfo nameProperty  = propertyModelType.GetProperty("Name");
            PropertyInfo typeProperty  = propertyModelType.GetProperty("Type",
                                                                       BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            nameProperty?.SetValue(propertyModel, model.Name);

            if (model.Type != null)
            {
                typeProperty?.SetValue(propertyModel,
                                       typeProperty.PropertyType.Cast(TypeModelMapper.EmitBaseType(model.Type, typeProperty.PropertyType)));
            }

            return((BasePropertyModel)propertyModel);
        }
Пример #6
0
        public MethodModel MapUp(BaseMethodModel model)
        {
            MethodModel methodModel = new MethodModel();

            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 <BaseTypeModel> genericArguments =
                    (List <BaseTypeModel>)HelperClass.ConvertList(typeof(BaseTypeModel),
                                                                  (IList)genericArgumentsProperty?.GetValue(model));
                methodModel.GenericArguments =
                    genericArguments.Select(g => TypeModelMapper.EmitType(g)).ToList();
            }

            methodModel.Modifiers = model.Modifiers;

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

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

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

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

            if (returnType != null)
            {
                methodModel.ReturnType = TypeModelMapper.EmitType(returnType);
            }
            return(methodModel);
        }
Пример #7
0
        public BaseMethodModel MapDown(MethodModel 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,
                                                   HelperClass.ConvertList(genericArgumentsProperty.PropertyType.GetGenericArguments()[0],
                                                                           model.GenericArguments.Select(t => TypeModelMapper.EmitBaseType(t, genericArgumentsProperty.PropertyType.GetGenericArguments()[0])).ToList()));
            }
            modifiersProperty?.SetValue(methodModel, model.Modifiers);
            if (model.Parameters != null)
            {
                parametersProperty?.SetValue(methodModel,
                                             HelperClass.ConvertList(parametersProperty.PropertyType.GetGenericArguments()[0],
                                                                     model.Parameters.Select(p => new ParameterModelMapper().MapDown(p, parametersProperty.PropertyType.GetGenericArguments()[0])).ToList()));
            }
            if (model.ReturnType != null)
            {
                returnTypeProperty?.SetValue(methodModel,
                                             returnTypeProperty.PropertyType.Cast(TypeModelMapper.EmitBaseType(model.ReturnType, returnTypeProperty.PropertyType)));
            }

            return((BaseMethodModel)methodModel);
        }