コード例 #1
0
        public static bool RegisterConverter(IEntityMappingConverter converter, Type entityType, Type modelType)
        {
            if (!Converters.ContainsKey(entityType))
            {
                Converters[entityType] = new Dictionary <Type, IEntityMappingConverter>();
            }

            if (!Converters[entityType].ContainsKey(modelType))
            {
                Converters[entityType][modelType] = converter;
                return(true);
            }
            return(false);
        }
コード例 #2
0
        public EntityConversionAttribute(Type entityType, Type modelType)
        {
            EntityType = entityType;
            ModelType  = modelType;

            if (entityType == typeof(int) && modelType.GetTypeInfo().IsEnum)
            {
                Type   repo        = typeof(EnumIntConverter <>);
                Type[] args        = { modelType };
                Type   constructed = repo.MakeGenericType(args);

                Converter = Activator.CreateInstance(constructed) as IEntityMappingConverter;
            }
            else if (Converters.ContainsKey(entityType) && Converters[entityType].ContainsKey(modelType))
            {
                Converter = Converters[entityType][modelType];
            }
            else
            {
                throw new ConverterNotFoundException(entityType, modelType);
            }
        }
コード例 #3
0
 private void Test(IEntityMappingConverter converter, object highLevelValue, object lowLevelValue)
 {
     Assert.IsTrue(highLevelValue.Equals(converter.ConvertToModelFormat(lowLevelValue)));
     Assert.IsTrue(lowLevelValue.Equals(converter.ConvertToEntityFormat(highLevelValue)));
 }