Define A Variable That Is A Collection Of Interfaces?

May 6, 2010

I want to define a variable that is a collection of interfaces - it could be any interface that is defined for use in my app.

e.g. Dim x as New List(Of InterfaceBase)

Is there a base type for all interfaces that I can use for InterfaceBase?

View 1 Replies


ADVERTISEMENT

Collection Of Interfaces (plugin System)

Mar 8, 2012

I am trying to make a plugin system in vb.net and i am using interfaces to do that. I have managed to implement the plugins but now i am having problems with setting the plugins in a dictionary or some sort of array.

The system is simple. I have the main application and i have plugins. The application needs 2 mandatory plugins and that is data and authentication. Other plugins are free to use so i have 3 interfaces. Data, Authentication and CustomPlugins.

I load the plugins with this

CODE:

It works fine like this but i want to make a collection of plugins because i don't know how many plugins the customer make. So initially i thought to make a collection

CODE:

But that doesn't work. The main focus is to load as many plugins as i like but have then in some sort of array. A dictionary would be perfect but is not a must.

View 2 Replies

Define A Collection In .NET So Can Reference Items Either By Value Or Name

Apr 18, 2011

I often have a class defined and I also define another class that is simply a collection of the other class. To do this I found it easiest just to define the other class as Inherits List(Of Type). The reason I define a collection class is to add extra functionality to the collection. Take the following code for example.

Class Car
Property Name As String
Property Year As Short

[Code]....

how can I define my own collection so that I can reference it by index or name like that. Right now I can only reference it by index.

View 5 Replies

Specify Variable Implementing Two Interfaces Possible?

Mar 13, 2011

Is is possible to implement a type specifier with 2 interfaces in .net? Something like:
Public Sub New(obj as ICollection and INotifyCollectionChanged)
''Initialize Code
End Sub

View 2 Replies

C# - Define A Variable Of Different Types?

Feb 8, 2011

i wonder if it's possible to define a variable/property of more than one type. Let's say i want a property TextWebControl that is a WebControl and also implements Web.UI.ITextControl(f.e. like a TextBox or Label). But i don't want to enforce that it is a TextBox or Label, but only one that inherits from WebControl and also implements ITextControl so that it also would work with controls added in future releases of .Net-Framework.

.Net-Framework 4.0

Edit: I have retagged the question and added VB.Net because it's my default language. Normally it's no problem for me to understand C# also, but i must admit that it's difficult to translate generic stuff to VB.Net without experiences and it's also better documentated in C# than in VB. So i would appreciate(and aceept) a working example of a VB.net generic type of ITextControl/WebControl.From Marc's answer i understand that i need a generic class. But how do i instantiate it in SomeClass? This won't compile:

Class SomeClass
Public Property info As InfoControl(Of WebControl, ITextControl)
End Class
Public Class InfoControl(Of T As {WebControl, ITextControl})
End Class

View 3 Replies

How To Define Variable As Global

May 14, 2009

I have no idea as to how I can define a variable as "GLOBAL" in VB Express 2008. I used VB V 3.0 and if I remember correctly the statement "Global varName as Integer" allowed me to use the variable across different forms. I've tried the statement "Public varName as Integer = 0" on Form1 but Form2 tells me the variable is not declared.

The statement (in Form1) "Form2.Label1.Text = CStr(varName)" displays the value on Form2 in Label1 but I cannot then use the value again in Form2, e.g. "Label2.Text = Label1.Text". How I can transfer a variable value from one form to another and manipulate that variable in the second form?

View 4 Replies

How To Define Variable From Sql Query

May 18, 2010

[Code]...

I have remplace the keyarr definition by my SQL query: With the code above, I can print both keyarr in a console. What should I change in the _sqlReader.Read() function in order to get keyarr definition like the first code. I would like that keyarr could be
interpreted by the rest of my code.

View 7 Replies

Define A Type For Each Session Variable?

Sep 18, 2011

Im trying to grasp session varibles, i understand what they are etc but i would like to know how to define a type for each session variable.Iv written it like this

Session("Title") = txtTitleContent.Text

How can i tell it what type of value is going to be in it, because at the moment im only playing about with strings, but what if i have an integer and want to pass it back to the back end to save it will throw an error saying "conversion from string to integer is not valid" should i use Cint to deal with this?

View 1 Replies

How To Define Datagrid And Chart Name As Variable

May 3, 2012

Is it possible to define a datagrid and chart name as variable? I'm planning to put the result into the predefined datagridview inside FOR and NEXT loop. I've been trying but getting different sorts of errors..

For i = 1 to 10

[Code]...

View 2 Replies

Define Property (IsInEditMode) And Global Variable (isEditMode) In ASP.NET?

Mar 9, 2009

public partial class _Default : System.Web.UI.Page
{
private bool isEditMode = false;
protected void Button1_Click(object sender, EventArgs e)

[code]....

What is the VB code equivalent for the above C# code. Mainly how to define Property (IsInEditMode) and Global variable (isEditMode) in ASP.NET?

View 5 Replies

Send Mail Using A Variable To Define The "From" User?

Jun 2, 2011

The company I work for has an application where various users can log in and add their own "clients". Currently, via sql mail a confirmation email goes out to the client who has been added but the "From" value is generic i.e.Admin@CompanyA.com. What we need is a way for an email message to be sent to the new client but have the "From" email be that of the user adding the new client. When a user registers to use our system they supply basic info including their email, so when they log in and then add a client we would like to have an email sent to that client but have the "From" address be that of the logged in user instead of the generic one from our company. The email would have to be sent from our company's server but we want the sendee to be able to directly "reply" to the sender's email.

View 2 Replies

Why Define A Variable "As Long"

Apr 20, 2011

Why define a variable "As Long"? And how does it differ from "As Variant"?

View 1 Replies

C# - Create A Collection Of Variable Binding In A Class?

Apr 15, 2010

I'm trying to create a collection of variable binding in a class.It is intended to look something like this:

Dim x as integer, s as string
Dim c as new VBindClass
x = 1
s = "Hello"

[code]....

Is there some function that allow us to retrieve a unique ID for a given variable and also get/set based on variable?

Update:At last, I've managed to found the answer. Here's the code:

Dim gh As Runtime.InteropServices.GCHandle = Runtime.InteropServices.GCHandle.Alloc(obj)
Return Runtime.InteropServices.GCHandle.ToIntPtr(gh).ToInt64

View 2 Replies

Assigning The Collection Returned By Computer.FileSystem.GetFiles To A Variable?

Sep 14, 2010

Do you know how to declare a variable that can hold the result of a call to GetFiles?

I don't know how to do this, so I am using the following verbose/duplicative version:
Dim l_v_String_FoundFile As String
If My.Computer.FileSystem.GetFiles("A:u_Au_W", FileIO.SearchOption.SearchAllSubDirectories,

[code].....

View 5 Replies

Assigning The Collection Returned By My.Computer.FileSystem.GetFiles To A Variable

Mar 10, 2012

Do you know how to declare a variable that can hold the result of a call to GetFiles?

I don't know how to do this, so I am using the following verbose/duplicative version:

Dim l_v_String_FoundFile As String
If My.Computer.FileSystem.GetFiles("A:u_Au_W", FileIO.SearchOption.SearchAllSubDirectories, l_v_String_FileMask).Count = 1 Then

[Code].....

View 14 Replies

Bind An IEnumarable Collection To A Datagrid (items Of Variable Contents)?

Aug 11, 2011

While working with an excel file (.xlsx), the data I get from it is an IEnumerable(of Dictionary). When I bind this to my datagrid, I get the problem that I only see 2 columnsI've been tracing this problem and discovered that in the first row in the excel, there are only 2 values (cell C and D). I think the binding to datagrid looks at this first row to create its headers. This results in my datagrid only showing columns C and D.

View 1 Replies

Office Automation :: Garbage Collection When Reassigning Object Variable

Jan 23, 2009

If I use a single variable of type Excel.Worksheet to reference Worksheet1, and then change it to Worksheet2, Worksheet3 and so on, is it adequate to simply do "Marshal.FinalReleaseComObject(worksheetVariable)" once at the end? Or would I be left with some references still in memory? In other words, do I need to do a "Marshal.FinalReleaseComObject" before each re-assignment?

View 3 Replies

Define "what My Variable Will Be"?

Jan 27, 2011

So I have this:

Dim aBoolean As Boolean = True

Will it make any difference to just do this?

Dim aBoolean = True

In other languages, I believe it was a good practice to also define the type of variable it would be, for performance or something. I am not entirely sure with VB.NET.

View 4 Replies

.net - Multiple "= New" With The Same Variable - Does Garbage Collection Dispose

Jul 30, 2009

Dim x as whatever
Try
x = new whatever(1)
something is done with x

[code]....

What happens to x = whatever(1)Does garbage collection find the pointer to the first new and destroy it or what?

View 2 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

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

Are Interfaces Used Often

Oct 16, 2009

Are Interfaces used often? Need opinions.

View 4 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 - Casting Interfaces And MEF?

Mar 13, 2009

I have the following problem with MEF: Interface definition to be used by host:

Public Interface IExecuteDoSomething
Inherits IAddinSettings
Event DataReceived As EventHandler(Of DataReceivedEventArgs)
Function DoSomething() As Boolean
End Interface

[Code]...

Everything seems to work fine until the Button2_Click routine is executed, then an InvalidCastException is thrown with the info:Unable to cast object of type 'System.Collections.Generic.List1[SharedLibrary.IExecuteDoSomething]' to type 'System.Collections.Generic.List1[SharedLibrary.IAddinSettings]'.

How can i solve this problem, because the imported object implements both of the interfaces?

View 1 Replies

A To Z Usage Of Interfaces In .NET?

Dec 30, 2011

In this discussion let us discuss every usage of interfaces in .NET. Any real time examples and difficulties in using interfaces can also be discussed here.

View 6 Replies







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