C# - Extending An Object And Any Child Collections?
Jul 30, 2009
I have an class named Foo. This class contains a collection of child objects of type FooChildBase, but I also have a further class of type FooChildTwo which inherits from FooChildBase.
Class Foo
Public Children As IList(Of FooChildBase)
End Class
Class FooChildBase
[code]....
What I would like to do is have my FooSpecial Class treat it's Children collection as if they were FooChildSpecial objects, but still be able to add FooChildTwo objects to it. Is this possible and if so how can it be done?
EDIT:I need to FooChildSpecial class to wrap any of the objects in the Children collection with the extra values, whether they are FooChildBase or FooChildTwo?
View 3 Replies
ADVERTISEMENT
Jan 27, 2010
imagine i want to add an extension method to System.Collections.Generic.List(Of T)
let's say i want to give it .GetUBound which returns Count-1
View 7 Replies
Jan 4, 2010
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?
View 3 Replies
Feb 18, 2011
Im working with MDI parent/child objects. when closing the child objects i need the child to check to see if it is the last child object before closing. i couldn't find anything on google, maybe im searching for the wrong thing.
View 2 Replies
Jun 14, 2010
If I defined a ENUM in a base object with serveral default values. When I inherit from the base object I want to add more options the the ENUM list which are specific to the inheriting object.
For example my base could have a ENUM called Direction with values:
None
ALL
Stop
Start
I create a new class call Compass which inherits the base class and what to add the following to the ENUM Direction. I create a new class call Navigation which inherits the base class and what to add the following to the ENUM Direction. So, In my inheriting class haow do I extend the ENUM.
View 1 Replies
Jul 27, 2009
If I'm extending OnCreated for a LINQ to SQL table object, is it possible to get a reference to the data context to which the table belongs? For example, if I add a property to the data context:
Partial Class MyDataContext
Private _myValue As String
Public ReadOnly Property MyValue As String
[Code].....
I don't want the property on the data context to be Shared, because it could be different per instance. I've been pouring over the designer code to figure out where the reference might be, but no luck yet.
View 3 Replies
Sep 20, 2010
I have a question specifically about getting the current cookies set to a particular visitor on an ASP.NET webpage. I understand you need to use Request.Cookies - and by default it returns a collection of all cookies set, as an HTTPCookieCollection. However, the MSDN documentation states that you do: Request.Cookies("Username") as an example, in order to fetch an individual cookie and then compare whether it is set, etc. All fine and dandy but why adding parentheses and a string does the type suddenly change to
HTTPCookie.
I understand HTTPCookie is for dealing with individual cookies and HTTPCookieCollection is for dealing with multiple cookies at a time for like iteration purposes, etc., but I don't understand when on the MSDN documentation it explicitly states that the Request.Cookies property (the Cookies property) is of type HTTPCookieCollection, and if you do what I explained it changes the type (I can see this from IntelliSense) and it does not state this happens in the MSDN documentation. I'm not asking about the MSDN documentation lol, but why this happens when adding the parentheses and a string denoting the cookie name. I'm still pretty new to Visual Basic. By the way, I'm doing this all in Visual Web Developer although using VB as the language of choice.
View 3 Replies
Jan 3, 2012
given the following class structures:[code]I add the following property to MyList, trying to answer questions like "find out the number of elements with specified type, say Derived1, inside MyList?"[code]
View 1 Replies
Feb 24, 2009
is there any collection in vb.net which store object as byref and not byval.
View 4 Replies
Mar 15, 2007
My colleague and I have recently upgraded our projects from .NET Framework 1.0 and VS2002 to .NET Framework 2.0 and VS2005. We also applied the latest VS2005 service pack.
Our problem: normally when debugging we use the QuickWatch window to drill down into and view collections of objects belonging to the parent object we are "watching". THIS NO LONGER WORKS...instead, we get a message in the value line against the object collection saying:"In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user."This is incredibly frustrating, particularly when we have large nested collections of objects.We are pretty sure this feature was working fine after we upgraded, but we are not so sure that it was working after we applied the VS2005 service pack.
View 1 Replies
Apr 25, 2009
I have a VB.NET project where I am able to iterate through the keys and values collections of a dictionary object using an index:
MyDictionary.Keys(idx)
MyDictionary.Values(idx)
When this code is taken from the test project and placed into the real project I get the following error:
'System.Collections.Generic.Dictionary(Of Double, String).KeyCollection' cannot be indexed because it has no default property.[code]...
In the line in sub search that says "dtf.Keys(idx) = 0" place your cursor after the right parenthesis and backspace you should get a tooltip that says, "<Extension> ElementAtOrDefault(index as Integer) as Double - index: the zero based element of the index to retrieve.
View 3 Replies
May 6, 2010
Say I have a text file I want to load it to a System.Collections.Specialized.StringCollection
object dim a as System.Collections.Specialized.StringCollection
set a = a contains many systems System.Collections.Specialized.StringCollection object.
Each line in text.txt go to an element in a.
View 7 Replies
Oct 26, 2011
I have these objects:[code]Using LINQ I need to take a List(Of MakeInfo) and a List(Of ModelInfo) and aggregate the StockInfo from ModelInfo into the List(Of MakeInfo).So for each MakeInfo I will have a total count of all stock where MakeInfo.Name = ModelInfo.Make, and also a minimum price.I think it's going to be something like this, but I'm having trouble accessing the nested object and not sure if it's going to be possible with a single query.[code]
View 2 Replies
Nov 21, 2011
I'm checking If a border's child property is not set to nothing or equal to a given element, but whenever I run the program, it says that it's set to nothing and crashes. Here's my code:
If Not Me.Child.Equals(Nothing) Then ...
If Me.Child.Equals(value) Then ...
Both gives an error. What should I do to pass these lines? Also in C# it would look like this:
if(this.Child != null) ...
if (this.Child != value) ...
But this time it doesn't give an error.
View 2 Replies
Sep 21, 2011
I'm having a problem with this code in the highlighted line(*); getting the error in the heading.
Dim htmlarraylist As New List(Of iTextSharp.text.IElement)
htmlarraylist = *HTMLWorker.ParseToList(New StreamReader(tempFile), New StyleSheet())*
[Code].....
View 2 Replies
Dec 22, 2010
I have a series of API calls that are returning J# data types. I have been able to convert most of the data types (Integer, Boolean, Double, Float, etc) just fine.What I need to do now is convert a java.Util.Collection to a VB .NET collection (ArrayList)
Here is my attempt:
Public Function MakeDotNETCollection(ByVal javaCol As java.util.Collection) As Collection
Dim dotNetCol As Collection
[code]....
I keep getting a runtime error "Unable to cast object of type 'AbstractListlistIterator' to type 'System.Collections.IEnumerator.
View 1 Replies
Nov 7, 2010
I am constructing a collection of objects, and need to use inheritance on a base class - I have been trying for hours in various ways and can't get this to work whatsoever - the error is always "Object reference not set to an instance of an object." The idea in the example below is that an object is instantiated, and within that lies a collection of Students when I try to access the oDemo.Students(0).Name property the error is raised. Otherwise the object appears to have instantiated OK.Here is the code being used to instantiate and access the class (from ASP.NET).
Dim oDemo As New MyDemo.Students
lblTest.Text = oDemo.Student(0).Name
Here is the sample code from the class library:
[code]......
View 2 Replies
Oct 13, 2010
I am using Visual Studio 2005 and am writing a SSIS package. In the package I have a VB.Script that looks at a directory on a server and creates a list of the files. I then have a store Proc that looks at a table and gets a list of files that matches the files in the first array. The result is a fullresultset. The next step I need to create a 3rd array that only contains the rows from the first that are not in the second. However, I am getting the following error. Error: The script threw an exception: Unable to cast object of type 'System.Object' to type 'System.Collections.ArrayList'.
View 3 Replies
Feb 5, 2011
[code]...
What's really the point in using the former?It's hard to use linq if I used the former. I have to convert that to an array first which is difficult because there is no (asarray) function.I think I would change all of my code that's using System.
Collections.Specialized.StringCollection to System.Collections.Generic.List(Of String)
View 2 Replies
Sep 6, 2011
Limited to using v2.0 of .Net framework (we use VB.net) due to environmental constraints on our servers.I've got an ASP.net webpage which pulls data from a webservice that performs checks on user accounts in active directory. Operators can check multiple accounts at one time using the web interface. The webservice returns a list(of AccountCheck) objects which themselves contain single properties like username, email address, and List(of AccountError) objects which contain multiple properties.[code]What I want to do is using some kind of repeater, create multiple panels or divs which contain labels showing the username, email etc, and a gridview which has the accounterror list bound to it to show all the errors. The users could be checking 2, 5, 7 accounts at once, and is dynamic.
View 2 Replies
Nov 8, 2011
I occasionally find myself passing this or Me to a child object. Such as this condensed real-world example...
Public Class Entity
Private mValidator as New EntityValidator()
Readonly Property IsValid()[code]....
I'm concerned about .Validate(Me).I get no warnings or Code Analysis violations, but it just feels wrong. I get nervous about infinite recursion and garbage collection.
View 2 Replies
Jul 19, 2011
I create a form2.vb which have a report viewr and modifier set to public. In reportviewer properties i add the Report1.rdlc Now i want to pass the vlue in the textbox at report1.rdlc i use following steps and code to do it butnot sucessful yet i need ur guidelines first from menu click report ___ report parameter and set the parameter name like conparm. Then i frm2 load event i write following
[Code]...
View 1 Replies
May 14, 2012
I'm getting an error after sending a list to a web service.This is the code that is calling the web service:
Dim sProgramInterest As New List(Of Integer)
crmService.InsertProspectGetId(sProgramInterest.ToList)
But I'm getting this error.
[code].....
View 3 Replies
Jul 7, 2010
I have created a Dictionary class (MyDictionary for the example). I am currently trying to pass MyDictionary into a function, filter it into a new instance of MyDictionary and pass this new instance into another method. When I am attempting to create the second instance from the filtered first instance of MyDictionary via Lambda Expressions and the ToDictionary Method, I am getting the following error:
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.Int32,System.String]' to type 'MyDictionary'. I have simplified the example and recreated it in LINQPad and am getting the same error.
Here's the simplified version of my code:
[Code]...
View 2 Replies
Jan 7, 2012
And here is the code that produces the error
CODE:
How can i cast this one?
View 1 Replies
Sep 22, 2010
With the two lists (t1s and t2s), I want to display t1s in a DataGridView, and in one column show the T2 property as a comboBox column, which dropdown will show the t2s list such that a new list instance can be selected. T2 has a Name property that should be used for displaying it in the comboBoxColumn.
I'm able to display the dropdown, but remaining a few problems:
1. How to display the correct comboBox "selection" on "load"?
2. How to change the T2 child object instance when combobox selection is made?
3. This is a really basic problem, which suddenly happened and I just couldn't understand what I have changed; The code marked BLUE now just shows empty cells.. While the AutoGenerated columns do show values.. Shouldn't those "manual" columns work?
[Code]...
View 29 Replies
Mar 5, 2010
When you create a webpage in ASP.net, the codebase inherits System.Web.UI.Page Now when I extend the page object to check for SessionExpired for example, I create a new class and inherit from system.web.ui.page, and overwrite some functions. The problem then is that on each page, I have to replace system.web.ui.page with my custompage class. Is there a way to extend a class by adding methods or modifying its methods directly (e.g. add the sessionExpired check to System.Web.UI.Page) ?I'm using .NET 2.0
View 2 Replies
Mar 17, 2011
I have a class within a library, with no root namespace, firstone.dll:
namespace first
public partial class one
public sub fun()
[Code]....
Is there a way to extend the class in a separate dll and still have access to the original class? I don't want to inherit the class just extend it.
View 3 Replies
Jun 27, 2011
I know from .NET 3.5 onwards (or might be 3.0) we can use Exension Methods to add our own methods to any Type in the .NET Framework and this is very handy, but I'm wondering if it is possible to "extend" an Enum as well?
View 13 Replies
Aug 19, 2011
I would like to create a DataGridView that displays records that fill either 18 or 35 columns. I would like to avoid displaying all 35 columns for all records, instead showing the 17 extra columns on a second row for records that need them.How would I go about this? I'm guessing I need to create a new class that inherits from DataGridViewRow and override it's Paint or PaintCells method, but I have no experience with overriding Paint events, so I'm kind of lost after that.
View 8 Replies