vendredi 15 février 2019

Abstract class inherit using reflection

there is an abstract class in a DTSearch dll then i have to access this abstract class using reflection method.How? there is an abstact class named as "Datasource" in DTSearch.

dtIndexJob.DataSourceToIndex is of type "Datasource"; how can i assign this property dynamically.

sVaultPath = "E:\\New folder";
            sdtSearchAppPath = "C:\\Program Files (x86)\\dtSearch Developer\\bin\\dtSearchNetApi2.dll";
            sIndexPath = "E:\\indexing";
            dtSearchAssembly = Assembly.LoadFrom(sdtSearchAppPath);
            dtIndexJob = dtSearchAssembly.CreateInstance("dtSearch.Engine.IndexJob");


            string name = "DataSource";
            string property = "DataSource";
            string value = "Baz";

            // Get the type contained in the name string



           // object ob 
                Type type= dtSearchAssembly.GetType("dtSearch.Engine.DataSource");
            //type = typeof()

            PropertyInfo[] propInfos
                = type.GetProperties(BindingFlags.Instance
                    | BindingFlags.Public
                    | BindingFlags.DeclaredOnly);


           // PropertyInfo prop = type.GetProperty(property);

            // Set the value of the given property on the given instance
            //prop.SetValue(instance, value, null);


           // dataSource = dtSearchAssembly.CreateInstance(prop.GetType().FullName);
            dataSource.Folder = sVaultPath;
            if (!dataSource.Rewind())
            {
                iRet = 0;
                return iRet;
            }


            dtIndexJob.ActionCreate = true;
            dtIndexJob.ActionAdd = true;
            dtIndexJob.IndexPath = sIndexPath;
            dtIndexJob.StoredFields = new System.Collections.Specialized.StringCollection();
            dtIndexJob.StoredFields.Add("*");
            dtIndexJob.DataSourceToIndex = dataSource;





Aucun commentaire:

Enregistrer un commentaire