Exemplo n.º 1
0
        private Expression InjectCast(Expression exp)
        {
            var method = exp.Entity as IMethod;

            if (method == null)
            {
                return(exp);
            }

            IType castTargetType;
            var   parameters = method.GetParameters();

            if (parameters.Length > 0 || (method.ReturnType != TypeSystemServices.VoidType && method.ReturnType != null))
            {
                var isFunc = method.ReturnType != null && method.ReturnType != TypeSystemServices.VoidType;
                var genericTypeParameters = parameters.Select(p => p.Type).ToList();
                if (isFunc)
                {
                    genericTypeParameters.Add(method.ReturnType);
                }

                castTargetType = new GenericConstructedType(TypeSystemServices.Map(isFunc ? typeof(Func <>) : typeof(Action <>)), genericTypeParameters.ToArray());
            }
            else
            {
                castTargetType = TypeSystemServices.Map(typeof(Action));
            }

            return(CodeBuilder.CreateCast(castTargetType, exp));
        }
Exemplo n.º 2
0
        private static IType MapNestedType(IType entity)
        {
            if (entity.DeclaringEntity == null || entity.DeclaringEntity.EntityType != EntityType.Type)
            {
                return(entity);
            }

            var parentType = MapNestedType((IType)entity.DeclaringEntity);
            GenericConstructedType constructedParent = null;

            if (parentType.GenericInfo != null && parentType.ConstructedInfo == null)
            {
                constructedParent = (GenericConstructedType)parentType.GenericInfo.ConstructType(parentType.GenericInfo.GenericParameters);
            }
            constructedParent = constructedParent ?? parentType as GenericConstructedType;
            IType result = constructedParent == null || entity.DeclaringEntity == constructedParent
                                ? entity
                                : GenericMappedType.Create(entity, constructedParent);

            if (result.GenericInfo != null && result.ConstructedInfo == null)
            {
                result = result.GenericInfo.ConstructType(result.GenericInfo.GenericParameters);
            }
            return(result);
        }
Exemplo n.º 3
0
        protected MethodInvocationExpression CallMethodOnSelf(IMethod method)
        {
            var entity    = _stateMachineClass.Entity;
            var genParams = _stateMachineClass.ClassDefinition.GenericParameters;

            if (!genParams.IsEmpty)
            {
                var args = genParams.Select(gpd => gpd.Entity).Cast <IType>().ToArray();
                entity = new GenericConstructedType(entity, args);
                var mapping = new InternalGenericMapping(entity, args);
                method = mapping.Map(method);
            }
            return(CodeBuilder.CreateMethodInvocation(
                       CodeBuilder.CreateSelfReference(entity),
                       method));
        }