Exemplo n.º 1
0
        public NamespaceModel MapDown(NamespaceMetadata model, Type NamespaceMetadataType)
        {
            object       NamespaceMetadata          = Activator.CreateInstance(NamespaceMetadataType);
            PropertyInfo nameProperty               = NamespaceMetadataType.GetProperty("Name");
            PropertyInfo NamespaceMetadatasProperty = NamespaceMetadataType.GetProperty("Types",
                                                                                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

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

            return((NamespaceModel)NamespaceMetadata);
        }
Exemplo n.º 2
0
        public static AssemblyModel MapDown(AssemblyMetadata model, AssemblyModel assemblyModelType)
        {
            AssemblyModel assemblyModel           = assemblyModelType;// Activator.CreateInstance(assemblyModelType);
            PropertyInfo  nameProperty            = assemblyModelType.GetType().GetProperty("Name");
            PropertyInfo  namespaceModelsProperty = assemblyModelType.GetType().GetProperty("NamespaceModels",
                                                                                            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((AssemblyModel)assemblyModel);
        }
Exemplo n.º 3
0
        public NamespaceMetadata MapUp(NamespaceModel model)
        {
            NamespaceMetadata NamespaceMetadata = new NamespaceMetadata();

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

            if (types != null)
            {
                NamespaceMetadata.Types = types.Select(n => TypeModelMapper.EmitType(n)).ToList();
            }
            return(NamespaceMetadata);
        }
Exemplo n.º 4
0
        public static AssemblyMetadata MapUp(AssemblyModel model)
        {
            AssemblyMetadata assemblyModel = new AssemblyMetadata();
            Type             type          = model.GetType();

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

            if (namespaceModels != null)
            {
                assemblyModel.Namespaces = namespaceModels.Select(n => new NamespaceModelMapper().MapUp(n)).ToList();
            }
            return(assemblyModel);
        }
Exemplo n.º 5
0
        public MethodMetadata MapUp(MethodModel model)
        {
            MethodMetadata MethodMetadata = new MethodMetadata();

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

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

            MethodMetadata.Modifiers = model.Modifiers;

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

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

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

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

            if (returnType != null)
            {
                MethodMetadata.ReturnType = TypeModelMapper.EmitType(returnType);
            }
            return(MethodMetadata);
        }
Exemplo n.º 6
0
        public MethodModel MapDown(MethodMetadata model, Type MethodMetadataType)
        {
            object       MethodMetadata           = Activator.CreateInstance(MethodMetadataType);
            PropertyInfo nameProperty             = MethodMetadataType.GetProperty("Name");
            PropertyInfo extensionProperty        = MethodMetadataType.GetProperty("Extension");
            PropertyInfo genericArgumentsProperty = MethodMetadataType.GetProperty("GenericArguments",
                                                                                   BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            PropertyInfo modifiersProperty  = MethodMetadataType.GetProperty("Modifiers");
            PropertyInfo parametersProperty = MethodMetadataType.GetProperty("Parameters",
                                                                             BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            PropertyInfo returnTypeProperty = MethodMetadataType.GetProperty("ReturnType",
                                                                             BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            nameProperty?.SetValue(MethodMetadata, model.Name);
            extensionProperty?.SetValue(MethodMetadata, model.Extension);
            if (model.GenericArguments != null)
            {
                genericArgumentsProperty?.SetValue(MethodMetadata,
                                                   HelperClass.ConvertList(genericArgumentsProperty.PropertyType.GetGenericArguments()[0],
                                                                           model.GenericArguments.Select(t => TypeModelMapper.EmitBaseType(t, genericArgumentsProperty.PropertyType.GetGenericArguments()[0])).ToList()));
            }
            modifiersProperty?.SetValue(MethodMetadata, model.Modifiers);
            if (model.Parameters != null)
            {
                parametersProperty?.SetValue(MethodMetadata,
                                             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(MethodMetadata,
                                             returnTypeProperty.PropertyType.Cast(TypeModelMapper.EmitBaseType(model.ReturnType, returnTypeProperty.PropertyType)));
            }

            return((MethodModel)MethodMetadata);
        }
Exemplo n.º 7
0
        private void FillBaseType(TypeMetadata model, TypeModel 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("AssemblyName")?.SetValue(typModel, model.Name);
            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()));
            }
        }
Exemplo n.º 8
0
        private void FillType(TypeModel model, TypeMetadata TypeMetadata)
        {
            TypeMetadata.Name       = model.Name;
            TypeMetadata.IsExternal = model.IsExternal;
            TypeMetadata.IsGeneric  = model.IsGeneric;
            TypeMetadata.Type       = model.Type;
            TypeMetadata.Name       = model.AssemblyName;
            TypeMetadata.Modifiers  = model.Modifiers ?? new TypeModifiers();

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

            TypeMetadata.BaseType = EmitType(baseType);

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

            TypeMetadata.DeclaringType = EmitType(declaringType);

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

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

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

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

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

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

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

            if (fieldsProperty?.GetValue(model) != null)
            {
                List <ParameterModel> fields =
                    (List <ParameterModel>)HelperClass.ConvertList(typeof(ParameterModel),
                                                                   (IList)fieldsProperty?.GetValue(model));
                TypeMetadata.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 <MethodModel> methods = (List <MethodModel>)HelperClass.ConvertList(typeof(MethodModel),
                                                                                         (IList)methodsProperty?.GetValue(model));
                TypeMetadata.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 <MethodModel> constructors =
                    (List <MethodModel>)HelperClass.ConvertList(typeof(MethodModel),
                                                                (IList)constructorsProperty?.GetValue(model));
                TypeMetadata.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 <PropertyModel> properties =
                    (List <PropertyModel>)HelperClass.ConvertList(typeof(PropertyModel),
                                                                  (IList)propertiesProperty?.GetValue(model));
                TypeMetadata.Properties = properties?.Select(g => new PropertyModelMapper().MapUp(g))
                                          .ToList();
            }
        }