/// <summary> /// Initialize a new object. /// </summary> /// <param name="nativeDbType">Native database type as used in stored procedures.</param> /// <param name="typeMapper">Mapps native to target data types and renders code items associated with data type.</param> /// <param name="precision">Native DB type precision - if applicable.</param> /// <param name="scale">Native DB type scale - if applicable.</param> public TypeInfo(string nativeDbType, ITypeMapper typeMapper, int precision, int scale) { this.typeMapper = typeMapper; this.precision = precision; this.scale = scale; this.NativeDbType = typeMapper.NativeDbType(nativeDbType); this.IsVariableLengthNativeType = typeMapper.IsVariableLengthNativeType(nativeDbType); this.Type = typeMapper.Type(nativeDbType, precision, scale); this.DefaultValue = typeMapper.DefaultValue(nativeDbType, precision, scale); this.IsValueType = typeMapper.IsValueType(nativeDbType); this.DbType = typeMapper.DbType(nativeDbType); this.NullableType = typeMapper.NullableType(nativeDbType, precision, scale); this.NullValue = typeMapper.NullValue(nativeDbType, precision, scale); this.DataType = typeMapper.GetType(nativeDbType, precision, scale); }
/// <summary> /// Adds a type mapper to the chain with given priority. If mapper privided as an external MBean, the /// <paramref name="objectName"/> arguments is the name of this MBean; otherwise it is null. /// </summary> /// <param name="mapper">The mapper instance. In case of external mapper this is a reference to proxy of the MBean.</param> /// <param name="objectName">In case of external mapper, this is its <see cref="ObjectName"/>.</param> /// <param name="priority">The priority of a mapper. Must be unique.</param> /// <exception cref="NonUniquePriorityException">Another mapper with privided priority is already registered.</exception> public void AddTypeMapper(ITypeMapper mapper, ObjectName objectName, int priority) { TypeMapperInfo newMapperInfo = new TypeMapperInfo(priority, objectName == null ? mapper.GetType().AssemblyQualifiedName : null, objectName); if (_mappers.ContainsKey(priority)) { TypeMapperInfo exisingMapperInfo = _mapperInfos.Find(delegate(TypeMapperInfo info) { return info.Priority == priority; }); throw new NonUniquePriorityException( newMapperInfo.ObjectName != null ? newMapperInfo.ObjectName.ToString() : newMapperInfo.TypeName, exisingMapperInfo.ObjectName != null ? exisingMapperInfo.ObjectName.ToString() : exisingMapperInfo.TypeName, priority ); } _mappers.Add(priority, mapper); _mapperInfos.Add(newMapperInfo); }
/// <summary> /// Adds a type mapper to the chain with given priority. If mapper privided as an external MBean, the /// <paramref name="objectName"/> arguments is the name of this MBean; otherwise it is null. /// </summary> /// <param name="mapper">The mapper instance. In case of external mapper this is a reference to proxy of the MBean.</param> /// <param name="objectName">In case of external mapper, this is its <see cref="ObjectName"/>.</param> /// <param name="priority">The priority of a mapper. Must be unique.</param> /// <exception cref="NonUniquePriorityException">Another mapper with privided priority is already registered.</exception> public void AddTypeMapper(ITypeMapper mapper, ObjectName objectName, int priority) { TypeMapperInfo newMapperInfo = new TypeMapperInfo(priority, objectName == null ? mapper.GetType().AssemblyQualifiedName : null, objectName); if (_mappers.ContainsKey(priority)) { TypeMapperInfo exisingMapperInfo = _mapperInfos.Find(delegate(TypeMapperInfo info) { return(info.Priority == priority); }); throw new NonUniquePriorityException( newMapperInfo.ObjectName != null ? newMapperInfo.ObjectName.ToString() : newMapperInfo.TypeName, exisingMapperInfo.ObjectName != null ? exisingMapperInfo.ObjectName.ToString() : exisingMapperInfo.TypeName, priority ); } _mappers.Add(priority, mapper); _mapperInfos.Add(newMapperInfo); }
private static IGeneratedType GenerateType(ModuleBuilder moduleBuilder, ITypeDescription typeDescription, ITypeMapper typeMapper) { var typeBuilder = moduleBuilder.DefineType(typeDescription.Name, TypeAttributes.Public | TypeAttributes.Class); typeBuilder.DefineDefaultConstructor(MethodAttributes.Public); var types = typeDescription.PropertyDescriptions.Select(x => x.Type).ToArray(); var constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, types); var index = 1; foreach (var property in typeDescription.PropertyDescriptions) { constructorBuilder.DefineParameter(index, ParameterAttributes.None, property.Name.LowercaseFirst()); index++; } var ctorIl = constructorBuilder.GetILGenerator(); ctorIl.Emit(OpCodes.Ldarg_0); ctorIl.Emit(OpCodes.Call, typeBuilder.BaseType.GetConstructor(Type.EmptyTypes)); index = 1; foreach (var property in typeDescription.PropertyDescriptions) { var targetPropertyType = typeMapper.GetType(property.Type); EmitForPropertyDescription(typeBuilder, property, ctorIl, index, targetPropertyType); index++; } ctorIl.Emit(OpCodes.Ret); var type = typeBuilder.CreateType(); return new GeneratedType(typeDescription.Name, type, typeDescription); }