コード例 #1
0
		private IAstRefOrValue ConvertMappingValue(
			ReadWriteSimple rwMapOp,
			int operationId,
			IAstRefOrValue sourceValue)
		{
			IAstRefOrValue convertedValue = sourceValue;
			if (rwMapOp.Converter != null)
			{
				convertedValue = AstBuildHelper.CallMethod(
					rwMapOp.Converter.GetType().GetMethod("Invoke"),
                    new AstCastclassRef(
					    (IAstRef)AstBuildHelper.ReadMemberRV(
					         GetStoredObject(operationId, typeof(ReadWriteSimple)),
					         typeof(ReadWriteSimple).GetProperty("Converter")
					    ),
                        rwMapOp.Converter.GetType()
                    ),
					new List<IAstStackItem>()
                    {
                        sourceValue,
						AstBuildHelper.ReadLocalRV(locState),
                    }
				);
			}
			else
			{
				if (rwMapOp.ShallowCopy && rwMapOp.Destination.MemberType == rwMapOp.Source.MemberType)
				{
					convertedValue = sourceValue;
				}
				else
				{
					var mi = staticConvertersManager.GetStaticConverter(rwMapOp.Source.MemberType, rwMapOp.Destination.MemberType);
					if (mi != null)
					{
						convertedValue = AstBuildHelper.CallMethod(
							mi,
							null,
							new List<IAstStackItem> { sourceValue }
						);
					}
					else
					{
						convertedValue = ConvertByMapper(rwMapOp);
					}
				}
			}

			return convertedValue;
		}
コード例 #2
0
		private IAstRefOrValue ConvertByMapper(ReadWriteSimple mapping)
		{
			IAstRefOrValue convertedValue;
			ObjectsMapperDescr mapper = objectsMapperManager.GetMapperInt(
				mapping.Source.MemberType,
				mapping.Destination.MemberType,
				mappingConfigurator);
			int mapperId = AddObjectToStore(mapper);

			convertedValue = AstBuildHelper.CallMethod(
				typeof(ObjectsMapperBaseImpl).GetMethod(
					"Map",
					new Type[] { typeof(object), typeof(object), typeof(object) }
					),

				new AstReadFieldRef
				{
					fieldInfo = typeof(ObjectsMapperDescr).GetField("mapper"),
                    sourceObject = GetStoredObject(mapperId, mapper.GetType())
				},

				new List<IAstStackItem>()
                    {
						AstBuildHelper.ReadMembersChain(
							AstBuildHelper.ReadLocalRA(locFrom),
							mapping.Source.MembersChain
						),
						AstBuildHelper.ReadMembersChain(
							AstBuildHelper.ReadLocalRA(locTo),
							mapping.Destination.MembersChain
						),
						(IAstRef)AstBuildHelper.ReadLocalRA(locState)
                    }
				);
			return convertedValue;
		}
コード例 #3
0
		private IAstNode ProcessReadWriteSimple(ReadWriteSimple readWriteSimple, int operationId)
		{
			IAstRefOrValue sourceValue = ReadSrcMappingValue(readWriteSimple, operationId);

            IAstRefOrValue convertedValue;

            if (readWriteSimple.NullSubstitutor != null && (ReflectionUtils.IsNullable(readWriteSimple.Source.MemberType) || !readWriteSimple.Source.MemberType.IsValueType))
            {
                convertedValue = new AstIfTernar(
                    ReflectionUtils.IsNullable(readWriteSimple.Source.MemberType)
                        ? (IAstValue)new AstExprNot(AstBuildHelper.ReadPropertyRV(new AstValueToAddr((IAstValue)sourceValue), readWriteSimple.Source.MemberType.GetProperty("HasValue")))
                        : new AstExprIsNull(sourceValue),
                        GetNullValue(readWriteSimple.NullSubstitutor), // source is null
                        AstBuildHelper.CastClass(
                            ConvertMappingValue(
                                readWriteSimple,
                                operationId,
                                sourceValue
                            ),
                            readWriteSimple.Destination.MemberType
                        )
                );
            }
            else
            {
                convertedValue =
                    ConvertMappingValue(
                        readWriteSimple,
                        operationId,
                        sourceValue
                    );
            }

			IAstNode result = WriteMappingValue(readWriteSimple, operationId, convertedValue);

			if (readWriteSimple.SourceFilter != null)
			{
				result = Process_SourceFilter(readWriteSimple, operationId, result);
			}

			if (readWriteSimple.DestinationFilter != null)
			{
				result = Process_DestinationFilter(readWriteSimple, operationId, result);
			}
			return result;
		}