Exemple #1
0
        public static TKTConstructorDesc SearchConstructor(TKTConstructorDesc desc, CnEnDict WordDict, Type ForType)
        {
            TKTConstructorDesc bracket2 = desc;

            if (WordDict != null && desc.Bracket.IsNameValue)
            {
                List <TKTProcArg> args = new List <TKTProcArg>();
                foreach (var arg in desc.Bracket.ListArgs)
                {
                    string     newArgName = WordDict.Get(arg.ArgName);
                    TKTProcArg newArg     = new TKTProcArg(newArgName, arg.ArgType, arg.ArgType.IsGenericType);
                    args.Add(newArg);
                }
                bracket2 = new TKTConstructorDesc(args);
            }
            ConstructorInfo[] constructorInfoArray = ForType.GetConstructors();
            foreach (ConstructorInfo ci in constructorInfoArray)
            {
                if (ci.IsPublic)
                {
                    TKTConstructorDesc bracketCi = ProcDescHelper.CreateProcBracket(ci);
                    if (bracketCi.Eq(bracket2))
                    {
                        return(bracketCi);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        public TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = MType.GetMethods( );

            foreach (var method in methodArray)
            {
                CodeAttribute procAttr = Attribute.GetCustomAttribute(method, typeof(CodeAttribute)) as CodeAttribute;
                if (procAttr == null)
                {
                    ExMethodInfo exMethod     = GclUtil.CreatExMethodInfo(method, this.ForType);
                    TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        return(typeProcDesc);
                    }
                }
                else
                {
                    ProcDescCodeParser parser = new ProcDescCodeParser();
                    parser.InitType(ForType, method);
                    TKTProcDesc typeProcDesc = parser.Parser(WordDict, procAttr.Code);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        ExMethodInfo exMethod = GclUtil.CreatExMethodInfo(method, this.ForType);
                        typeProcDesc.ExMethod = exMethod;
                        return(typeProcDesc);
                    }
                }
            }
            if (ParentMapping != null)
            {
                return(ParentMapping.SearchProc(procDesc));
            }
            return(null);
        }
Exemple #3
0
        //public override ZType CreateNewFor(Type forType)
        //{
        //    PureZType gcl = new PureZType(forType);
        //    return gcl;
        //}

        public override TKTConstructorDesc[] GetConstructors()
        {
            List <TKTConstructorDesc> list = new List <TKTConstructorDesc>();

            //TKTConstructorDesc bracket2 = desc;
            ConstructorInfo[] constructorInfoArray = this.SharpType.GetConstructors();
            foreach (ConstructorInfo ci in constructorInfoArray)
            {
                if (ci.IsPublic)
                {
                    TKTConstructorDesc bracketCi = ProcDescHelper.CreateProcBracket(ci);
                    list.Add(bracketCi);
                }
            }
            return(list.ToArray());
        }
Exemple #4
0
        public TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = MType.GetMethods(/*BindingFlags.DeclaredOnly*/);

            foreach (var method in methodArray)
            {
                if (ReflectionUtil.IsDeclare(MType, method))
                {
                    TKTProcDesc typeProcDesc = ProcDescHelper.CreateProcDesc(method);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        return(typeProcDesc);
                    }
                }
            }
            return(null);
        }
Exemple #5
0
        public TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = MType.GetMethods(/*BindingFlags.DeclaredOnly*/);

            foreach (var method in methodArray)
            {
                if (ReflectionUtil.IsDeclare(MType, method))
                {
                    MappingCodeAttribute procAttr = Attribute.GetCustomAttribute(method, typeof(MappingCodeAttribute)) as MappingCodeAttribute;
                    if (procAttr == null)
                    {
                        TKTProcDesc typeProcDesc = ProcDescHelper.CreateProcDesc(method);
                        if (typeProcDesc.Eq(procDesc))
                        {
                            return(typeProcDesc);
                        }
                    }
                    else
                    {
                        ProcDescCodeParser parser     = new ProcDescCodeParser();
                        ParameterInfo[]    paramArray = method.GetParameters();
                        foreach (var param in paramArray)
                        {
                            parser.AddType(param.ParameterType);
                        }
                        TKTProcDesc typeProcDesc = parser.Parser(WordDict, procAttr.Code);
                        if (typeProcDesc.Eq(procDesc))
                        {
                            typeProcDesc.Method = method;
                            return(typeProcDesc);
                        }
                    }
                }
            }
            return(null);
        }
Exemple #6
0
        public TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = MType.GetMethods();

            foreach (var method in methodArray)
            {
                if (ReflectionUtil.IsDeclare(MType, method))
                {
                    //ZCodeAttribute procAttr = Attribute.GetCustomAttribute(method, typeof(ZCodeAttribute)) as ZCodeAttribute;
                    Attribute[] attrs = Attribute.GetCustomAttributes(method, typeof(ZCodeAttribute));
                    if (attrs.Length == 0) // if (procAttr == null)
                    {
                        ExMethodInfo exMethod     = GclUtil.CreatExMethodInfo(method, this.ForType);
                        TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                        if (typeProcDesc.Eq(procDesc))
                        {
                            MethodInfo rmethod = method;
                            if (rmethod.IsAbstract)
                            {
                                rmethod = searchMethodByMethod(method);
                            }
                            if (rmethod == null)
                            {
                                return(null);
                            }
                            else
                            {
                                TKTProcDesc rdesc = ProcDescHelper.CreateProcDesc(exMethod);
                                return(rdesc);
                            }
                        }
                    }
                    else
                    {
                        ParameterInfo[] paramArray = method.GetParameters();

                        parser.InitType(ForType, method);
                        foreach (Attribute attr in attrs)
                        {
                            ZCodeAttribute zCodeAttribute = attr as ZCodeAttribute;
                            TKTProcDesc    typeProcDesc   = parser.Parser(WordDict, zCodeAttribute.Code);
                            if (method.IsStatic && !method.IsAbstract && typeProcDesc.HasSubject() &&
                                typeProcDesc.GetSubjectArg().ArgType == this.ForType)
                            {
                                typeProcDesc = typeProcDesc.CreateTail();
                            }
                            if (typeProcDesc.Eq(procDesc))
                            {
                                MethodInfo rmethod = method;
                                if (rmethod.IsAbstract)
                                {
                                    rmethod = searchMethodByMethod(method);
                                }
                                if (rmethod == null)
                                {
                                    return(null);
                                }
                                else
                                {
                                    ExMethodInfo exMethod = GclUtil.CreatExMethodInfo(rmethod, this.ForType);
                                    typeProcDesc.ExMethod = exMethod;
                                    return(typeProcDesc);
                                }
                            }
                        }
                    }
                }
            }
            if (isRootMapping())
            {
                return(null);
            }
            else
            {
                return(ParentMapping.SearchProc(procDesc));
            }
        }
        public TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = MType.GetMethods();

            foreach (var method in methodArray)
            {
                if (ReflectionUtil.IsDeclare(MType, method))
                {
                    CodeAttribute procAttr = Attribute.GetCustomAttribute(method, typeof(CodeAttribute)) as CodeAttribute;
                    if (procAttr == null)
                    {
                        ExMethodInfo exMethod     = GclUtil.CreatExMethodInfo(method, this.ForType);
                        TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                        if (typeProcDesc.Eq(procDesc))
                        {
                            MethodInfo rmethod = method;
                            if (rmethod.IsAbstract)
                            {
                                rmethod = searchMethodByMethod(method);
                            }
                            if (rmethod == null)
                            {
                                throw new RTException("方法与被翻译类型的方法不一致");
                            }
                            else
                            {
                                TKTProcDesc rdesc = ProcDescHelper.CreateProcDesc(exMethod);
                                return(rdesc);
                            }
                        }
                    }
                    else
                    {
                        ParameterInfo[] paramArray = method.GetParameters();

                        parser.InitType(ForType, method);
                        TKTProcDesc typeProcDesc = parser.Parser(WordDict, procAttr.Code);
                        if (method.IsStatic && !method.IsAbstract && typeProcDesc.HasSubject() && typeProcDesc.GetSubjectArg().ArgType == this.ForType)
                        {
                            typeProcDesc = typeProcDesc.CreateTail();
                        }
                        if (typeProcDesc.Eq(procDesc))
                        {
                            MethodInfo rmethod = method;
                            if (rmethod.IsAbstract)
                            {
                                rmethod = searchMethodByMethod(method);
                            }
                            if (rmethod == null)
                            {
                                throw new RTException("过程描述标注错误");
                            }
                            else
                            {
                                ExMethodInfo exMethod = GclUtil.CreatExMethodInfo(rmethod, this.ForType);
                                typeProcDesc.ExMethod = exMethod;
                                return(typeProcDesc);
                            }
                        }
                    }
                }
            }
            if (isRootMapping())
            {
                return(null);
            }
            else
            {
                return(ParentMapping.SearchProc(procDesc));
            }
        }
        public override TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = this.SharpType.GetMethods();

            foreach (var method in methodArray)
            {
                if (!ReflectionUtil.IsDeclare(SharpType, method))
                {
                    continue;
                }
                /* 映射类可能有多个同义的方法对应同一个实际方法 */
                ZCodeAttribute[] attrs = AttributeUtil.GetAttributes <ZCodeAttribute>(method);
                /* 编译器生成的类可能没有标注,没有标注的方法必定在ZMappingType上 */
                if (attrs.Length == 0)
                {
                    ExMethodInfo exMethod     = ZTypeUtil.CreatExMethodInfo(method, this.SharpType);
                    TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        TKTProcDesc rdesc = ProcDescHelper.CreateProcDesc(exMethod);
                        return(rdesc);
                    }
                }
                else if (attrs.Length > 0)
                {
                    ParameterInfo[] paramArray = method.GetParameters();
                    parser.InitType(SharpType, method);
                    foreach (ZCodeAttribute attr in attrs)
                    {
                        ZCodeAttribute zCodeAttribute = attr as ZCodeAttribute;
                        TKTProcDesc    typeProcDesc   = parser.Parser(zCodeAttribute.Code);
                        if (method.IsStatic && !method.IsAbstract && typeProcDesc.HasSubject() &&
                            typeProcDesc.GetSubjectArg().ArgType == this.SharpType)
                        {
                            typeProcDesc = typeProcDesc.CreateTail();
                        }
                        if (typeProcDesc.Eq(procDesc))
                        {
                            ExMethodInfo exMethod = null;// getExMethod(method);
                            /* 非 Abstract 的方法肯定从被映射的类中搜索 */
                            if (method.IsAbstract)
                            {
                                var method2 = searchMethodFromSharp(method);
                                exMethod = ZTypeUtil.CreatExMethodInfo(method2, this.SharpType);
                                //return exMethod;
                            }
                            else
                            {
                                exMethod = ZTypeUtil.CreatExMethodInfo(method, this.ZMappingType);
                                //return exMethod;
                            }
                            typeProcDesc.ExMethod = exMethod;
                            return(typeProcDesc);
                        }
                    }
                }
            }
            if (ParentMapping != null && !isRoot())
            {
                var epi = ParentMapping.SearchProc(procDesc);
                if (epi != null)
                {
                    //epi.IsSelf = false;
                    return(epi);
                }
            }
            return(null);
        }