コード例 #1
0
        static void UpdateComObj(ref Comobjectstorage comobj, Type t)
        {
            List <string> props      = new List <string>();
            var           properties = t.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo propinfo in properties)
            {
                if (propinfo.DeclaringType != t)
                {
                    continue;
                }

                Comobjectstorage.classprops comprop = new Comobjectstorage.classprops();
                comprop.returntype = propinfo.PropertyType.Name;
                comprop.name       = propinfo.Name;
                comprop.bget       = propinfo.CanRead;
                comprop.bset       = propinfo.CanWrite;
                comobj.props.Add(comprop);
                props.Add("get_" + propinfo.Name);
                props.Add("set_" + propinfo.Name);
            }

            var methods = t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod);

            foreach (MethodInfo mtdinfo in methods)
            {
                if (mtdinfo.DeclaringType != t)
                {
                    continue;
                }

                if (props.Contains(mtdinfo.Name))
                {
                    continue;
                }

                Comobjectstorage.classmtds mtd = new Comobjectstorage.classmtds();
                mtd.name       = mtdinfo.Name;
                mtd.returntype = mtdinfo.ReturnType.Name;
                foreach (System.Reflection.ParameterInfo pi in mtdinfo.GetParameters())
                {
                    Comobjectstorage.paramtr para = new Comobjectstorage.paramtr();
                    para.name = pi.Name;
                    int len = pi.ParameterType.Name.Length;
                    para.vartype = pi.ParameterType.Name;
                    if (pi.ParameterType.Name[len - 1] == '&')
                    {
                        para.vartype = pi.ParameterType.Name.Substring(0, len - 1);
                        para.bout    = pi.IsOut;
                        para.bref    = !para.bout;
                    }
                    mtd.pars.Add(para);
                }
                comobj.mtds.Add(mtd);
            }
        }
コード例 #2
0
        static void GatherDataFromTLB(Comobjectstorage comobj)
        {
            TLI.TLIApplication tli = new TLI.TLIApplication();
            TypeLibInfo        ti  = tli.TypeLibInfoFromFile(comobj.path);

            foreach (CoClassInfo cc in ti.CoClasses)
            {
                string progid = comobj.progid;
                if (progid != "")
                {
                    int k = progid.IndexOf('.');
                    if (k != -1)
                    {
                        comobj.namesp = progid.Substring(0, k);
                        comobj.name   = progid.Substring(k + 1).Replace('.', '_');
                    }
                }
                if (comobj.clsid.ToString("B").ToLower() != cc.GUID.ToLower())
                {
                    continue;
                }

                comobj.clsid    = new Guid(cc.GUID);
                comobj.wcfclsid = Guid.NewGuid();

                foreach (TLI.MemberInfo minf in cc.DefaultInterface.Members)
                {
                    if (minf.AttributeMask != 0)
                    {
                        continue;
                    }

                    InvokeKinds functype = minf.InvokeKind;
                    if (functype != TLI.InvokeKinds.INVOKE_FUNC && functype != TLI.InvokeKinds.INVOKE_PROPERTYGET &&
                        functype != TLI.InvokeKinds.INVOKE_PROPERTYPUT && functype != TLI.InvokeKinds.INVOKE_PROPERTYPUTREF)
                    {
                        continue;
                    }

                    if (functype != TLI.InvokeKinds.INVOKE_FUNC)
                    {
                        Comobjectstorage.classprops prop = comobj.findproperty(minf.Name);
                        if (prop == null)
                        {
                            prop            = new Comobjectstorage.classprops();
                            prop.name       = minf.Name;
                            prop.returntype = VarianttoManaged(minf.ReturnType);
                            comobj.props.Add(prop);
                        }
                        if (functype == TLI.InvokeKinds.INVOKE_PROPERTYGET)
                        {
                            prop.bget = true;
                        }
                        else if (functype == TLI.InvokeKinds.INVOKE_PROPERTYPUT || functype == TLI.InvokeKinds.INVOKE_PROPERTYPUTREF)
                        {
                            prop.bset = true;
                        }

                        foreach (TLI.ParameterInfo pmi in minf.Parameters)
                        {
                            Comobjectstorage.paramtr par = new Comobjectstorage.paramtr();
                            par.name    = pmi.Name;
                            par.vartype = VarianttoManaged(pmi.VarTypeInfo);
                            par.bref    = false;
                            if (pmi.VarTypeInfo.PointerLevel != 0)
                            {
                                par.bref = true;
                            }
                            (functype == TLI.InvokeKinds.INVOKE_PROPERTYGET ? prop.getpars : prop.setpars).Add(par);
                        }
                    }
                    else
                    {
                        Comobjectstorage.classmtds mtd = new Comobjectstorage.classmtds();
                        mtd.name = minf.Name;

                        mtd.returntype = VarianttoManaged(minf.ReturnType);
                        foreach (TLI.ParameterInfo pmi in minf.Parameters)
                        {
                            if (pmi.Name == "OptionalArgs" && !bincoptional)
                            {
                                continue;
                            }
                            Comobjectstorage.paramtr par = new Comobjectstorage.paramtr();
                            par.name    = pmi.Name;
                            par.vartype = VarianttoManaged(pmi.VarTypeInfo);
                            par.bref    = false;
                            if (pmi.VarTypeInfo.PointerLevel != 0)
                            {
                                par.bref = true;
                            }
                            mtd.pars.Add(par);
                        }
                        comobj.mtds.Add(mtd);
                    }
                }
            }
        }