public BaseNamespaceMetadata MapDown(NamespaceMetadata model, Type namespaceModelType)
        {
            object       namespaceModel          = Activator.CreateInstance(namespaceModelType);
            PropertyInfo nameProperty            = namespaceModelType.GetProperty("Name");
            PropertyInfo namespaceModelsProperty = namespaceModelType.GetProperty("Types",
                                                                                  BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            nameProperty?.SetValue(namespaceModel, model.Name);
            namespaceModelsProperty?.SetValue(namespaceModel,
                                              HelperClass.ConvertList(namespaceModelsProperty.PropertyType.GetGenericArguments()[0],
                                                                      model.Types.Select(t => new TypeModelMapper().MapDown(t, namespaceModelsProperty.PropertyType.GetGenericArguments()[0])).ToList()));

            return((BaseNamespaceMetadata)namespaceModel);
        }
        public static BaseAssemblyMetadata MapDown(AssemblyMetadata model, BaseAssemblyMetadata assemblyModel)
        {
            //object assemblyModel = Activator.CreateInstance(assemblyModelType);
            PropertyInfo nameProperty            = assemblyModel.GetType().GetProperty("Name");
            PropertyInfo namespaceModelsProperty = assemblyModel.GetType().GetProperty("Namespaces",
                                                                                       BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            nameProperty?.SetValue(assemblyModel, model.Name);
            namespaceModelsProperty?.SetValue(
                assemblyModel,
                HelperClass.ConvertList(namespaceModelsProperty.PropertyType.GetGenericArguments()[0],
                                        model.Namespaces.Select(n => new NamespaceModelMapper().MapDown(n, namespaceModelsProperty.PropertyType.GetGenericArguments()[0])).ToList()));
            return((BaseAssemblyMetadata)assemblyModel);
        }
        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);
        }
Exemple #4
0
        public static AssemblyModel MapUp(BaseAssemblyModel model)
        {
            AssemblyModel assemblyModel = new AssemblyModel();
            Type          type          = model.GetType();

            assemblyModel.Name = model.Name;
            PropertyInfo namespaceModelsProperty = type.GetProperty("NamespaceModels",
                                                                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            List <BaseNamespaceModel> namespaceModels = (List <BaseNamespaceModel>)HelperClass.ConvertList(typeof(BaseNamespaceModel), (IList)namespaceModelsProperty?.GetValue(model));

            if (namespaceModels != null)
            {
                assemblyModel.NamespaceModels = namespaceModels.Select(n => new NamespaceModelMapper().MapUp(n)).ToList();
            }
            return(assemblyModel);
        }
        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);
        }
        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);
        }
        private void FillBaseType(TypeMetadata model, BaseTypeMetadata typModel)
        {
            Type typeModelType = typModel.GetType();

            typeModelType.GetProperty("Name")?.SetValue(typModel, model.Name);
            //typeModelType.GetProperty("IsExternal")?.SetValue(typModel, model.IsExternal);
            //typeModelType.GetProperty("IsGeneric")?.SetValue(typModel, model.IsGeneric);
            typeModelType.GetProperty("Type")?.SetValue(typModel, model.Type);
            typeModelType.GetProperty("NamespaceName")?.SetValue(typModel, model.NamespaceName); //?? assembly
            typeModelType.GetProperty("Modifiers")?.SetValue(typModel, model.Modifiers);         //?? new TypeModifiers());

            if (model.BaseType != null)
            {
                typeModelType.GetProperty("BaseType",
                                          BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                ?.SetValue(typModel, typeModelType.Cast(EmitBaseType(model.BaseType, typeModelType)));
            }

            if (model.DeclaringType != null)
            {
                typeModelType.GetProperty("DeclaringType",
                                          BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                ?.SetValue(typModel, typeModelType.Cast(EmitBaseType(model.DeclaringType, typeModelType)));
            }

            if (model.NestedTypes != null)
            {
                PropertyInfo nestedTypesProperty = typeModelType.GetProperty("NestedTypes",
                                                                             BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                nestedTypesProperty?.SetValue(typModel,
                                              HelperClass.ConvertList(typeModelType,
                                                                      model.NestedTypes?.Select(c => EmitBaseType(c, typeModelType)).ToList()));
            }

            if (model.GenericArguments != null)
            {
                PropertyInfo genericArgumentsProperty = typeModelType.GetProperty("GenericArguments",
                                                                                  BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                genericArgumentsProperty?.SetValue(typModel,
                                                   HelperClass.ConvertList(typeModelType,
                                                                           model.GenericArguments?.Select(c => EmitBaseType(c, typeModelType)).ToList()));
            }

            if (model.ImplementedInterfaces != null)
            {
                PropertyInfo implementedInterfacesProperty = typeModelType.GetProperty("ImplementedInterfaces",
                                                                                       BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                implementedInterfacesProperty?.SetValue(typModel,
                                                        HelperClass.ConvertList(typeModelType,
                                                                                model.ImplementedInterfaces?.Select(c => EmitBaseType(c, typeModelType)).ToList()));
            }

            if (model.Fields != null)
            {
                PropertyInfo fieldsProperty = typeModelType.GetProperty("Fields",
                                                                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                fieldsProperty?.SetValue(typModel,
                                         HelperClass.ConvertList(fieldsProperty.PropertyType.GetGenericArguments()[0],
                                                                 model.Fields?.Select(c =>
                                                                                      new ParameterModelMapper().MapDown(c,
                                                                                                                         fieldsProperty?.PropertyType.GetGenericArguments()[0])).ToList()));
            }

            if (model.Methods != null)
            {
                PropertyInfo methodsProperty = typeModelType.GetProperty("Methods",
                                                                         BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                methodsProperty?.SetValue(typModel,
                                          HelperClass.ConvertList(methodsProperty.PropertyType.GetGenericArguments()[0],
                                                                  model.Methods?.Select(m =>
                                                                                        new MethodModelMapper().MapDown(m,
                                                                                                                        methodsProperty?.PropertyType.GetGenericArguments()[0]))
                                                                  .ToList()));
            }

            if (model.Constructors != null)
            {
                PropertyInfo constructorsProperty = typeModelType.GetProperty("Constructors",
                                                                              BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                constructorsProperty?.SetValue(typModel,
                                               HelperClass.ConvertList(constructorsProperty.PropertyType.GetGenericArguments()[0],
                                                                       model.Constructors?.Select(c =>
                                                                                                  new MethodModelMapper().MapDown(c,
                                                                                                                                  constructorsProperty?.PropertyType.GetGenericArguments()[0])).ToList()));
            }

            if (model.Properties != null)
            {
                PropertyInfo propertiesProperty = typeModelType.GetProperty("Properties",
                                                                            BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                propertiesProperty?.SetValue(typModel,
                                             HelperClass.ConvertList(propertiesProperty.PropertyType.GetGenericArguments()[0],
                                                                     model.Properties?.Select(c =>
                                                                                              new PropertyModelMapper().MapDown(c,
                                                                                                                                propertiesProperty?.PropertyType.GetGenericArguments()[0])).ToList()));
            }
        }
        private void FillType(BaseTypeMetadata model, TypeMetadata typeModel)
        {
            typeModel.Name = model.Name;
            //typeModel.IsExternal = model.IsExternal;
            //typeModel.IsGeneric = model.IsGeneric;
            typeModel.Type          = model.Type;
            typeModel.NamespaceName = model.NamespaceName;
            typeModel.Modifiers     = model.Modifiers; //?? new TypeModifiers();

            Type         type             = model.GetType();
            PropertyInfo baseTypeProperty = type.GetProperty("BaseType",
                                                             BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            BaseTypeMetadata baseType = (BaseTypeMetadata)baseTypeProperty?.GetValue(model);

            typeModel.BaseType = EmitType(baseType);

            PropertyInfo declaringTypeProperty = type.GetProperty("DeclaringType",
                                                                  BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            BaseTypeMetadata declaringType = (BaseTypeMetadata)declaringTypeProperty?.GetValue(model);

            typeModel.DeclaringType = EmitType(declaringType);

            PropertyInfo nestedTypesProperty = type.GetProperty("NestedTypes",
                                                                BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (nestedTypesProperty?.GetValue(model) != null)
            {
                List <BaseTypeMetadata> nestedTypes = (List <BaseTypeMetadata>)HelperClass.ConvertList(typeof(BaseTypeMetadata),
                                                                                                       (IList)nestedTypesProperty?.GetValue(model));
                typeModel.NestedTypes = nestedTypes?.Select(n => EmitType(n)).ToList();
            }

            PropertyInfo genericArgumentsProperty = type.GetProperty("GenericArguments",
                                                                     BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (genericArgumentsProperty?.GetValue(model) != null)
            {
                List <BaseTypeMetadata> genericArguments =
                    (List <BaseTypeMetadata>)HelperClass.ConvertList(typeof(BaseTypeMetadata),
                                                                     (IList)genericArgumentsProperty?.GetValue(model));
                typeModel.GenericArguments = genericArguments?.Select(g => EmitType(g)).ToList();
            }

            PropertyInfo implementedInterfacesProperty = type.GetProperty("ImplementedInterfaces",
                                                                          BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (implementedInterfacesProperty?.GetValue(model) != null)
            {
                List <BaseTypeMetadata> implementedInterfaces =
                    (List <BaseTypeMetadata>)HelperClass.ConvertList(typeof(BaseTypeMetadata),
                                                                     (IList)implementedInterfacesProperty?.GetValue(model));
                typeModel.ImplementedInterfaces =
                    implementedInterfaces?.Select(i => EmitType(i)).ToList();
            }

            PropertyInfo fieldsProperty = type.GetProperty("Fields",
                                                           BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (fieldsProperty?.GetValue(model) != null)
            {
                List <BaseParameterMetadata> fields =
                    (List <BaseParameterMetadata>)HelperClass.ConvertList(typeof(BaseParameterMetadata),
                                                                          (IList)fieldsProperty?.GetValue(model));
                typeModel.Fields = fields?.Select(g => new ParameterModelMapper().MapUp(g))
                                   .ToList();
            }

            PropertyInfo methodsProperty = type.GetProperty("Methods",
                                                            BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (methodsProperty?.GetValue(model) != null)
            {
                List <BaseMethodMetadata> methods = (List <BaseMethodMetadata>)HelperClass.ConvertList(typeof(BaseMethodMetadata),
                                                                                                       (IList)methodsProperty?.GetValue(model));
                typeModel.Methods = methods?.Select(c => new MethodModelMapper().MapUp(c)).ToList();
            }

            PropertyInfo constructorsProperty = type.GetProperty("Constructors",
                                                                 BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (constructorsProperty?.GetValue(model) != null)
            {
                List <BaseMethodMetadata> constructors =
                    (List <BaseMethodMetadata>)HelperClass.ConvertList(typeof(BaseMethodMetadata),
                                                                       (IList)constructorsProperty?.GetValue(model));
                typeModel.Constructors = constructors?.Select(c => new MethodModelMapper().MapUp(c))
                                         .ToList();
            }

            PropertyInfo propertiesProperty = type.GetProperty("Properties",
                                                               BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (propertiesProperty?.GetValue(model) != null)
            {
                List <BasePropertyMetadata> properties =
                    (List <BasePropertyMetadata>)HelperClass.ConvertList(typeof(BasePropertyMetadata),
                                                                         (IList)propertiesProperty?.GetValue(model));
                typeModel.Properties = properties?.Select(g => new PropertyModelMapper().MapUp(g))
                                       .ToList();
            }
        }