Exemple #1
0
        private void MapConstructor(GenericReferenceExpression node, GenericMappedConstructor member)
        {
            var source  = member.SourceMember;
            var genArgs = node.GenericArguments
                          .Select(ga => _methodToStateMachineMapper.MapType((IType)ga.Entity))
                          .ToArray();
            var result = source.DeclaringType.GenericInfo.ConstructType(genArgs).ConstructedInfo.Map(source);

            node.Entity         = result;
            node.ExpressionType = result.Type;
        }
Exemple #2
0
        /// <summary>
        /// Maps a type member involving generic arguments to its constructed counterpart, after substituting 
        /// concrete types for generic arguments.
        /// </summary>
        public IEntity Map(IEntity source)
        {
            if (source == null)
                return null;

            // Map generic source to the constructed owner of this mapping
            if (source == _genericSource)
            {
                return _constructedOwner;
            }

            // Use cache if possible
            if (_cache.ContainsKey(source))
            {
                return _cache[source];
            }

            // Map entity based on its entity type
            IEntity mapped = null;
            switch (source.EntityType)
            {
                case EntityType.Ambiguous:
                    mapped = MapAmbiguousEntity((Ambiguous)source);
                    break;

                case EntityType.Method:
                    mapped = new GenericMappedMethod(_tss, ((IMethod)source), this);
                    break;

                case EntityType.Constructor:
                    mapped = new GenericMappedConstructor(_tss, ((IConstructor)source), this);
                    break;

                case EntityType.Field:
                    mapped = new GenericMappedField(_tss, ((IField)source), this);
                    break;

                case EntityType.Property:
                    mapped = new GenericMappedProperty(_tss, ((IProperty)source), this);
                    break;

                case EntityType.Event:
                    mapped = new GenericMappedEvent(_tss, ((IEvent)source), this);
                    break;

                case EntityType.Parameter:
                    mapped = new GenericMappedParameter((IParameter)source, this);
                    break;

                case EntityType.Array:
                case EntityType.Type:
                    mapped = MapType((IType)source);
                    break;

                default:
                    return source;
            }

            // Cache mapped result and return it
            _cache[source] = mapped;
            return mapped;
        }