Esempio n. 1
0
        public MethodInvocationExpression CreateConstructorInvocationWithReferencedEntities(IType type, Method containingMethod)
        {
            GeneratorTypeReplacer mapper;

            type = GeneratorTypeReplacer.MapTypeInMethodContext(type, containingMethod, out mapper);
            MethodInvocationExpression mie = CodeBuilder.CreateConstructorInvocation(type.GetConstructors().First());

            foreach (var entity in _referencedEntities.Keys)
            {
                mie.Arguments.Add(CreateForeignReference(entity));
            }
            if (mapper != null)
            {
                mie.Accept(new GenericTypeMapper(mapper));
            }
            return(mie);
        }
Esempio n. 2
0
        private void Map()
        {
            var type    = GeneratorTypeReplacer.MapTypeInMethodContext((IType)_sharedLocalsClass.Entity, _currentMethod);
            var conType = type as GenericConstructedType;

            if (conType != null)
            {
                foreach (var key in _mappings.Keys.ToArray())
                {
                    _mappings[key] = (IField)conType.ConstructedInfo.Map(_mappings[key]);
                }
            }
            var locals = CodeBuilder.DeclareLocal(_currentMethod, "$locals", type);

            foreach (var reference in _references)
            {
                IField mapped;
                if (!_mappings.TryGetValue(reference.Entity, out mapped))
                {
                    continue;
                }

                reference.ParentNode.Replace(
                    reference,
                    CodeBuilder.CreateMemberReference(
                        CodeBuilder.CreateReference(locals),
                        mapped));
            }

            var initializationBlock = new Block();

            initializationBlock.Add(CodeBuilder.CreateAssignment(
                                        CodeBuilder.CreateReference(locals),
                                        CodeBuilder.CreateConstructorInvocation(type.GetConstructors().First())));
            InitializeSharedParameters(initializationBlock, locals);
            _currentMethod.Body.Statements.Insert(0, initializationBlock);

            foreach (IEntity entity in _mappings.Keys)
            {
                _currentMethod.Locals.RemoveByEntity(entity);
            }
        }