Как получить свойства объекта, который был создан из пользовательского класса FoxPro в .Net dll? - PullRequest
0 голосов
/ 11 декабря 2011

Это мой класс 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

Я вызываю .NET dll как COM-объект из FoxPro. Это мой класс .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ı"
                   };
        }
    }
}

The oj parameter QuickWatch screen Oj parameter's GetType() method

Но я не мог написать свойства или поля объекта FoxPro. Тогда как я могу установить свойство объекта C #, которое было возвращено f_Metot DLL. В чем проблема получения свойств объекта от FoxPro?

Я не знаю преобразование COM-объекта. Не могли бы вы объяснить?

Заранее спасибо ....

1 Ответ

1 голос
/ 12 декабря 2011

Рик Страл сделал статью из трех частей о взаимодействии между VFP и .Net - хотя она немного устарела, я ожидаю, что вы найдете ответ в одном из них, вероятно, в первом .

...