简体   繁体   中英

How to get properties of object which has been created from FoxPro custom class in .Net dll?

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ı"
                   };
        }
    }
}

oj参数QuickWatch屏幕Oj参数的GetType()方法

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....

里克·斯特拉尔(Rick Strahl) 在VFP和.Net之间的互操作方面了三篇文章 -尽管它有些陈旧,但我希望您能在其中一个(也许是第一个)中找到答案。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM