Flattening An Object Hierarchy Using A Shim Class - Initializing Derived Object Properties From The Base Object?
Jul 10, 2010
I am somewhat new to object oriented programming and am attempting to flatten a Linq object hierarchy by using a shim class.how to initalize a derived class with property values from a base class?I have two objects, a base object with about 100 properties, and a derived object which inherits from the base object and adds a few additional properties beyond those of the base object. My simple constructor creates the derived object, but I am looking for a way to initialize the derived object properties with values from the base object.Right now I am using reflection to iterate over the properties individually and I suspect there may be a better way. The following example shows my shim class constructor for the derived class, and two properties:
newProperty1 - a new string property of the derived class
flattenedProperty2 - a new string property of the derived class, copied from a 2nd-level object of the base class
Code example:
Public Class derivedObj
Inherits baseObj
Private _newProperty1 As String[code].......
Is this the correct constructor approach to flatten the object hierarchy using a shim class? My second question relates to initialization of properties in the derived class. The constructor above creates the derived object, but what is the best way to initialize the derived object properties with values from the base object? The following code uses reflection to iterate over the properties individually, but I suspect there may be a better way.
Code example:
' property names are in the string array fieldNames
'baseObjQuery is an ienumerable of baseObj
'derivedObjList is a list of derivedObj[code].....
Is there a simple way to initialize values for the properties in the derived object based upon the values of the common properties in the base object?
View 7 Replies
ADVERTISEMENT
Dec 15, 2011
I'd like to have something like:
[Code]...
View 1 Replies
Jan 12, 2011
I am trying to write an VBA application in Excel 2010 using "Microsoft Soap Toolkit 3.0" on 64 bit Windows 7 to consume an web service. But i got an error while initializing an object of SoapClient30.
Error message is :: Runtime error '429' :ActiveX component can't create object.
View 2 Replies
Jul 20, 2009
I want to build a MVC helper function for which I pass a Entity Framework object and have it build a select. Generally speaking I tried something like this:
Public Function RenderSelect(ByVal helper As HtmlHelper, ByVal sSelectName As String, ByVal aItmes As Array, Optional ByVal sTitleKeyName As String = "name", Optional ByVal sValueKeyName As String = "id") As String
' open select
[Code].....
However, it isn't working. It would be great to have a way to do this and pass the current entity object.
View 3 Replies
Oct 26, 2010
Dynamic Object Properties in a MVC Helper on a Entity Framework object
View 1 Replies
Feb 13, 2012
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 .[code]...
View 6 Replies
Aug 8, 2011
Background:I have a base class and several inherited derived classes. The derived classes don't always need to have the same properties. If any properties are shared among the derived classes, those properties would live at the base class level ('Contents', for example).Similarly, GoodDocument below has 'GoodThings' but would not want/need to have 'BadThings'.I want to treat instances of both 'GoodDocument' and 'BadDocument' as type 'Document'
public mustinherit class Document
public property Contents as string
public sub new()...
[code]....
View 3 Replies
Jun 17, 2009
Here is a test program I wrote to explore a facet of object casting ...
Module Module1
Sub Main()
Dim class1 As MyBaseClass = New MyBaseClass()
Dim class2 As MyInheritedClass = New MyInheritedClass()
Dim class3 As MyBaseClass = Nothing
[Code] .....
The problem comes with the TryCast statement on class3. My intention is that class3 remains as a baseclass, but when the TryCast is applied, class3 morphs itself into an Inherited class which is not what I wanted. So is there a gap in my OOP/VB.NET knowledge and this action is legitimate or should class3 still be regarded as a base class?
View 6 Replies
Dec 10, 2010
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 ?
View 1 Replies
Aug 6, 2010
Here is the structure that I have:
Friend Class StandardFormatFile
Friend fileType As String
Friend numberOfSeries As Integer
[code].....
View 3 Replies
Nov 20, 2010
I have a property grid and I want to be able to set the selectedobject to a class. The class contains properties. This is what I have, but it 'OtherFiles' is not an object.
pgProperties.SelectedObject(OtherFiles)
How do you create a class as an object. In VB.NET 2008 please. C# is ok.
View 1 Replies
Aug 11, 2009
dim myCollection as new Specialized.StringCollection
dim myFoundThings as new ArrayList
dim index as Integer
dim newResultMemberName as String
[code]....
This is part of some code that will run without user interaction once it's spinning away, and I need to create a unique object from some items found in a StringCollection, naming the objects using information found in the strings stored in that StringCollection.
View 2 Replies
Jun 15, 2009
i've created bunch of classes. i have webservices which reference these classes and contains the classes as parameters and return objects.when i call the weservice, i have to convert the class to the webservice object else i can type conversion error.is there a generic way to convert between these types without having to assign the values by hand?
for example
public class person
fname as string
lname as string
end class
[code]....
i would liek ot be able to call the web service and return the data type back and have a generic coversion instead of as above in stead of:
dim wsPerson as wsReference.Person = ws.getperson()
View 2 Replies
Apr 18, 2012
I have an object (a third component gridview) which is serializable, and I need a deep clone of this object. I have the following code which throws the exception."The type System.Windows.Forms.Control in assembly System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKey Token=b77a5c5 61934e089 is not serializable".So the gridview's base class is System.Windows.Forms.Control, which is not serializable. How can I get a deep clone from the gridview? [code]
View 5 Replies
May 5, 2010
I have created a set of classes that represent an hierarchySo when I reference like this:
Dim alldeals as deals
alldeals.Deal(5).DealSlot(3).SlotType= "SomeType"
alldeals.Deal(5).DealSlot(4).SlotType= "SomeOtherType"
[code].....
View 3 Replies
Jan 27, 2009
I'm looking for advice to make my code efficient in terms of execution speed and memory usage. Basically, how to lay out my objects. The program displays parts of several data series in bar- or line- charts, as well as calculated series based on these data series. The key user input will be to change what part of data series to look at, and that input should trigger instant chart update, with minimal lag.
[Code]...
View 10 Replies
Jun 7, 2010
I am utilizing a centralized class object that needs to call another class object. The program itself will do something like the following
sFieldValue = CentralObject.ObjectHandler(1, TestFunction, "FunctionVar,FunctionVar2,FunctionVar3")
In the central object I have a function
Public
Function ObjectHandler(ByVal ObjectType
As
Integer,
[code]....
View 5 Replies
Jun 10, 2009
I am moving from VB to C#. I am trying to loop through a collection class which is a collection of data classes but I can't seem to get the actual values out of the data class properties(find the correct code to do so). I have a method that loops through the collection class(Contacts) and saves each record(Contact). I am using reflection because my method will not know if it is Contacts class or a Customer class and so forth. Here is my code in VB(watered down)
Public Function SaveCollection(ByVal objCollection as Object, ByVal TableName as string, ByVal spSave as string)
Dim objClass as Object
[Code]....
The C# code keeps returning null. In my locals window I can see the proprties on the class on objClass and the value of the propery but I can seem to figure out how to access it through code. I used the DictionaryBase because that seems to closely match would I need to do. My data class(Contact) has a bunch or properties that match the field names in the database of the Contact Table. After I get the propInfo variable set I then set up my SQLParameter with the fieldname, datatype etc and then set the value to the propInfo.value.
View 5 Replies
Jun 7, 2010
Not sure how to do thisI have a hierarchy:
Deals at the top
Deals is a collection of Deal
Deal is a collecton of DealSlots
[code]....
View 3 Replies
Apr 12, 2006
I am developing an IT Asset Tracking application using VB 2005 and SQL Server 2005 Express edition. Will I need to create classes to represent objects such as Computers, Printers, Scanners/Faxes, Contracts, Purchase Orders etc or are there any other approaches.For example, if I am correct, I will have a class called Computer and its properties will include Make,Model,CPU,Hard Disk,Memory etc. Is this the right approach.
Computers can be split up into Desktop PC's, Servers and Notebooks. Would I have to create separate classes for these as well or would they be ok under the Computer class.Once I create an object from the class, how can I use the object to interact with the SQL db.I am a beginner to VB.NET 2005 therefore I am slowly getting to grips with OOP.
View 13 Replies
Aug 19, 2009
I have a class in which some of the fields are also classes.
I can put values in the "normal" properties, but in the others when o try to assign values it gives the: "Object reference not set to an instance of an object"
But the code compiles fine.
dados_Defenicao = New ServiceReference1.draftClaimEntryDefinition
dados_Defenicao.arCode = "123"
dados_Defenicao.claimMarket.warrantyType = "w" - Here it gives the error
View 4 Replies
Jul 5, 2010
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]...
View 2 Replies
Jan 20, 2009
In VB.Net is there any difference between the following three ways of initializing object variables
Method 1
Dim commandObject As SqlCommand
commandObject = New SqlCommand("MadeUpCommand")
Method 2
Dim commandObject As SqlCommand = New SqlCommand("MadeUpCommand")
Method 3
Dim commandObject As New SqlCommand("MadeUpCommand")
Is one more efficient than the others, or are they effectively all the same?
View 3 Replies
Oct 22, 2010
how to implement UI, BL and DAL in a project the way that I see it as a requirement for some projects. The way I am able to do a project now is from a form create an object of a class in which there are properties and functions that do database selects, updates and deletes. Looks to me that doing a project like that is separating the UI from the DAL. In an update button click event I may call Obj. Delete (txtCustID.txt) for example. I don't understand the part of further breaking it down to include a Business layer; in which a vb solution is made up of three solutions.What goes in the BL?Does the BL call the DAL?
View 2 Replies
Oct 5, 2009
If you want a instance of an object to be created when a form loads or another class is created, you have two options:
Public class example
private IAmAObject As IAmAObject
public sub new()
[CODE]...
Or like this:
public class example
private IAmAObject as new IAmAObject
public sub new()
[CODE]...
I always use the first one. It's more type work but I think it's neater. How about you people and is there any real difference between the two?
View 4 Replies
Jul 29, 2011
I am getting following error whenever I want to use IIf function inside entity framework query.
LINQ to Entities does not recognize the method 'System.Object IIf(Boolean, System.Object, System.Object)' method, and this method cannot be translated into a store expression.
View 1 Replies
Apr 16, 2010
What do I need to convert?
Dim CEESearchByAppNo = From CEEsearch In dbCEE.tblScanneds _
Where CEEsearch.AppNo = iAppNo
[code].....
View 5 Replies
May 8, 2009
How do I calculate the direction an object is facing in degrees, if object A is at x1, y1 and facing object B which is at x2, y2?
View 2 Replies
Apr 7, 2011
Supose a base class
Public Class airplane
Private var_num_seats As Integer
Private var_num_engines As Integer
[code]....
Obviously, I don't wish that the class Glider has the method "start_engines" neither the property "num_engines". Otherwise, other child classes may have. How can I supress these property and method in child class, not just ignoring (if I can)?
View 2 Replies
Mar 17, 2012
The book "Beginning ASP .NET 4 in VB 2010" contains the following:NOTE: TaxableProduct inherits from Product.You can also cast in the reverse directionfor example, cast a Productreference to a TaxableProduct reference. The trick here is that this
View 2 Replies