如何获取从 .Net dll 中的 FoxPro 自定义类创建的对象的属性?
这是我的 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对象转换。请您解释一下好吗?
提前致谢....
This is my FoxPro class:
DEFINE CLASS clscem AS custom
Height = 102
Width = 212
publicproperty = "this is my initial value"
pubprop = ""
Name = "clscem"
ENDDEFINE
and this is my form1.scx code:
objSinif = CREATEOBJECT("SinifDeneme.Class")
donenObjSinif = objSinif.f_Metot(thisform.CLSCEM1)
thisform.command1.Caption = donenObjSinif.M_SitringProp
I am calling .NET dll as COM object from FoxPro. This is my .NET class of 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ı"
};
}
}
}
But I couldn't write the properties or fields of FoxPro object. Whereas I can set the property of C# object whicj was returned by f_Metot of DLL. Where is the problem to get object properties which is coming from FoxPro?
I don't know the COM object conversion. Would you please explain?
Thanks in advance....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Rick Strahl 做了 关于 VFP 和 .Net 之间的互操作的三部分文章 - 虽然它有点旧,但我希望您能在其中一篇中找到答案,可能第一个。
Rick Strahl did a three part article set on interop between VFP and .Net - although it's a little old, I would expect you will find your answer in one of them, probably the first.