Collection Of Arbitrary Types

Oct 21, 2010

I know there's the old, late-bound, VB6 Collections, but I was looking for something like Generics, but either without having to specify the type at compile time, OR finding a clever way to allow the code to determine the type on its own and then call some generic class.Why? I'm bored, and I thought it'd be fun to try and implement my own library for NBT, or NamedBinaryTag.It's the storage format used in the popular Minecraft game.url...I know there are existing implementations out there, but there's no point in copying those if I'm doing this solely as a learning experience to get a better grasp on file streams, byte arrays, endian conversion, and general .NET stuff (I used to fiddle with VB6/VBA a lot, so .NET is a huge change).

What's hanging me up is TAG_Compound. Per that specification, it's essentially a collection of objects of any other Tag type, including additional, nested TAG_Compounds. You can do some freaky nesting/recursion with this kind of a format.I've got a rough outline in my head of how to do the other classes, but the storage of arbitrary types is just making me draw a blank on how to store that in a stub class (clsTagCompound) So that a generic class (clsNBT(Of T)) can use generic functions to access the payload.List(Of T) looks like it could work if I could feed it a common interface. But since a Generic class will be the main component used, its interface is also generic, and that just leads to nasty generics chain (List(Of (clsNBT(Of XXX))).[code]What I'm thinking of doing, is making all derived classes implement INbt(Of T).For clsTagCompound, its SetPayload method will start walking a bytestream after the compound's name field is parsed. For each new TagType that it encounters, it would theoretically call DirectCast on a temp variable Dim'ed to INbt(Of T) to convert it to the class defining that particular TagType.But this doesn't seem to work as planned. I believe my Catch 22 is that to even use clsTagCompound, I still have to define T, and that's where I get stuck again. I somehow need to create an interface that is NOT generic, yet can be applied to all the classes for the various Tag types and still call their GetPayload function to return the payload specific to a particular tag.

View 4 Replies


ADVERTISEMENT

C# - Arbitrary Precison Floating Types In .net : Finding Library That Allows That?

Oct 21, 2009

I need to do maths on both floats and integers with much bigger accuracies and magnitudes than offered both by int/float/double in .net. I recall there was something like that for c/c++.

View 2 Replies

Initializing Class Collection Of Inherited Types

Oct 4, 2010

Is there a way to have a class collection of inherited types be initialized? For example, here is my code:
Public Class CamryCar
Property Name As String = "Camry"
Property Color As String
End Class
Public Class RedCamry
[Code] .....

I prefer this one as I don't have an extra property to deal with. But I can find a way to initialize that that list with objects of RedCamry and BlueCamry. Is it impossible or is there another way to do this?

View 3 Replies

Way To Remove All Other Cursor Types From Application Collection?

Sep 26, 2010

I have a nice mouse cursor that I attached to every event on the form and the controls, and I would like it to remain always the same cause some times it changes to cursor appstarting.Is there a way to remove all the other cursor types from the application collection?

View 2 Replies

Use Linq To Entities To Group A Collection Without Using Anonymous Types?

Apr 24, 2012

The documentation has an example about grouping on multiple properties[code]...

Is it possible to rewrite the original query to just return IEnumerable(Of CustomerRegionGroup), or do I have to use the anonymous type, and run a second query on the result of the first?

View 1 Replies

Cannot Iterate Of A Collection Of Anonymous Types Created From A LINQ Query?

Mar 17, 2010

Every LINQ example I have seen for VB.NET anonymous types claims I can do something like this:

[code]...

Now when I go to iterate through the collection(see example below), I get an error that says "Name "x" is not declared. For Each x in Infos It's like VB.NET doesn't understand that Infos is a collection of anonymous types created by LINQ and wants me to declare "x" as some type. (Wouldn't this defeat the purpose of an anonymous type?) I have added the references to System.Data.Linq and System.Data.DataSetExtensions to my project. Here is what I am importing with the class:

[code]...

View 4 Replies

Declare With An Arbitrary Number Of Parameters?

Jan 19, 2009

Is it possible to have a class, sub or function declared with an arbitrary number of parameters? And those parameters be a type, like generics? For example

vb.net
Public Class Test (Of T1, (Of T2))'The (Of T2) means that after the first parameter can be an arbitrary number of parameters

[Code]....

View 9 Replies

Set Listview Items In Arbitrary Order?

Aug 27, 2010

You can set listview items in a-z order and z-a order but how to set listview items in arbitrary order?

View 4 Replies

Adding Arbitrary Labels And TextBoxes At Run Time?

Sep 28, 2011

The three labels "Floor" "Typ." "HeadsI can insert once fine but multiple times only the third instance is written to the form.I have 2 textboxes to test that the Label.Name is changed but I can't make the Label.text stand for each label. I am certain this will occur too with the textboxes.I also need to keep track of these boxes for further use with the program.

Public Class Form1
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

[code]....

View 1 Replies

Asp.net - Select A Variable TimeSpan With An Arbitrary End Point

Apr 29, 2009

I've been working on a Stored Procedure that checks the time, then retrieves records going back over the last full 24 hour period between 8am and the previous 8am. So, for instance, assume that it's currently 10am. The stored procedure looks at the current time, notes that it is past 8am, and sets the query to run backwards 24 hours, from 8am today to 8a yesterday. If it were, say, 7am, the query would be set to check from 8am yesterday to 8am the day before. This was actually relatively simple to do. The SP is meant to be used to retrieve records for a report tracking jobs completed in the given time span.

However, they've come back at me and asked me to change the stored procedure such that the hour the report ends at, and the span of time checked, is configurable from the front-end of the site. I have this working for TimeSpans greater or equal to 24 hours, but am having trouble with spans under that. Here's what I have so far for my logic in the Stored Procedure -

-- Retrieves data on jobs that completed/completed with errors during a given time span.
DECLARE @Hour NVARCHAR(2)
DECLARE @TimeFrame NVARCHAR(2)

[Code].....

View 2 Replies

C# - Order List By Arbitrary Sort Expression?

Mar 2, 2011

I have a generic list, like this:
System.Collections.Generic.List<Question> myquestions = new System.Collections.Generic.List<Question>();

And I have a paging example, using a LINQ table acquried from database, doing this for paging:
var questions = context.Questions
.OrderBy(sidx + " " + sord)
.Skip(pageIndex * pageSize)
.Take(pageSize);

Right now, for paging my populated from code list, I have:
var questionss = myquestions
.OrderBy(x => x.Id)
.Skip(pageIndex * pageSize)
.Take(pageSize);

And what I want is being able to order "myquestions" by a string as in the above example. Is that possible?

View 5 Replies

Accessing Elements In A Multidimensional Array Of Arbitrary Dimensions?

Jul 3, 2010

I'm trying to write some of my own linear algebra methods, and I'd like them to work independent of the number of dimensions of the array. However, there doesn't seem to be any generic method, that I can see, for looking up a particular element in an array of arbitrary size. I mean I could write code to find the rank and then use (), (,), (,,), (,,,), etc, but that seems rather cumbersome.

View 4 Replies

Adding Arbitrary Number Of Controls In Loop At Runtime

Jul 12, 2009

How do you add an arbitrary number of controls to a form at run time? With indexed controls I could define the 'seed' control at design time and reference 'clones' of the 'seed' control at run time via the index. Now I must declare each additional instance of the control at run time then set each individual property that differs from the default for that control for each instance. Then I must add the newly declared control to the appropriate container controls collection. I'd like to do this in a loop but how can I get away from using a fixed control name in the declaration:

Dim controlname As New Control

I can't use a string that I can manipulate the contents of for controlname because it sees it as a double declaration. I can't use an array such as Control(index) for controlname. Dim Control(maxindex) As New Control doesn't work. Dim Control(maxindex) As Control works but any assignment based on this such as Control(indexvalue).Name = "ControlName" fails. It didn't address the issue of handling the declaration of new controls in a loop with some kind of variable name for the control.

View 1 Replies

C# :: Determining Object Equivalence For Value Types, Reference Types And ILists?

Nov 1, 2009

I have a class with a Property called 'Value' which is of type Object.Value can be of any type, a structure, a class, an array, IList etc.My problem is with the setter and determining whether the value has changed or not.This is simple enough for value types, but reference types and lists present a problem.For a class, would you assume that the Equals method has been implemented correctly, or just assume that the value has changed every time the setter is called?If I did assume it's changed, then perhaps I should assume it for value types as well, so that the behaviour is consistent.

View 2 Replies

Compare Two Types In Dictionary Of Types .net?

Jun 23, 2012

I need to compare two dictionary values if the types stored are equal, this is what i have

if gettype(Args(key)) = gettype(argtypes(key)) then
'' do something
end if

[Code]....

View 1 Replies

.net - Storing Subcollections (filtered Versions Of The Main Collection) Inside The Collection As Cache?

Jan 15, 2010

Is it good practice to store sub-collections of item X inside a parent collection of item X for caching 'filter-queries' which are performed on the parent collection? (They won't be used together (as in color AND type).) Or is it also ok to just Loop over the collection and return the correct entities in a temporary collection?

[Code]...

View 1 Replies

C# - Edit List Collection : Error Note Collection Was Modified - Enumeration Operation May Not Execute?

Sep 7, 2011

I have the following classes:

Product, Service and OrderItem

Product and Service must inherit OrderItem. So basically I want to store OrderItem object in my shopping cart and these object are store in a list.

Public MustInherit Class OrderItem
Private m_enuItemType As TypeOfItem = TypeOfItem.None
Private m_strUserID As Integer[code].....

View 1 Replies

Use Find/Replace To Replace Arbitrary Text Per Line?

Dec 9, 2011

I have a bunch of object variables which are all initialised in their declarations such that:

Private _myObject As New ThisObject("SomeString")

where ThisObject is one of a number of object types, but all are initialised using a string.

I would like to use the Visual Studio Find/Replace dialog box to search for "As New" then replace everything from "As New" to the first set of speech marks with some text such that:

EDIT

My original example could be solved using other methods. This example is more representative of the actual problem:

Private _myObjectA As New ThisObjectA("SomeString")
Private _myObjectLongName As New ThisObjectLongName("SomeString")

[Code]....

View 2 Replies

Make A Custom Collection That Take Advantage Of The Collection Editor?

Feb 8, 2010

I have been researching for a couple of days now and to no avail. Does Anyone know how to make a custom collection that take advantage of the collection editor? I would like to be able to have 3 Color Values, 1 Boolean and 1 String.

View 15 Replies

.net - Collection Initializes For Read-only Collection Properties?

Jul 25, 2011

I'm trying to support Basic.NET on my framework so I'm trying to convert C# 4 code to Basic.NET 10. Microsoft is committed to "co-evolve" these two but I'm having a problem with collection initialization... I found that I can initialize a collection much like in C#:

[Code]...

View 6 Replies

.net - Search The Collection Of A Collection In LINQ Where Clause?

Apr 15, 2009

I've got the following ADO.NET Entity Framework Entity Data Model:I want to find all the Policyholders with both a Service of a given Id and also a Keyword of a given Status.

This LINQ Does Not Work:

Dim ServicesId As Integer = ...
Dim KeywordStatus As Integer = ...
Dim FoundPolicyholders = From p As Policyholder In db.PolicyholderSet.Include("Keywords").Include("Services") _
Where p.Services.Id = ServicesId _
And p.Keywords.Status = KeywordStatus _
Select p

The Where clause cannot search the p.Services and p.Keywords EntityCollections in that way.

[Code]...

View 1 Replies

Accessing And Adding Items To A Collection That Is In A Collection?

Apr 6, 2012

currently in my application I have a Global Collection that is a Collection of Collections.Currently I am trying to add items/ elements to one of the child collections of the Global Collection but I am unable to use the collections methods of the child.When I assign a variable to the child collection and return the collection it is just an object with the collection inside.

Ex:
Dim GlobalCollection as New Collection
Dim ChildCollection1 as New Collection
Dim tempCurrentCollection[code]......

View 3 Replies

Collection Index Must Be In The Range 1 To The Size Of The Collection?

Dec 17, 2009

I've been working with a CMS called InsiteCreations 2008. I'm running into an error I just can't wrap my head around. I would even be willing to compensate anyone a small amount over paypal, for a solution. The error is rare in occurance, and appears when clicking about 3-4% of links to other pages within our CMS.The full code page is quite large, but there seems to be only one function associated with the error. The error also only appears when not logged into the CMS. If logged into the CMS, clicking the link simply displays the page as normal. I have already checked permissions on the page from the CMS admin console, and it is public.

The error message is as follows:

Server Error in '/' Application.Collection index must be in the range 1 to the size of the collection.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

[code]....

View 2 Replies

Search The Collection Of A Collection In LINQ Where Clause?

Apr 15, 2011

search the collection of a collection in my LINQ Where clause?

View 11 Replies

.NET LINQ - Count Of Collection Within Collection?

Apr 14, 2011

Take the following scenario:

Public Class Store
Public Overridable Property Areas As List(Of Area)
End Class
Public Class Area

[code]....

What's the quickest way to get a total count of shelves for a store? I.e. for a store I get the total count of areas by using Areas.Count Or will I need to loop through each area and tally the count of shelves?

View 2 Replies

Asp.net - Add Controls To A Collection And Update From Collection

Mar 25, 2011

I have an ASP.NET app with lots of textboxes all over the page that need updating at various points through program execution. These textboxes actually belong to a certain class, so for easy updating I thought I could create a Dictionary(Of string, object) and add the control.ID and the control to it and then for updating do something like this:

[Code]...

View 3 Replies

C# - VB Collection - Convert To A Modern Collection?

Jun 26, 2012

I need to convert a VB Collection to a modern one, like Dictionary or Hashtable. For my approach, I need the Collection's KEYS. Googling tells me that it's impossible. Re-writing the entire application using new collections is not an option as the application is really old and large (converted from VB6 to VB.Net).Using the old Collection also is not good - as there are new components in development.Converting a - for example - Hashtable to Collection works:

using VBCollection = Microsoft.VisualBasic.Collection;
public static VBCollection ToVBCollection(this Hashtable table)
{

[code]....

View 1 Replies

Collection Of Lines - Using The Collection.contains?

Aug 12, 2009

I have a collection of lines and as i loop through through the collection, i need to see if it aleady contains a certain line; however, the contains method wants a string and i have stored lines, so how can i use this method to see if my line is already in the collection so i don't place it in there twice?

View 7 Replies

Print To A Collection() Then Prompt To Print The Collection?

Aug 4, 2011

Is it possible to print to a collection(), then prompt to print the collection?

[Code]....

View 2 Replies

Add Together Two Nullable Types?

Aug 27, 2010

I have: Dim nVar1 As Long?Dim nVar2 As Long?Dim nVarSum As Long?nVar1 = Nothing nVar2 = 5 nVarSum = nVar1 + nVar2 I would prefer the result to end with nVarSum being 5, instead of Nothing. I understand if you add something to an unknown value, you will end up with "somthing + unknown" or x+5 will always equal "x+5" not "5" because you are still carrying around that unknown "x". However, how can I effectively treat an unknown or Nothing as a zero for the purposes of addition in this case?(What is basically happening is that the end user is sending us a data file, this code parses that file and then sums together about 15 fields. If the user leaves those fields blank instead of assigning a zero to them, I need to treat it as if it was a zero for this one addition operation, but all the rest of the code needs to continue seeing it as a Nothing value since the user did not ACTUALLY submit zero... they submitted blank or nothing)

View 3 Replies







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