VS 2010 Dll That Is Implemented By A Class With A Default Constructor

Dec 27, 2010

I have a base class which must be overriden. This base class sits in one dll shared by all. The derived classes will each be in their own dll such that the addition of a new derived class can be done by distributing a new dll. The set of dlls, and therefore the set of derived classes, will be discovered by the main program on startup. That's all pretty straightforward. The problem is that the main program needs to be able to query a database to figure out which type of derived class it needs, then create a class of that type. Naturally, it can't know which types will be available ahead of time because even I don't know that. The program has to be dynamically extensible.The obvious way to do this is to have an interface in the dll that is implemented by a class with a default constructor. The sole purpose of that class would be to return an object of the type (one of the derived types) defined in that dll. The derived types can't really be this class, because they can't have a default constructor since the base class doesn't have a default constructor, and the derived class can't make up the arguments that the base class constructor needs.

So basically, each dll that houses a derived class would also house a simple class that implemented an interface for the sole purpose of creating that particular derived class. The main program would examine the dll to find a class that implemented the interface, and once it found one, it could ask it what type of class it created, or it could ask it to create an instance of that class. It seems like there ought to be an easier way to dynamically add new classes to the project. It seems like the derived class ought to be able to tell the main project what type it was. This could be done, except that the derived class would have to exist before any of its methods could be called unless the methods were shared. Since you can't have a shared method in an interface, the interface itself would make no sense at that point, in which case I would need to discover whether the class in the dll derived from the base class in the second dll, just to figure out whether or not I wanted to create it. That's getting convoluted by now, so I guess I'll leave it there. The basic point is that the base class is known to the main program from a common dll. The number and types of derived classes can't be known at this time, so the program has to be able to discover them dynamically. Each derived class will sit in its own dll (or there could be more than one in a dll), and has to be discovered, and instances created, as needed, by the main program.

View 2 Replies


ADVERTISEMENT

VS 2008 - Creating Default Constructor Within Class

Feb 3, 2010

I'm doing a lab for school, and I came across something I have never done before: create a default constructor within my class. It involves creating a private field to store the connection string, then create a default constructor that sets the connection string.

Here is what I have so far:
Public Class Appointments
Private sqlconnection As String = ConfigurationSettings.AppSettings("ConnectionString")
Private Property connectionstring() As String
Get
Return sqlconnection
[Code] .....

View 3 Replies

VS 2010 How To Eliminate Default Constructor

Jan 19, 2011

I have written a number of classes in my time in VB.NET which set the basic elements in a custom New constructor through parameters. This makes things easier and enforces discipline. However, using Public Sub New() becomes pointless. If someone else tried to use this class, he or she could make a mess of it all by using Sub New without the arguments. I'd like to remove this method but I haven't found out how. I could make it raise an exception, but that somehow seems unseemly. I'd like a neater way. Does anyone know how?

View 22 Replies

Pass A Delegate Into A Constructor Of An Abstract Class From A Descendant's Constructor?

Feb 15, 2010

I have an abstract class which requires a delegate to function. I pass the delegate into the constructor. Now that I have a non default constructor I need to call the abstract class's constructors from the concrete class which means that I need to use MyBase.New(...). I have included a quick example below.

Public MustInherit Class BaseClass
Public Delegate Sub WorkMethod()
Private _Work As WorkMethod

[code]....

I have tried to do this but I keep getting the following error: "Implicit reference to object under construction is not valid when calling another constructor".Can I not do what I am trying to do above? I initially had the delegate setup in its own setter method. But then I am creating a deceptive API because it does require a point to a method to work properly.

View 3 Replies

VS 2010 Pass By Reference To Constructor Of A Class?

Feb 11, 2012

Implementing a simple MVC in vb. The controller instance creates and holds instances of the model and view:

Public Class Controller
Public Property myModel As Model
Public Property myView As View

[code].....

View 7 Replies

INotifyPropertyChanged.PropertyChanged Implemented And Not Implemented; Visual Studio Build Error

Jan 2, 2012

I'm seeing a strange build bug a lot. Sometimes after typing some code we receive the following build error.

Class 'clsX' must implement 'Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs)' for interface System.ComponentModel.INotifyPropertyChanged'.

And

'PropertyChanged' cannot implement 'PropertyChanged' because there is no matching event on interface 'System.ComponentModel.INotifyPropertyChanged'.

Those error should never go together! Usually we can just ignore the exception and build the solution but often enough this bug stops our build. (this happens a lot using Edit and Continue which is annoying)Removing the PropertyChanged event and retyping the same code! sometimes fixes this.We're using a code generator that causes this error to surface but just editing some files manually triggers this exception too. This error occur's on multiple machines using various setups.

View 4 Replies

Default Value At Declaration Or In Constructor?

Mar 4, 2011

One would think I'd already know this, but I never really gave it much thought before now. When declaring a member variable for a class, is it better to set the default value at the declaration

Private m_strMyVariable As String = ""
Or is it better to do it in the constructor
Private m_strMyVariable As String

[Code]....

Should I maybe always specify a value at declaration, even if it's Nothing, and just override that value in the constructor(s) as needed? Or is it situation specific? If so, a really quick rundown of which situations might warrant which treatment would be nice.

View 4 Replies

Interface Be Implemented Across An Aggregate/composite Class In .net?

Mar 30, 2010

VB.NET .NET 3.5 I have an aggregate class called Package as part of a shipping system. Package contains another class, BoxType . BoxType contains information about the box used to ship the package, such as length, width, etc. of the Box.

Package has a method called GetShippingRates. This method calls a separate helper class, ShipRater, and passes the Package itself as an argument. ShipRater examines the Package as well as the BoxType, and returns a list of possible shipping rates/methods.

What I would like to do is construct an Interface, IRateable, that would be supplied to the helper class ShipRater. So instead of:

[Code]...

However, ShipRater requires information from both the Package and its aggregate, BoxType. If I write an interface IRateable, then how can I use the BoxType properties to implement part of the Interface?

View 2 Replies

C# - MVVM ViewModel Default Constructor?

May 25, 2011

I have been getting up to speed with the MVVM pattern in Silverlight and was wondering how to implement binding from the View to the ViewModel when the ViewModel constructor has a parameter if an interface type.If I bind the viewmodel to the view in XAML then you can not use a parameterised constructor. Given that I was creating a default constructor passing an instance to the parameterised constructor but this breaks the abstraction.

View
<navigation:Page x:Class="QSmart.DataViewer.Report.RecentFailures.Report"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

[code]....

Is it recommended to use the code behind of the view to pass into the parameterised constructor and then bind to the viewmodel?

View 1 Replies

Access To Object Passed ByRef In The Constructor Of A Class Through Another Part Of The Class?

Aug 18, 2009

I have some classes, BsfciFile and StudyFlashCard. Bsfci is the extension to which I save my set of flashcards in an INI format. I am currently working to transform my code from using Windows API calls to access the INI to using a IniFile class that I found on the internet. I would like the BsfciFile to have a Array of StudyFlashCard objects, but I would like the StudyFlashCard class to use the IniFile class object contained in the BsfciFile class. I can pass the IniFile from the BsfciFile class to the constructor for the StudyFlashCard class, but I want it to modify the same IniFile as the BsfciFile class has later on.

[Code]...

View 1 Replies

Winforms : Where Is Default Constructor Of A Windows Form

Jan 1, 2011

where can I find the default constructor of a windows form? I mean:

Public Sub New()

End Sub

I should say that I Use Visual Studio 2008 as my editor.

View 3 Replies

.net - Why Can't Access The Backing Field On An Auto Implemented Property From Within An Inherited Class

Dec 20, 2011

I have a class that exposes an auto implemented property Enabled

[Code]...

But If I had not use an auto implemented property and declared my own backing-field as follows this is accessible from the subclass: Private _Enabled as Boolean ---- EDIT ----
The abve line is incorrect - this is not possible, it was in fact Protected in the original code which allowed access from the sub class See @JonSkeet answer ---- EDIT Of course I can just access Enabled from the sub class to work around this but can someone explain why this is the behaviour?

View 2 Replies

VS 2010 Disable Default Class Members And Methods?

Mar 13, 2011

Is there a way to disable the default members and methods inherited from the base class?

I made some classes in which elements like "Equals" and "ReferenceEquals" are confusing or I don't want them to show, or I have other methods providing similar functionality with different names and I don't want to override and use the default name.

View 3 Replies

VS 2010 Comments On Strategy Pattern Implemented

May 18, 2012

a debate has been sparked here about the use of the strategy pattern in my classes.
Basically, I have a 'Shape' object that is an interface 'IShape'. We have 'Circle', 'Rectangle' and 'Elongated' that are the concrete classes that must implement the IShape interface.

[Code]...

View 3 Replies

Implement Class Constructor In VB?

Jul 19, 2010

I just would like to know how to implement class constructor in this language.

View 2 Replies

Set Properties Of A Class Only Through Constructor

Mar 1, 2010

I am trying to make the properties of class which can only be set through the constructor of the same class

View 7 Replies

Construction - Inherit A Class That Also Has A Constructor

Mar 15, 2010

i'm working with different classes and different constructors. It's working fine until i try to inherit a class that also has a constructor. vb asks for mybase.new but when i add that vb says that a constructor cannot call itself, when i try it in a different way vb asks the parameters of the constructor of the class that i want to inherit.

View 11 Replies

Declare New Bitmap In Class' Constructor?

Jun 6, 2009

i've declared a bitmap at class level + i want to load an image into that variable in the constructor. i don't know why but it won't work and everything i've tried won't work either.am i missing a reference or something?

[Code]...

View 2 Replies

Overloaded Constructor In Abstract Class

Nov 19, 2010

I have an abstract class in vb.net with two subclasses. In the abstract class I have a constuctor that looks like this:[code]I would like to create a second constructor that doesn't take any arguments and just initializes the args to default values.[code]When I attempt to create a new subclass using the second constructor the compiler complains that I'm missing two args to the constructor.Is there a reason I can't overload the constructor in the abstract class?

View 2 Replies

Use Constructor In A Custom Collections Class?

Mar 1, 2010

I have a custom collection class that I would like to pre-populate with data from the database. Basically it would search for "submembers" that are related to the "member" data record using the "member"'s primary key id.

I figured the best way to do this would be in the constructor of the class, but I am not so sure now. The collection class does not have any properties (the member class does).[code]...

View 4 Replies

Custom Class Constructor Needs To Be Able To Return Error

Mar 12, 2010

I'm making a class that reads a file and processes data in it, but I need some error handling. I'm giving it a constructor that takes a file location and processes that file. How can I make it so the constructor tells the program whether it found the file or not? Optimistically the program that calls this class would check for that first, but since I'm not going to be the only one that uses this class I'd like to know how to secure such a thing. It's probably bad practice to do this within the class, but I'd like to be sure it's as portable as possible.

View 6 Replies

Event Raised In Constructor Cannot Be Handled Outside Very Class

Oct 26, 2009

I discovered that an event raised (directly on indirectly) in the constructor cannot be handled outside the very class. To prove if that was the actual problem, I wrote a simple exemplary app.
Class with the event:
Namespace Utils
Public Class A
Public Event Test()
Public Sub New()
CallTest()
[Code] .....
The reason of such behavior became quite obvious after writing those pieces, but maybe there is a way to omit it?

View 2 Replies

Method To Be Called In Child Class Constructor

Nov 11, 2009

How do I force the Visual Studio compiler to generate an error when a required method is not being called in the constructor of a child class? Like when you edit the form designer code, the compiler complains when InitializeComponent()isn't the first call in the constructor of a form. Is this even possible in VB.NET?

View 2 Replies

Naming Convention For Variables In Class Constructor

Nov 26, 2010

In the past when I have written classes and constructors, I named the variables in the constructor parameter something different than what would have been stored in the actual class itself.What I do now is name them the same, and reference the internal variables with Me.varname.Here is a class I just started building.Is my naming convention incorrect? [code]

View 1 Replies

Partial Mock Of A Class With Private Constructor

Sep 9, 2011

I am trying to write some unit tests on a class that looks like this, using Moq [code] the parameterized constructor is private or internal one of the two methods relies on the result of the other.I want to check that when GetThisOrThat is called with a value, it actually calls GetThis. But I also want to mock GetThis so that it returns a specific well-known value.To me this is an example of Partial Mocking, where we create a Mock based on a class, passing the parameters for the constructor. The problem here is that there is no public constructor, and therefore, Moq can not call it..I tried using the Accessors generated by Visual Studio for MSTest, and use those accessors for the mocking, and this is what I came up with [code]

View 1 Replies

Set ReadOnly Field In Constructor Of Inherited Class

Apr 1, 2012

[Code]...

Is there an explanation for this limitation? I mean, it's still in the constructor for the object, and the base class constructor is still executed first.

View 1 Replies

Constructor - Whats The Best Way To Initialize Shared Members In A Class In VB.Net?

Dec 8, 2010

I was looking on the interweb to see if there were any good examples on how to initialize shared members within a class while still initializing instance variables. I did find an expression that might fit to the answer:

[code]...

How do I initialize both instance and shared members without re-initializing the shared members every time an object is created from a class? Thanks!

View 2 Replies

Make Constructor Public And Allow Anybody To Create An Instance Of Class?

Apr 6, 2009

I have a class inside a class.I need to expose the properties of the 2nd class to other classes, therefore it is public.However, I do not wish other classes to be able to create instances of this 2nd class, it should only be instantitated from its parent class.I thought I could resolve this issue by making the constructor of the 2nd class private, but this even prevents the parent class from instantiating its child class! How can I work around this, do I have to make the constructor public and allow anybody to create an instance of the class?

View 3 Replies

C# - WINFORM Or WPF: Trigger Custom Event Inside The Constructor Of The Class That Emits It?

Nov 17, 2009

I have a userControl11 (either in winform or wpf) which has a ValueChanged custom event. If I put it in client form and in form_load set its value to 100, it will trigger the ValueChanged event. But if I set this value inside the constructor of UserControl1 the custom event won't trigger. How can I force it to do so ?whatever the technical reason, functionally it does make sense. If the object is initializing its value from some sources unknown to the client form and the client form has a textbox bound to this usercontrol value, it is sure convenient that it could refresh its textbox at any time including when the form loads just using one single event handler. Without this the client form has to create another initializer for this bound textbox at form load.

Below the source code of my trials in winform:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[code]....

View 4 Replies

Put The XMLSerializer Behind A 'facade' Class That User Won't Have To Supply Type Info To The Constructor?

Mar 19, 2012

I wish to put the XMLSerializer behind a 'facade' class of mine so that user wont have to supply type info to the constructor. But doing this has a problem. Consider this class:

Class XmlFormatter
Private Shared xs As XmlSerializer
Public Function Deserialize(ByVal serializationStream As Stream) As Object
Dim o As Object = Nothing

[code]....

The problem is that the user of this class cannot use Deserialize without first using Serialize because the XMLSerializer instance is created in Serialize and it is shared. But using Deserialize without this instance will simply return Nothing.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved