VS 2010 : Exposing An Instance Property As Shared?

May 24, 2010

Suppose I have a class of objects called Porky with a property called IsHuge:

Public Class Porky
Public Property IsHuge As Boolean
End Class

Now I want to make a special kind of Porky -- let's call it UberPorky -- for which I want to change ALL instances to either IsHuge or not IsHuge. What I'd like to do is this:

Public Class UberPorky
Inherits Porky
Public Overrides Shared Property IsHuge As Boolean

[code]....

The trouble is, I can't do that. I'm not allowed to reference MyBase or Me in a Shared property.

View 17 Replies


ADVERTISEMENT

C# - Exposing Property As Variant In .NET For Interop?

Feb 28, 2012

I am creating a wrapper class in .NET (VB.NET as it happens but is equally related to C#) that is exposed to COM and one of the properties I am trying to wrap is a Variant. I thought I would just be able to use an Object, but I get an error: Public Property FieldValue([vFieldID As Object = -1]) As Object cannot be exposed to COM as a property 'Let'. You will not be able to assign non-object values (such as numbers or strings) to this property from Visual Basic 6.0 using a 'Let' statement.*

My property declaration looks like this:
Public Property FieldValue(Optional ByVal vFieldID As Object = -1) As Object
Get

[code].....

View 2 Replies

VS 2010 Exposing Picture Box Drawing Surface?

Dec 27, 2010

studying GDI+ for drawing, there are many suggestions to expose the graphic surface for the paintbox control or a form using e.graphics in the paint event. Can graphics be exposed outside the paint for the picture box control?

In my old vb6 project that I am converting to vb.net 2010, I have several large routines located in a code module that draw lines, circles, etc on a picture box and it is desirable to keep these outside the paint event of the picture box so the same routines can be used to draw on more than one picture box.

In experimenting, I found I can create e.graphics from the picture box paint event and pass it by reference to a drawing routine and the drawing routine seems to work ok on initial experiments but it requires visiting the picture box paint event to get the drawing surface in the external sub.Is this apprach good programming practice or is there a better way to create the graphics surface of a picture box or form in subroutines outside the paint event?

View 1 Replies

Use Shared Vs Instance References?

Mar 3, 2010

As I stated before in my Sorting questions.When is it advisable to use Shared Functions vs Instance Functions References.The problem I posed was that in a threaded application if I was sorting an array of 999999999 elements I typically want to call a shared function that handles this; however in .NET the way to sort is through a .Sort method which you pass an array to be sorted and a function handler; or Comparisson(t of).

My impression is that if in order to do a ClosestToN Sort I would have to calculate the value of N in the array first; then sort and then subtract the value of N from the sorted array.JohnH suggested passing the value of N as a Property in a Class that contained a reference to a sort Algorithm.The benchmark suggested in a 1 thread model it would work faster (which I knew that it would through math, but the accessors I was speculative on; I turned out to be wrong it worked fine either way).

My issue is in a Multi-Thread application creating instances for an accessor may cause memory to fill quickly if I am dealing with 1000's of threads.Is it better in this case to use a slower Shared function, then a faster Instance Function?

View 5 Replies

Access Of Shared Member Through Instance

Nov 6, 2009

After I formatted my laptop and reinstalled Visual Studio 2005, I receive a lot of same error as below message.
"Access of shared member through an instance; qualifying expression will not be evaluated"
If I click the error, it direct me to the line and all 102 error suggest me to add "Windows.Forms." before "DialogResult.OK". Should I add something on "Reference"?

View 4 Replies

Creating A Shared Instance Of An Object?

Feb 13, 2012

I would like to create a global instance of a User Class that can be referenced by all the forms in my MDI application.This object may be set during the login procedure by the Login form but the user attributes are to be available for other forms. For example, MyUser.ID will be required for meeting the audit requirements whenever data is changed.

View 14 Replies

How Many Instance Will A Shared Variable Be Created

Apr 7, 2010

How many instances of a shared variable will be created in a class? just one? correct

[code]...

So, in other words, the DocumentDelivery class will only have one instance of RenderList, correct? can somebody confirm?

View 3 Replies

Ajax - Passing Instance To Shared Method In .NET?

Nov 4, 2010

I have been thrown in at the deep end with an existing VB.NET project at work. I have never used VB.NET before so I am struggling a little. Does anyone know how to solve the following.I need to pass an instance to client side and then pass it to a shared method in order to access instance methods from when the shared method.The starting point is a fileupload control within the HTML of my Contacts.aspx file:

<asp:FileUpload ID="DocUpload1" runat="server" onchange="CallMe();" />

The onchange event calls a javascript method, see below, this uses AJAX PageMethods to called a Shared method in my code behind This is the script code which is in my Contact.aspx file

[Code]...

If anyone knows the solution please could they update the code as I probably won't be able to understand if you just give a description. I just hope I am along the right tracks.

View 1 Replies

.net - Prohibit An Instance From Calling Shared/Static Method?

Aug 27, 2010

Is it possible to prohibit an instance of a class from calling a shared/static method?

For example:

I want to allow this:

ClassName.MethodOne()

But I want to disallow this:

Dim A As New ClassName
A.MethodOne()

The reason this is desirable is that in this case it is semantically confusing if an instance can call the method.

View 2 Replies

C# - Access A Shared/static Member Through An Instance Variable?

Mar 3, 2011

Here's an example of what I'm talking about...

Public Class Sample1

Public Shared Function MyValue() As Integer
Return 0
End Function
Public Sub Code()

[Code]...

Me.MyValue gives a warning in VB.NET and (the equivalent code gives) an error in C#. Is there a particular reason for this? I find it more intuitive/natural to access the shared function using 'Me.MyValue' - but I avoid it to keep my warnings at 0. Did someone else just decide 'Nah, it makes more sense to do it the other way' or is there some technical reason I don't understand?

EDIT: I was thinking of it wrong, more like a 'sub class' in OOP. Even if something is declared in the base class, you access it through the instance you have. But that relationship is not the same with shared or static.

View 6 Replies

Overload Shared Methods On Non-instance Types Using Extensions?

May 14, 2012

I want to extend the BitConverter class with an overload of ToString() that takes a parameter of type Char, representing a value delimiter.Why? By default, the ToString() call returns a string representation of a byte array, delimited by dash symbols. The signature does not allow you to specify a different delimiter, which I find very unfortunate.Now because this is not an instance type, or maybe because I'm overloading a shared method, I'm having a hard time finding the proper syntax to define my extension method.What am I doing wrong here, causing the overloads to not show up in IntelliSense:

Imports System.Runtime.CompilerServices
Module BitConverterExtensions
<Extension()>

[code].....

View 1 Replies

Purpose Of Using Shared Methods That Return An Instance Of A Class?

Oct 11, 2010

What is the purpose of using shared methods that return an instance of a class, as opposed to a constructor?

ie: in VB.net, the system.drawing.color class has shared method "FromArgb(int, int, int) as color". This is different from java's implementation which simply is a constructor that takes three ints. Why the decision to do one or the other?

View 1 Replies

Sql Server - Access A Shared Function From An Instance Of An Object?

Dec 28, 2010

The context of this question is that I am trying to debug performance issues (apart from the obvious ones I already know about and can find).I inherited a code base (VB.NET) for an ASP.NET app. This is an app that was developed way back in .NET 1.1 days, and was the first .NET app for a lot of the developers who worked on it.

In this code base is a class called DatabaseUtility that contains several Shared Public methods as well as non-Shared Public Functions and Subs for CRUD operations to the database (SQL Server).

It is common in my "BL" that a method creates an instance of the DatabaseUtility which essentially figures out what the connection string should be and opens a connection, as well as giving the developer a handle to the other methods contained within it.Dim utility as New DatabaseUtility()

Once I have that, I start to create parameters that I am going to pass to one of the methods in DatabaseUtility (like GetDataSet). There is a Shared method in my DatabaseUtility called CreateParameter which does essentially that. It creates a SqlParameter object so I can add it to a Parameters collection.

Now, the code base is littered with a lot of this:

utility.CreateParameter(...)However, because CreateParameter is a Shared method, I am not sure what is going on behind the scenes. I know because it is a Shared member that an instance of the DatabaseUtility is not created when I call it like this:DatabaseUtility.CreateParameter(...)

However, because I am calling it from an instance (utility), does that change the behavior at all?

View 1 Replies

Moving Large Instance Method To Shared And Creating Stub?

Jun 5, 2011

If I have a very large function/sub in a class that is an instance method (i.e., not Shared), do I gain or lose anything by moving that to a shared method and then declaring a small stub method for the instance use?

I.e., I go from this:
Public Sub MyBigMethod(ByVal Foobar As String)
If String.IsNullOrWhitespace(Foobar) Then
Throw New ArgumentNullException("Foobar")
End If
[Code] .....

My thinking is I save on memory size per each instance of the object. Because each instance only has to lug around the stub method which handles calling the shared version and passing an instance of itself to the shared method so that it can do whatever it needs to do. But I'll wager that I sacrifice a very teensy amount of speed because of the added function call overhead.

View 1 Replies

Possible To Have A Shared/Static Dependency Property?

May 25, 2010

[using VB.NET, but I can easily read C# code in responses]I have a class called QuestionClipboard with ALL shared methods/properties. I previously had a QuesitonClipboard.doesClipboardHaveContent function that returned true/false if there was a Object on my 'clipboard'.I'd prefer to implement a Dependency Property so I can allow this true/false value to participate in data binding.The "GetValue(dp as DependencyProperty)" method requires an object instance, which would mean that my Property CAN'T be shared!Here is what the code would look like in my perfect world... Of course, the word "Shared" before the property declaration renders this code useless.

Private Shared clipboardHasContentPropertyKey As DependencyPropertyKey = DependencyProperty.RegisterReadOnly("clipboardHasContent", GetType(Boolean), GetType(QuestionClipboard), _

[code]....

View 1 Replies

Shared Property Is Used For All Application Instances?

Mar 17, 2010

i have an multi-threading applicaton. so I am using system.threading.thread class to create thread. each threads call its own class and inside each class i am accessing webservices. I need to have status returned from each webservice. thats why I defined a shared property as list of generic object which will be updated within each class called its thread. but I have an hesitation that when I run application on the server. this shared object will be used by all instances of web application. Is it true or shared properties is used only for its own instance?

View 5 Replies

Use Shared Property With Class Inheritance?

Jan 12, 2011

I have a base class which defines a shared readonly property like this[code]...

View 5 Replies

Access A Shared Property Of The TestClass Class From The Page.aspx?

Jan 18, 2010

I have:

Page.aspx
Page.aspx.vb
TestClass.vb

I'm trying to access a shared property of the TestClass class from the Page.aspx.This code works fine:

<head>
<script language="JavaScript">
<% if System.Globalization.CultureInfo.CurrentCulture.Name.ToLower = "pt-br" Then %>[code]......

View 2 Replies

Refactoring A Module Into A Class: Changing Shared Fields To Instance Fields

Nov 14, 2011

I'm currently refactoring an old Visual Basic DLL (VB.Net), which stores all of its data in one module called Globaldefinitions as public fields. There are about 200 fields, referenced thousands of times all around the code:

Public Module Globaldefinitons
Public a As Short
...
Public zz10 As Double

[Code]...

I need to change the module into a class with non-shared fields. This means, each and every of these thousands of references needs to reference the instance of that class:

globalDefinitionsInstance.a = 5

How do I go about this efficiently?

Regular expressions operating on the source fall flat. Refactoring tools like Re-Sharper or CodeRush don't seem to offer this functionality. Visual Studio 2010 cannot do it automatically either.

View 2 Replies

Writing To The Eventlog In Win7, With Instance Of Eventlog And .WriteEntry Being A Shared Member

Dec 8, 2010

I have an app the writes to the eventlog correctly in xp. The code does not work in win7.

CODE:

I get an error about inaccessable logs:security. I get that. Run as admin it goes away. I do not want to have to do that every time for every user that runs the app. besides they may not have the rights

So I wanted to make an instance of eventlog and set the Log to write to so it does not search the logs and error out on security.

CODE:

Now i get warnings about "Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated."

How the hell else are you to set the log so that the code will work under win7 with normal user rights AND not get this silly warnings?

I have 71 places that I write to the eventlog. that may or may not be too many but that is for another thread.

CODE:

View 8 Replies

Access Form Property With Instance?

May 15, 2012

In Windows Forms (Vb.net) how can I access the properties without instance (new) ?Form1.Property = "" ? the property deceleration is not static? what is called this way of deceleration?While you can't access Class1.Property!

View 1 Replies

Reference Property Of Instance Via Reflection

Jan 2, 2010

When I got a fieldsinfo-array of a class I know all of it's fields. Now, how can I access all of the fields of an instance of the same class by using the fieldsinfo-array? [code]I'm sure there exists a possiblity to get the value of the instance, but how?

View 5 Replies

Access Of Shared Member, Constant Member, Enum Memberor Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated?

Jun 23, 2009

i changed a class variable to shared so i can access it in all instances of the class, but it caused an error. what is causing this, and how can i fix it?

Private
Shared img As Bitmap
Me
.img = bgImage

View 2 Replies

Entity Framework Navigable Property Not Set To Instance Of Object?

Mar 21, 2012

I have the following query:

Dim queryStudent = (From p In dbContext.Residents _
Where p.people_code_id = people_id _
Where p.year = year _

[code].....

View 2 Replies

C# - Check If A Class Is A New Instance Or Has At Least Once Property Populated Before Saving To Database

May 15, 2012

I thought this would be an easy one but I can't think of a good way to do it.User submits a webform. Based on submitted information I build three classes and assign their properties from received data:

UserInfo userInfo = new UserInfo();
UserAddress userAddress = new UserAddress();
UserEmployer userEmployer = new UserEmployer();

Based on submitted information some classes end up being populated with properties and some do not.

What's the best way to check whether userInfo class, for example, ended up with properties assigned ? I don't want to save a particular object to the database if it doesn't have any real properties assigned and all of them are set to either null or "".

I only want to save the objects that ended up with at least one real property assigned.ps. using NHibernate to save data to db

View 4 Replies

Access Of Shared Member, Constant Member, Enum Member Or Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated

Jun 2, 2011

how do I overcome it? I have created a class and compiled into .dll This code

[Code]...

View 2 Replies

Warning 1: Access Of Shared Member, Constant Member, Enum Member Or Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated

May 31, 2010

In the following code i get a warning at line 59:Warning 1: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.and.. At line 78 I get this Warning:

Warning 2 Property 'SelectedCustomer' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

The program compiles and runs well, but i cant' undesrtand the reason for these warnings. Any Idea ?

1: Public Class Form1
2:
3: 'Form level members
4: Private objCustomers As New ArrayList

[code]....

View 5 Replies

RE Exposing COM Interface To .NET?

Jun 29, 2010

Is it possible to create a VB6 interface that can be implemented in a .NET class? I have the need to call a method in an existing VB6 class that behind the scenes will call either a VB6 or .NET class that utilize the same interface.

MyObject.Type = "clsVB6"
MyObject.DoSomething(intID)
would behind the scenes be utilizing a VB6 class that implemented a 'DoSomething' VB6

[code]....

View 2 Replies

.net - Error Exposing Event Through Interface?

May 19, 2010

I have this interface

Interface IProDataSource
Delegate Sub DstartingHandler(ByVal sender As Object, ByVal e As EventArgs)
Event starting_Sinc As DstartingHandler

[Code].....

View 2 Replies

Exposing A Supporting Class From A Usercontrol

Apr 8, 2010

I have a supporting GridColumn Class that resides in the same class library project as my GridBox usercontrol.It is used in a list of GridColumns as a property.[code]In the Load event of my form I would like to use the .Add method of the List(Of GridColumn) to add columns to the usercontrol.[code]It will not work though because it cannot find the GridColumn class.If I use: "Imports <My Class Library Name>" it works, but I would like it to work without having to do so.Standard controls do this all the time.Am I putting the supporting class in the wrong place?Is there a modifier I that will expose the class when the usercontrol is dropped on a form?As a work around I created a method that adds a column but I would like to know in any case.

View 9 Replies







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