Ejemplo n.º 1
0
        private static bool IsMapped(this AssemblyDefinition assembly, IModelMapperConfiguration configuration)
        {
            var typeAssemblyHash             = configuration.TypeToMap.Assembly.ManifestModule.ModuleVersionId.GetHashCode();
            var modelMapperServiceAttributes = assembly.CustomAttributes.Where(attribute => attribute.AttributeType.FullName == typeof(ModelMapperTypeAttribute).FullName).ToArray();

            return(modelMapperServiceAttributes.Any(attribute => {
                var mappedTypeAssemblyHash = int.Parse(attribute.ConstructorArguments.Skip(2).First().Value.ToString());
                var mappedType = (string)attribute.ConstructorArguments.First().Value;
                return mappedTypeAssemblyHash == typeAssemblyHash && mappedType == configuration.TypeToMap.FullName &&
                configuration.GetHashCode() == (int)attribute.ConstructorArguments.Last().Value;
            }));
        }
Ejemplo n.º 2
0
        private static bool TypeFromPath(this IModelMapperConfiguration configuration)
        {
            var assemblyPath = GetLastAssemblyPath();

            if (!string.IsNullOrEmpty(assemblyPath))
            {
                using var assembly = AssemblyDefinition.ReadAssembly(assemblyPath);
                if (assembly.IsMapped(configuration) && !assembly.VersionChanged() && !assembly.ConfigurationChanged())
                {
                    return(true);
                }
            }
            return(false);
        }
        public static void Extend(this ApplicationModulesManager modulesManager, IModelMapperConfiguration configuration)
        {
            if (modulesManager.Modules.FindModule <ModelMapperModule>() == null)
            {
                throw new NotSupportedException($"{typeof(ModelMapperModule)} is not registered");
            }
            TypeMappingService.Connect().Wait();
            var installed = ModelMapperConfigurations.FirstOrDefault(_ => _.TypeToMap == configuration.TypeToMap);

            if (installed != null)
            {
                installed.TargetInterfaceTypes.AddRange(configuration.TargetInterfaceTypes);
            }
            else
            {
                ModelMapperConfigurations.Add(configuration);
            }
        }
Ejemplo n.º 4
0
        static ((string key, string code)[] code, IEnumerable <Assembly> references) ModelCode(this Type type, IModelMapperConfiguration configuration = null)
        {
            var propertyInfos       = type.PropertyInfos();
            var additionalTypes     = propertyInfos.AdditionalTypes(type);
            var assemblyDefinitions = type.AssemblyDefinitions(additionalTypes);

            var additionalTypesCode = type.AdditionalTypesCode(additionalTypes, assemblyDefinitions);

            var containerName = type.ModelMapContainerName(configuration);
            var mapName       = type.ModelMapName(configuration: configuration);
            var containerCode = type.ContainerCode(configuration, $"IModel{containerName}", assemblyDefinitions, mapName);

            var modelMappersTypeName      = $"IModel{containerName}{ModelMappersNodeName}";
            var modelMappersInterfaceCode = ModelMappersInterfaceCode(modelMappersTypeName);

            var typeCode = type.TypeCode(mapName, modelMappersTypeName, assemblyDefinitions, configuration?.ImageName);

            foreach (var assemblyDefinition in assemblyDefinitions)
            {
                assemblyDefinition.Dispose();
            }

            var code = new [] { typeCode, containerCode, modelMappersInterfaceCode }.Concat(additionalTypesCode).ToArray();
            var allAssemblies = AllAssemblies(type, propertyInfos);

            return(code, allAssemblies);
        }
 private static IEnumerable <(Type targetInterfaceType, Type extenderInterface)> CollectExtenders(this IModelMapperConfiguration configuration, Type extenderInterface)
 {
     XafTypesInfo.Instance.FindTypeInfo(extenderInterface);
     return(configuration.TargetInterfaceTypes.Select(targetInterfaceType => (targetInterfaceType, configuration.IsDependency?typeof(IModelModelMappersContextDependency):extenderInterface)));
 }
Ejemplo n.º 6
0
 // ReSharper disable once SuggestBaseTypeForParameter
 public ModelController(IModelManager modelManager, IModelMapperConfiguration mapperConfiguration)
 {
     Mapper       = mapperConfiguration.CreateMapper();
     ModelManager = modelManager;
 }