createinstance

C# Activator createInstance for extending class

笑着哭i 提交于 2020-01-16 00:58:07
问题 I have a base class, which is as follows: public Data() { id = num++; SetVariables(); } //fill every Variable varNames, parseInduction, noise, seperator in Children Classes public Data(String line) { //first declare all variables in sub classes if (id == 0) throw new NotSupportedException("You are not allowed to use this constructor for creating the first instance!"); id = num++; SetVariables(); parseLine(line); } And i also have a Sub Class extending this Class. class DienstGruppe : Data {

How can I pass an argument to a C# plug-in being loaded through Assembly.CreateInstance?

大憨熊 提交于 2020-01-02 04:12:09
问题 What I have now (which successfully loads the plug-in) is this: Assembly myDLL = Assembly.LoadFrom("my.dll"); IMyClass myPluginObject = myDLL.CreateInstance("MyCorp.IMyClass") as IMyClass; This only works for a class that has a constructor with no arguments. How do I pass in an argument to a constructor? 回答1: You cannot. Instead use Activator.CreateInstance as shown in the example below (note that the Client namespace is in one DLL and the Host in another. Both must be found in the same

CLSIDFromProgID is successful but CreateInstace fails! Why?

帅比萌擦擦* 提交于 2019-12-24 10:56:36
问题 I am trying to create an instance of a COM object. I have the class name that implements the interface and I get a CLSID by using CLSIDFromProgID(). So since I am getting a CLSID I thought everything should be fine from now on. However when I do a call to CreateInstance and pass in the CLSID, I get an error saying "Class not registered". Also I get this error only in some computers. It runs error free on several computers. I don't understand where the problem could be. Is my registry dirty?

Factory Pattern in C++: generating explicit createInstance()-Method automatically

為{幸葍}努か 提交于 2019-12-23 03:21:34
问题 i have the problem in writing a C++ framework, that users should have less overhead than possible to use it. Users can publish their work to the frameworks by creating a shared library that contains a class, which is derived by a frameworks' BaseClass and implementing an extern "C" createInstance()-method in order to return an instance its' derived class. So the framework can access the user class by calling the createInstance-Method through the shared library with dlsym(). class BaseClass{}

Stuck with “Cannot find type” error using CreateInstance()

淺唱寂寞╮ 提交于 2019-12-23 01:11:25
问题 I am trying to use .CreateInstance() in a connection utility in a C# project, while serializing XML. .Unwrap() is used to unwrap the serializable return type and get an instance of the type I'm trying to create. String fileToLoad = @"D:\RPMOpen\svnCobra\conversion\aui\Model\bin\Debug\RPM_Model"; String file = Path.GetFileName(fileToLoad); AbstractResponseMessageData response = (AbstractResponseMessageData)Activator.CreateInstance(file, responseName).Unwrap(); My assembly RPM_Model at @"D:

Stuck with “Cannot find type” error using CreateInstance()

北城以北 提交于 2019-12-23 01:11:09
问题 I am trying to use .CreateInstance() in a connection utility in a C# project, while serializing XML. .Unwrap() is used to unwrap the serializable return type and get an instance of the type I'm trying to create. String fileToLoad = @"D:\RPMOpen\svnCobra\conversion\aui\Model\bin\Debug\RPM_Model"; String file = Path.GetFileName(fileToLoad); AbstractResponseMessageData response = (AbstractResponseMessageData)Activator.CreateInstance(file, responseName).Unwrap(); My assembly RPM_Model at @"D:

System.Activator.CreateInstance returning null

孤街醉人 提交于 2019-12-12 09:48:44
问题 The problem I have is that CreateInstance returns null. Here is the code: if(spattmono[0] != null) { if((SpecialAttack) System.Activator.CreateInstance( spattmono[0].GetClass()) == null) { Debug.Log("DUMB ACTIVATOR!!!"); } //combo.SetSpecialAttack(spattack); } Attack and SpecialAttack are both classes that store basic information, and inherit from UnityEngine.Object . Attmono and spattmono are both MonoScript arrays, attmono being able to hold 16 and spattmono being able to hold 4. They get

Is it possible to dynamically create form without having *.dfm and *.pas files?

穿精又带淫゛_ 提交于 2019-12-10 13:39:18
问题 is it possible to create and show TForm without having source files for it ? I want to create my forms at runtime and having the empty *.dfm and *.pas files seems to me useless. Thank you 回答1: Do you mean like this? procedure TForm1.Button1Click(Sender: TObject); var Form: TForm; Lbl: TLabel; Btn: TButton; begin Form := TForm.Create(nil); try Form.BorderStyle := bsDialog; Form.Caption := 'My Dynamic Form!'; Form.Position := poScreenCenter; Form.ClientWidth := 400; Form.ClientHeight := 200;

Factory Pattern in C++: generating explicit createInstance()-Method automatically

家住魔仙堡 提交于 2019-12-09 02:14:31
i have the problem in writing a C++ framework, that users should have less overhead than possible to use it. Users can publish their work to the frameworks by creating a shared library that contains a class, which is derived by a frameworks' BaseClass and implementing an extern "C" createInstance()-method in order to return an instance its' derived class. So the framework can access the user class by calling the createInstance-Method through the shared library with dlsym(). class BaseClass{} class UserClass : public BaseClass{} extern "C"{ BaseClass* UserXcreateInstance(){ return new UserClass

c# why can't I upcast to my plug-in's base class?

女生的网名这么多〃 提交于 2019-12-08 08:32:06
问题 I have a solution which creates DLLs and another one which consumes them. It is a Toolbox which can load various tools as plug-ins. At first things go well: These are the two classes, both in separate cs files: namespace PIClasses { public class PI_base : UserControl { public PI_base() { } public string Description { get; set; } public string Version { get; set; } private void InitializeComponent() { this.SuspendLayout(); this.Name = "PI_base"; this.ResumeLayout(false); } } } namespace