Generic Inherited Class Definition
Jan 11, 2010I'm having trouble with the definition of an inherited generic class. I have two base classes that are defined like this:[code]
View 2 RepliesI'm having trouble with the definition of an inherited generic class. I have two base classes that are defined like this:[code]
View 2 RepliesI can do this without problem.
Class A
End Class
Class B : Inherit A
End Class
Dim Obj1 As A = New B
I use jQuery ajax calls to ASP.Net web services (ASMX files) to update the web page data.
I have the database storing code seperate from the domain object class code (in the example code below, there is an Animal class and an AnimalRepository class). I'm implememting a convention that all similar domain object repository classes will have a Store method .
I would like to create a web service that can cater for calling the Store method for any one of these repository classes. To get this to work, in the below code sample, the List(Of Animal) parameter would need to be a generic type.[code]...
In our current project I am using a generic interface iService which is inherited by all other service interfaces. For instance IService is inherited by ILogService.
The ILogService interface is then implemented by LogService as below:
Public Interface IService(Of T)
Sub Save(ByVal T As IEntity)
Sub Remove(ByVal T As IEntity)
[Code]....
How can I update the method signature so T is displayed as Log?
If we are within the derived class then ofcource we can use MyBase keyword to access base class's object reference . That's fine , how can we take that base class's object reference outside that derived class's definition.My following code will explain what i want . Actually that is giving error right now, but it is explaining my requirement .
Public Class Base
Public x As String
End Class
[code]....
Actually there is error in ReadOnly Property BaseReference's Getter . Error is "Error 1 'MyBase' must be followed by '.' and an identifier. " how can i get base class object reference in Main method ?
Consider:
Public MustInherit Class Column
Public ReadOnly Property ReturnSomethingUseful() As Object
Get
'return something useful
[code]....
But this gives the following error:
Public Overrides Function ParseValue(sValue As String) As Boolean'
cannot override 'Public Overridable Function ParseValue(sValue As String) As Object'
because they differ by their return types.
I accept that you can't do this, but I'd like to be able to preserve the semantics of what I'm. trying to do, which is to have an untyped version that deals with Object, but a typed version in derived classes that knows about the specific type T.
Suppose I have piece of code like this:
Public Interface ISomething
....
End Interface
[code]....
I suspect I am being very silly here but I have the following setup
Class MustInherit myBaseClass
'some stuff
End Class
Class myInheritedClassA
[code]....
Running this results in the following error
Unhandled Exception: System.InvalidOperationException:
There was an error generating the XML document. --->
System.InvalidOperationException:
[code]....
is there any way of 'Widening' the inherited class to the base class so this would work?
EDIT:regarding XmlInclude(typeof inheritedClass), currently this method could potentially return a number of types of inherited class (i.e myInheritedClassA and myInheritedClassB) is it case of simply having to add each of the inheritedTypes in this tag?
I have a Journal that records entries for different types: Journal(Of ParentT)
[Code]....
I am trying to construct a generic interface class with generic functions. My goal was to use this to implement multiple worker classes for database interaction that have the same basic functionality. Each class will deal with different object for example, category, product or supplier but unless the the functions in the interface are generic that this won't work.This is the interface code that I have but I don't know if I have done it correctly. [code]
View 2 RepliesI understand that inherited classes can't be converted from base classes. But is there any way to write a conversion sub, so that the base class gets assigned to MyBase, then extra properties are added?[code]...
View 7 RepliesI'm trying to force an inherited class to use a custom attribute. I'm creating a class library where the user who wants to create an item will do so, but be forced to add an attribute (or visual studio will automatically add the default attribute) to their inherited class. Here is what I'm hoping to achieve:
BaseClass.vb:
<CustomAttribute(10)> _
Public Class BaseClass
End Class
MyClass.vb:
[Code]...
I have a class definition that I've seen other define properties that return collections of objects.
Public Property GetAllAdults() as Adults End Property I made the argument that this should be a method in the class, because it doesn't define an attribute of the class, and could not be extended with parameters. Is/Are there reasons why this should be defined as a property vs. a function?
How do I creat a simple array of class definitions?[code]...
View 13 RepliesI'm working a business layer (separate assembly) that will contain various business entities used in multiple client applications. One of the client applications is a WCF app that will need to serialize these entities. In order to properly serialize the entities, metadata for data contracts or for XML serialization must be added, but the serialization requirements may vary across applications.
Clearly I need the metadata separated from the class definition. So how do I add metadata to my entities for each separate application?
I call upon the VB ninjas out there. Here's my situation. I need to eventually be able to pass multiple models to a view. Currently I have a linq to sql class that, of course, has a bunch of generated model definitions. I need to make a model that implements multiple models. I somewhat understand how to do this in C#, but this project is testing my VB skillz. Here's some snippets from my linq to sql models. I need to combine these two into one model to pass to the view.
[Code]...
I have a base class which needs to define an enumeration:
BaseClass
- SomeEnum
I then need to create two derived classes from the base class and extend the values in the enumeration:
ChildClass1 : BaseClass
- SomeEnum
- SomeEnumValue1
[code]....
In C# or VB.NET can someone provide the syntax to do this?
In order to organize various methods of my MainForm class, I would like to categorize them into several files. Of course, the methods would still need to access form elements and additional variables I added in the MainForm class.
View 3 RepliesIf we are within the derived class then ofcource we can use MyBase keyword to access base class's object reference . That's fine , how can we take that base class's object reference outside that derived class's definition.
My following code will explain what i want . Actually that is giving error right now, but it is explaining my requirement .[code]...
I see a sample code that an object is instantiated within the class definition block. But when I test the folllowing, I got error "Process is terminated due to
[Code]...
I am currently using reflection to retrieve all properties of a class. I return a collection of PropertyInfo objects and all is working fine.
My problem is, I want to check if a property has been defined in a base class implementation and is therefore inherited in the current class.
I have 3 classes that need themselves in order to do their work but if I declare them the old way it would end up being an endless loop.
As an ex C++ programmer, I know I could use include once but I don't know if there is any equivalency in vb.net Here is the picture.
I have 3 Classes : SQLConnector, ErrorHandler, LogHandler
- ErrorHandler needs SQLConnector to get some IDs from the Database.
- ErrorHandler needs the LogHandler class to prepare the Logs to be... logged.
- SQLConnector needs the ErrorHandler class in case there is errors happening.
- LogHandler needs SQLConnector to insert in the database.
- LogHandler needs ErrorHandler in case the insert is not successful (sends mail in that case)
As you can see, all three classes are needed. The reason why I can't use LogHandler and ErrorHandler as one class is that I will use that class to log transactions and changes according to some parameters. Log is in no way exclusive to ErrorHandler.how I can prevent to make an endless loop and use all three of them as I wish?
In a global module, I define a new type that can take 4 values:
enum tAction as integer
None
Update
Insert
Delete
end enum
A use this type in many places in my code to check the value stored in a variable (if MyAction = tAction.Delete then ...)
In a separate file, I define a class. One of the properties should return a value of this type:
public class XXX
private _Action as tAction
public property ClassAction() as tAction
[Code].....
This way I could check a class property in the same manner (if MyClass.ClassAction = tAction.Insert then ...)
However I get a syntax error in the property definition: 'ClassAction' cannot expose type 'Globals.tAction' outside the project through class 'XXX'
My entire program consists in a few modules, in a single project. How can I use my tAction definition in my classes?
i have a class named fdetails and i do not want any other class to inherit from this classCan i set it to not being inherited by another class. I would like to get the things done in the following 3 languages
View 6 Repliesi have a class named fdetails and i do not want any other class to inherit from this classCan i set it to not being inherited by another class. I would like to get the things done in the following 3 languages
I'm trying to return code like this (can be found here):
{"hotspots": [{
"id": "test_1",
"anchor": { "geolocation": { "lat": 52.3729, "lon": 4.93 } },
[code].....
Can you define this :
Class
Object
Inheritance
Polymorphism
Abstraction
And could you make it easy to understand I'm having a hard time to understand those terms.
bare with me during this silly example. :-) Let's say I have a class like this:
Public Class Animal
Public iLegs as int32 ' Number of legs
Public bWings as Boolean ' Wings? Yes/No
End Class
And another class that inherits the "Animal" class and adds one more property:
Public Class ScaryAnimal
Inherits Animal
Public iScariness as int32 ' 0-100, how scary is it?
End Class
Now, if I have an instance of "Animal" with some values in it, and I decide I want to cast it to a ScaryAnimal for some reason, how do I do that without having to create a new instance of "ScaryAnimal" and copy each property value?Basically I'm looking for a way to do this, without having to write the lines marked with '*** below:
[Code]...
I have two classes[code]...
How can I modify class1 in a sub in class2?
The program below trhows an error in the line "mTable2 = mTable.Copy". The error is: "Unable to cast object of type 'System.Data.DataTable' to type InherintanceQuestion.InheritedTable". This is because mTables is an instance of the InheritedTable class which inherits a DataTable and mTable is a DataTable. So, is there any way I can create the mTable2 to the mTable.copy to the mTable.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
[code].....