コード例 #1
0
        public DataTypePointer GetConcreteType(Type typeParameter)
        {
            if (ClassType != null)
            {
                DataTypePointer dp = _type.GetConcreteType(typeParameter);
                if (dp != null)
                {
                    return(dp);
                }
            }
            IGenericTypePointer igp = null;
            IObjectPointer      op  = Owner;

            while (op != null)
            {
                igp = op as IGenericTypePointer;
                if (igp != null)
                {
                    break;
                }
                op = op.Owner;
            }
            if (igp != null)
            {
                return(igp.GetConcreteType(typeParameter));
            }
            return(null);
        }
コード例 #2
0
        public DataTypePointer GetConcreteType(Type typeParameter)
        {
            IGenericTypePointer gtp = _methodPointer as IGenericTypePointer;

            if (gtp != null)
            {
                return(gtp.GetConcreteType(typeParameter));
            }
            return(null);
        }
コード例 #3
0
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode", this.GetType().Name);
            if (_methodPointer == null)
            {
                MathNode.Trace("Warning: method pointer is null");
                return(null);
            }
            bool isWeb = false;

            if (_methodPointer.Owner != null && _methodPointer.Owner.RootPointer != null)
            {
                isWeb = _methodPointer.Owner.RootPointer.IsWebPage;
            }
            if (isWeb && _methodPointer.RunAt == EnumWebRunAt.Client)
            {
                CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression(
                    new CodeVariableReferenceExpression("clientRequest"), "GetStringValue", new CodePrimitiveExpression(DataPassingCodeName));
                return(cmie);
            }
            if (method == null)
            {
                throw new DesignerException("Calling {0}.ExportCode with null method", this.GetType().Name);
            }
            if (method.MethodCode == null)
            {
                throw new DesignerException("Calling {0}.ExportCode with null method.MethodCode", this.GetType().Name);
            }
            CodeStatementCollection supprtStatements = method.MethodCode.Statements;
            int n = ChildNodeCount;

            CodeExpression[] ps;
            if (n > 0)
            {
                IList <IParameter> pList = _methodPointer.MethodPointed.MethodParameterTypes;;

                //_methodPointer.MethodPointed.
                ps = new CodeExpression[n];
                for (int i = 0; i < n; i++)
                {
                    this[i].CompileDataType = new RaisDataType(pList[i].ParameterLibType);
                    if (typeof(string).Equals(pList[i].ParameterLibType))
                    {
                        if (this[i].Parent != null)
                        {
                            MathNodeMethodPointer mmp = this[i].Parent as MathNodeMethodPointer;
                            if (mmp != null && mmp.Method != null && mmp.Method.Owner != null)
                            {
                                if (typeof(DateTime).Equals(mmp.Method.Owner.ObjectType))
                                {
                                    if (this[i].ActualCompiledType != null && typeof(CultureInfo).Equals(this[i].ActualCompiledType.LibType))
                                    {
                                        this[i].CompileDataType = this[i].ActualCompiledType;
                                    }
                                }
                            }
                        }
                    }
                    ps[i] = this[i].ExportCode(method);
                }
            }
            else
            {
                ps = new CodeExpression[] { };
            }
            _methodPointer.SetParameterExpressions(ps);
            CodeExpression ce = _methodPointer.GetReferenceCode(method, supprtStatements, true);

            if (_methodPointer.ReturnBaseType != null && this.CompileDataType != null && this.CompileDataType.Type != null)
            {
                DataTypePointer     targetType = new DataTypePointer(this.CompileDataType.Type);
                DataTypePointer     sourceType = new DataTypePointer(_methodPointer.ReturnBaseType);
                IGenericTypePointer igp        = _methodPointer as IGenericTypePointer;
                if (igp != null)
                {
                    if (targetType.IsGenericType || targetType.IsGenericParameter)
                    {
                        DataTypePointer dtp = igp.GetConcreteType(targetType.BaseClassType);
                        if (dtp != null)
                        {
                            targetType = dtp;
                        }
                    }
                    if (sourceType.IsGenericType || sourceType.IsGenericParameter)
                    {
                        DataTypePointer dtp = igp.GetConcreteType(sourceType.BaseClassType);
                        if (dtp != null)
                        {
                            sourceType = dtp;
                        }
                    }
                }
                if (!targetType.IsAssignableFrom(sourceType))
                {
                    ce = CompilerUtil.GetTypeConversion(targetType, ce, sourceType, supprtStatements);
                }
            }
            return(ce);
        }
コード例 #4
0
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            CodeExpression ce;

            if (_valuePointer != null)
            {
                bool isWeb = false;
                if (_valuePointer.RootPointer != null)
                {
                    isWeb = _valuePointer.RootPointer.IsWebPage;
                }
                if (!IsField() && isWeb && this.IsWebClientValue())
                {
                    //this is a client property, use clientRequest.GetStringValue(DataPassingCodeName)
                    CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression(
                        new CodeVariableReferenceExpression("clientRequest"), "GetStringValue", new CodePrimitiveExpression(DataPassingCodeName));
                    ce = cmie;
                }
                else
                {
                    ce = _valuePointer.GetReferenceCode(method, method.MethodCode.Statements, _forValue);
                }
                ActualCompiledType = new MathExp.RaisTypes.RaisDataType(_valuePointer.ObjectType);
                if (CompileDataType != null)
                {
                    if (CompileDataType.Type != null && _valuePointer.ObjectType != null)
                    {
                        DataTypePointer     targetType = new DataTypePointer(CompileDataType.Type);
                        DataTypePointer     sourceType = new DataTypePointer(_valuePointer.ObjectType);
                        IGenericTypePointer igp        = _valuePointer as IGenericTypePointer;
                        if (igp != null)
                        {
                            if (targetType.IsGenericType || targetType.IsGenericParameter)
                            {
                                DataTypePointer dtp = igp.GetConcreteType(targetType.BaseClassType);
                                if (dtp != null)
                                {
                                    targetType = dtp;
                                }
                            }
                            if (sourceType.IsGenericType || sourceType.IsGenericParameter)
                            {
                                DataTypePointer dtp = igp.GetConcreteType(sourceType.BaseClassType);
                                if (dtp != null)
                                {
                                    sourceType = dtp;
                                }
                            }
                        }
                        if (!targetType.IsAssignableFrom(sourceType))
                        {
                            ce = CompilerUtil.GetTypeConversion(targetType, ce, sourceType, method.MethodCode.Statements);
                            ActualCompiledType = new MathExp.RaisTypes.RaisDataType(targetType.BaseClassType);
                        }
                    }
                }
            }
            else
            {
                ce = new CodeArgumentReferenceExpression(CodeName);
            }
            return(ce);
        }
コード例 #5
0
        public void ResolveGenericParameters(LimnorProject project)
        {
            MethodBase mb = MethodDef;

            if (mb != null)
            {
                if (_concreteReturnType == null && _returnType != null && (_returnType.IsGenericParameter || _returnType.IsGenericType))
                {
                    IGenericTypePointer igp = this.Owner as IGenericTypePointer;
                    if (igp != null)
                    {
                        _concreteReturnType = igp.GetConcreteType(_returnType);
                    }
                }
                if (TypeParameters == null && mb.ContainsGenericParameters && !(mb is ConstructorInfo))
                {
                    _genericParams = mb.GetGenericArguments();
                    if (_genericParams != null && _genericParams.Length > 0)
                    {
                        DlgSelectTypeParameters dlg = new DlgSelectTypeParameters();
                        dlg.LoadData(mb, project);
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            TypeParameters = dlg._holder.Results;
                        }

                        if (TypeParameters == null)
                        {
                            TypeParameters = new DataTypePointer[_genericParams.Length];
                            for (int i = 0; i < _genericParams.Length; i++)
                            {
                                TypeParameters[i] = new DataTypePointer(typeof(object));
                            }
                        }
                        if (_concreteReturnType == null && _returnType != null && (_returnType.IsGenericParameter || _returnType.IsGenericType))
                        {
                            if (_returnType.IsGenericType)
                            {
                                _concreteReturnType = new DataTypePointer(_returnType);
                                Type[] tcs = _returnType.GetGenericArguments();
                                if (tcs != null && tcs.Length > 0)
                                {
                                    _concreteReturnType.TypeParameters = new DataTypePointer[tcs.Length];
                                    for (int i = 0; i < tcs.Length; i++)
                                    {
                                        for (int k = 0; k < _genericParams.Length; k++)
                                        {
                                            if (_genericParams[k].Equals(tcs[i]))
                                            {
                                                _concreteReturnType.TypeParameters[i] = TypeParameters[k];
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (_returnType.IsGenericParameter)
                            {
                                for (int i = 0; i < _genericParams.Length; i++)
                                {
                                    if (_returnType.Equals(_genericParams[i]))
                                    {
                                        _concreteReturnType = TypeParameters[i];
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
 /// <summary>
 /// returns corresponding concrete type for the given generic argument or generic parameter
 /// </summary>
 /// <param name="typeParameter"></param>
 /// <returns></returns>
 public virtual DataTypePointer GetConcreteType(Type typeParameter)
 {
     if (typeParameter != null)
     {
         IObjectPointer op;
         if (TypeParameters != null)
         {
             if (typeParameter.IsGenericParameter || typeParameter.IsGenericType)
             {
                 MethodBase mb = MethodDef;
                 if (mb != null)
                 {
                     if (mb.ContainsGenericParameters)
                     {
                         Type[] tcs = mb.GetGenericArguments();
                         if (tcs != null && tcs.Length > 0)
                         {
                             for (int i = 0; i < tcs.Length; i++)
                             {
                                 if (tcs[i].Equals(typeParameter))
                                 {
                                     if (i < TypeParameters.Length)
                                     {
                                         return(TypeParameters[i]);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             op = this.Owner;
             IGenericTypePointer igp = null;
             while (op != null)
             {
                 igp = op as IGenericTypePointer;
                 if (igp != null)
                 {
                     break;
                 }
                 op = op.Owner;
             }
             if (igp != null)
             {
                 return(igp.GetConcreteType(typeParameter));
             }
         }
         LocalVariable lv = null;
         op = this.Owner;
         while (op != null)
         {
             lv = op as LocalVariable;
             if (lv != null)
             {
                 break;
             }
             op = op.Owner;
         }
         if (lv != null)
         {
             return(lv.GetConcreteType(typeParameter));
         }
     }
     return(null);
 }