簡體   English   中英

如何獲取已從.Net dll中的FoxPro自定義類創建的對象的屬性?

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

這是我的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ı"
                   };
        }
    }
}

oj參數QuickWatch屏幕Oj參數的GetType()方法

但是我無法編寫FoxPro對象的屬性或字段。 鑒於我可以設置C#對象的屬性,而whi是由DLL的f_Metot返回的。 獲取來自FoxPro的對象屬性的問題在哪里?

我不知道COM對象轉換。 你能解釋一下嗎?

提前致謝....

里克·斯特拉爾(Rick Strahl) 在VFP和.Net之間的互操作方面了三篇文章 -盡管它有些陳舊,但我希望您能在其中一個(也許是第一個)中找到答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM