Beispiel #1
0
        public override void ImplementMethod(MethodInfo declaration, MethodBuilder implement, FieldInfo input)
        {
            var @params = declaration.GetParameters();
            var callee  = ThisType.GetMethod(declaration.Name, BindingFlags.Public | BindingFlags.Instance,
                                             null, @params.Select(p => p.ParameterType).ToArray(), null);

            var ilGen = implement.GetILGenerator();

            ilGen.Emit(OpCodes.Ldarg_0);
            ilGen.Emit(OpCodes.Ldfld, input);
            for (var i = 0; i < @params.Length;)
            {
                ilGen.Emit(OpCodes.Ldarg_S, (byte)++i);
            }
            ilGen.Emit(OpCodes.Call, callee);
            ilGen.Emit(OpCodes.Ret);
        }
        private static void MapNestedProperties(
            string sourcePropertiesPrefix,
            IEnumerable <PropertyInfo> nestedProperties,
            IMappingExpression <TLinkedSource, TDestination> expression)
        {
            foreach (var property in nestedProperties)
            {
                var sourcePropertyInDotNotation = $"{sourcePropertiesPrefix}.{property.Name}";
                var method        = ThisType.GetMethod("MapProperty");
                var genericMethod = method.MakeGenericMethod(property.PropertyType);

                genericMethod.Invoke(null, new object[]
                {
                    sourcePropertyInDotNotation,
                    property.Name,
                    expression
                });
            }
        }
        private static void MapContextualizedProperties(
            IEnumerable <PropertyInfo> contextualizedProperties,
            IMappingExpression <TLinkedSource, TDestination> expression)
        {
            foreach (var property in contextualizedProperties)
            {
                var overridingPropertyInDotNotation = string.Format("{0}.{1}", ContextualizationPropertyName, property.Name);
                var defaultPropertyInDotNotation    = string.Format("{0}.{1}", ModelPropertyName, property.Name);

                var method        = ThisType.GetMethod("MapContextualizedProperty");
                var genericMethod = method.MakeGenericMethod(property.PropertyType);
                genericMethod.Invoke(null, new object[]
                {
                    overridingPropertyInDotNotation,
                    defaultPropertyInDotNotation,
                    property.Name,
                    expression
                });
            }
        }