【问题标题】:How to get properties of object which has been created from FoxPro custom class in .Net dll?如何获取从.Net dll 中的 FoxPro 自定义类创建的对象的属性?
【发布时间】:2011-12-10 23:15:59
【问题描述】:

这是我的 FoxPro 课程:

DEFINE CLASS clscem AS custom


Height = 102
Width = 212
publicproperty = "this is my initial value"
pubprop = ""
Name = "clscem"


ENDDEFINE

这是我的 form1.scx 代码:

objSinif = CREATEOBJECT("SinifDeneme.Class")
donenObjSinif = objSinif.f_Metot(thisform.CLSCEM1)
thisform.command1.Caption = donenObjSinif.M_SitringProp

我从 FoxPro 调用 .NET dll 作为 COM 对象。这是我的 .NET 类 DLL:

using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace ClsLib
{
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ProgId("SinifDeneme.Class")]
    [ComVisible(true)]
    public class Sinif
    {
        public string SitringField;
        public string M_SitringProp { get; set; }
        public Sinif f_Metot(object oj)
        {
            StreamWriter sw = File.CreateText(Path.GetDirectoryName(Assembly.GetAssembly(typeof(Sinif)).Location )+ "\\obje.txt");

            Type myObjectType = oj.GetType();

            //Get public properties
            PropertyInfo[] propertyInfo = myObjectType.GetProperties();
            sw.WriteLine("------------- PROPERTY --------------");
            foreach (PropertyInfo info in propertyInfo)
            {
                sw.WriteLine("Name:"+info.Name);
                sw.WriteLine("PropertyType:"+info.PropertyType);
                sw.WriteLine("GetValue():" + info.GetValue(oj,null));
                sw.WriteLine("-------------");
            }

            FieldInfo[] fieldInfo = myObjectType.GetFields();
            sw.WriteLine("------------- FIELDS --------------");
            foreach (FieldInfo info in fieldInfo)
            {
                sw.WriteLine("Name:" + info.Name);
                sw.WriteLine("AssemblyQualifiedName:" + info.FieldType.AssemblyQualifiedName);
                sw.WriteLine("GetValue():" + info.GetValue(oj));
                sw.WriteLine("-------------");
            }

            sw.Flush();
            sw.Close();
            sw.Dispose();



            return new Sinif()
                   {
                       M_SitringProp="SitringProp propertisi",
                       SitringField="Sitring fieldı"
                   };
        }
    }
}

但我无法编写 FoxPro 对象的属性或字段。而我可以设置由 DLL 的 f_Metot 返回的 C# 对象的属性。获取来自 FoxPro 的对象属性的问题在哪里?

我不知道 COM 对象转换。请解释一下好吗?

提前谢谢....

【问题讨论】:

    标签: c# com foxpro visual-foxpro


    【解决方案1】:

    Rick Strahl 做了a three part article set on interop between VFP and .Net - 虽然它有点旧,但我希望你会在其中一个中找到答案,可能是the first

    【讨论】:

      猜你喜欢
      • 2012-06-08
      • 2021-02-10
      • 2012-09-15
      • 2011-01-20
      • 1970-01-01
      • 2019-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多