[英]How to get properties of object which has been created from FoxPro custom class in .Net dll?
This is my FoxPro class: 这是我的FoxPro类:
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: 这是我的form1.scx代码:
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. 我正在从FoxPro调用.NET dll作为COM对象。 This is my .NET class of DLL: 这是我的.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ı"
};
}
}
}
But I couldn't write the properties or fields of FoxPro object. 但是我无法编写FoxPro对象的属性或字段。 Whereas I can set the property of C# object whicj was returned by f_Metot of DLL. 鉴于我可以设置C#对象的属性,而whi是由DLL的f_Metot返回的。 Where is the problem to get object properties which is coming from FoxPro? 获取来自FoxPro的对象属性的问题在哪里?
I don't know the COM object conversion. 我不知道COM对象转换。 Would you please explain? 你能解释一下吗?
Thanks in advance.... 提前致谢....
里克·斯特拉尔(Rick Strahl) 在VFP和.Net之间的互操作方面做了三篇文章 -尽管它有些陈旧,但我希望您能在其中一个(也许是第一个)中找到答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.