Inheritance - Specify A Return Type Of "Derivative(of T)" For A MustOverride Sub In .NET?
Apr 22, 2010
VB.NET 2008 .NET 3.5 I have two base classes that are MustInherit (partial). Let's call one class OrderBase and the other OrderItemBase. specific type of order and order item would inherit from these classes. Let's call these WebOrder (inherits from OrderBase) and WebOrderItem (inherits from OrderItemBase).
Now, in the grand scheme of things WebOrder is a composite class containing a WebOrderItem, like so:
OK I have a base query that is returning a list (ObjectQuery, actually but I don't think it matters) I have about 5 subtypes based on the main type and I need to filter them. Everything works fine until I want the results to be of the main type (not a subclass) Basically I have a query that includes everything, then I filter out the types that are not checked in a checkedbox list. (asp.net) Lets say I have an Entity named Task, and SubTask1 and SubTask2 that inherit from Task
im currently working on a program to have a program produce a derivative of a function. [code]....
This is the code that I have. The function I am trying to get the derivative for is g(x) = -2x^3 + 3(a+b)x^2 -6abx + 10. In my program a and b will be given by the user and than the derivative will be computed. I am not quite sure if I have done this correctly. Also, I would like the program to output the Maximum and Minimum of the function g(x) on the interval (0,1). I know I will need to use a function for each max and min.The way I have done this is: [code].....
where x and y are the critical points of g(x).Have I done this correctly? I am also a little stuck on how to combine these codes into one so that with the push of a button the derivative is done and a max and min produced.
public delegate UsernameCredentials UsernameRequiredEventHandler( object sender, string endpoint ); public event UsernameRequiredEventHandler UsernameRequired;
On Converting the above code in VB.Net as follow :
Public Delegate Function UsernameRequiredEventHandler(ByVal sender As Object, ByVal endpoint As String) As UsernameCredentials Public Event UsernameRequired As UsernameRequiredEventHandler
I am getting error on the above line saying that "Events cannot be declared with a delegate type that has a return type".I understand that this is not supported in VB.Net.
Is it possible to force the inherited classes to implement a set of New() constructors? I tried with this, but it doesn't work: MustOverride Sub New() MustOverride Sub New(Arg1 as Integer) MustOverride Sub New(Arg1 as String)
I'd like to have a Private or Protected "Setter" for a property that also happens to be an abstract (MustOverride). I'm porting some code from C# to VB and in C# this is pretty straight forward. In VB not so much (for me anyway).
Some code...
In C#... public abstract class BaseClassWithAnAbstractProperty { public abstract int AnAbstractIntegerProperty { get; protected set; } }
[Code]....
The issue seems to be the inability to flesh-out the Get/Set specifics in the declaration.
In my project (which I inherited from someone) there are a lot of functions like:
Public Function DoSomething(ByVal s As String) ' Do something to public properties End Function
And they are called like this:
DoSomething(s)
So the return value is ignored (which is object, as I see in the docs). Is it safe to change all these functions to Subs? Could I break something which isn't so obvious?
I would like to have a function(of T) that returns a list(of T) that is assignable to a variable of list(of T).For Example:
the variable: Private _StandardCodes As List(Of StandardCode) the assignment:[code]....
I'm getting the error "Type paramater 'T' for ... cannot be inferred", as a result I have to use a comparable function to return a list(of Object) and then do:
_StandardCodes = (From x In AMExtensions.queryObject(GetType(StandardCode), "StandardCode") _ Select CType(x, StandardCode)).ToList
I know a little about using a user specified type IE IIf(Of ReturnType)(ByVal expression as Boolean, ByVal TruePart As ReturnType, ByVal FalsePart As ReturnType) As ReturnType...Which works, however I've been trying to get this to work, but can't..
Protected Function InverseSign(Of ReturnType)(ByVal value As Double) As ReturnType Dim result As String Select Case Math.Sign(value) Case -1: result = "+" & Math.Abs(value).ToString()
[code]....
Using try cast just gives me the error saying ReturnType has no class-constraints? whatever that means..But my goal here is to be able to return either a string or double.. However every method I've tried to convert my result string to the ReturnType doesn't work.I've also tried simply overloading the function, but I can't because they only differ by return type. So that didn't work either.
I have an ASP.NET MVC 2 application in which I am creating a custom action filter. This filter sits on the controllers in the application and verifies from the database whether that function is currently available.[code]....
I have a base class with a static function that returns a typed dataset. I have several classes that inherit the base class with a non-static function that returns the same typed dataset. On these methods I get the 'Return type of parameter yadda is not CLS-compliant' I don't understand where this is coming from. I have non unsigned integers/etc. in this dataset.
I have a program which connects to an FTP server. my program needs to retreive the directory list of the server. I am doing this in the style of an OpenfileDialog control. now I can get all the information and fill the listview control. however the function I use to fill the listview control with the directory listing and file listing, returns a list(of string)
Because of this I can't determine if a file is a file and if a folder is a folder. I myself know which of them are because while getting the directorylists I check for a string value of D which means directory. if it doesn't have a D then it's a file.
Currently I have written a function to deserialize XML as seen below.How do I change it so I don't have to replace the type every time I want to serialize another object type ? The current object type is cToolConfig. How do I make this function generic ?
Public Shared Function DeserializeFromXML(ByRef strFileNameAndPath As String) As XMLhandler.XMLserialization.cToolConfig Dim deserializer As New System.Xml.Serialization.XmlSerializer(GetType(cToolConfig)) Dim srEncodingReader As IO.StreamReader = New IO.StreamReader(strFileNameAndPath, System.Text.Encoding.UTF8) Dim ThisFacility As cToolConfig
if i got a function with a try cath block inside and the function should return an integer.how would i do it that the function can return me a the error message?public function test() as Integer
I have the following code: Dim ipAdd As IPAddress = Dns.GetHostEntry(strHostname).AddressList(0) Dim strIP As String = ipAdd.ToString() When I convert to String instead of an IPv4 address like 192.168.1.0 or similar I get the IPv6 version: fd80::5dbe:5d89:e51b:d313 address. Is there a way I can return the IPv4 address from IPAddress type?
What i get from minfo.invoke i am binding to the grid gv1 !!! But unfortunately its not working for all minfo !!!! Few errors are like : return type is not IListSource ,IEnumerable or IDataSource !!!!
returns IEnumerable or IData Source or IListSource !how to do that ?Also if return type is none of these i should display the result in a Textfield by Serializing the data and displaying it as an XML?How to do that too?
Public Shared Function GetAllNotesByUser(ByVal UserID As Guid) As Account (??) Using db As New MyEntity Dim query= (From A In db.Account _
[Code].....
I would then like to pass this to another function to calculate the totals for all the accounts in the collection. Is it best practice to return an Ienumerable, a generic list, I'm just not sure what works best with LINQ and the entity framework.
I am building my own Message Box, I have overloaded the ShowDialog function and i wish to Change the Return Type from DialogResult to my own.To do so , shall i declare an Public Enum within the form and set it as the Return Type, or is there any other proper way?
Im writing a data access layer for my application.There are several functions that need to return a list of items like Employee Name, and EmployeeID so it can be bound to a dropdownlist.What would be the proper datatype to return, a Dictionary?The lists only contain 2 columns, a name and id.
I was playing with vb 2008 express and i created a function with no return type. Basically what it does is i specify a table name and a column name and it returns the value within but it doesn't type it until it gets to the calling variables type. So i have on function that i can use across all my tables.
Eg: dim mydate as date = getvalue("tblSRs", "datelogged") msgbox (mydate) dim desc as String = getvalue("tblSRs", "description") msgbox(desc)
Both return the correct values. were you always able to leave the typecasting till the end and whats the major downfall?
Ok, just needing a 2nd set of eyes looking at this to make sure the error isn't something else other than my LINQ code here. Here's the function class itself:
Public Function GetJacketByPolicyID(ByVal jacketID As Int32) As tblPolicy Dim db As New DEVDataContext() Dim j As tblPolicy = db.tblPolicies.Single(Function(p) p.policyNumber = jacketID) Return j End Function
and here is the code which calls this class function in the web control form itself:
Dim p As tblPolicy Dim j As New Jackets() p = j.GetJacketByPolicyID(3000050)
For some reason it's flagging the 2nd line in the GetJacketByPolicyID function saying the specified cast is not valid. So I'm guessing it's something I'm doing wrong. I'm sure the tblPolicy/tblPolicies class works right since I can create a new instance of a tblPolicy and set a few variables by hand and return it, so that's not it. I've also checked the datarow I'm fetching and there's no null values in the record, so that shouldn't be it either.