.net - Nullable Nested Objects And The Maybe Monad?
Sep 19, 2011
I'm struggling to implement a maybe monad - which I've called Nullable in this example.
The Nullable Class is implemented as follows: Public NotInheritable Class Nullable(Of TClass)
Private _value As TClass
Private _hasValue As Boolean
Public Shared Function Create(ByVal value As TClass) As Nullable(Of TClass)
Return New Nullable(Of TClass)(value)
End Function
[Code]...
The way the monad is implemented at the moment I would need to issue the following to access a property on the nested child class dim id = MyParentClass.ChildClass.Value.ID
but ideally what I'd like to be able to do is to have the following statement dim id = MyParentClass.ChildClass.Id and if the ChildClass is null then just return a default value for the property type.
I tried implementing this using Default Properties and setting the Value as default via an attribute but it wouldn't compile. Is that going to be possible or perhaps there is a better way of architecting it - or maybe I just haven't 'got' the maybe monad?
View 1 Replies
ADVERTISEMENT
Jul 21, 2009
I am tring to bind a class to a form where the class contains other class variables. For example:
Class Character
Private _name as String
Property Name as String
[code]......
View 5 Replies
Jan 3, 2012
I have a nested class, let's call it class1 and it has class2 inside it; VB.Net eg:[code]
1) How can I define X number of Class2 objects[let's call it: Node(x) array]** with NEW() subroutine called?' this raises error: dim cls2(n) as new class2 end sub.
2) How can I return actual number of Node() array? [code]Outside my class in main project I define cls1 object:[code]Now an array of class2 is created inside cls1.
3) Now,How can I access All of them[node(x) array which is created inside cls1] with all properties and methods available?
I remember I wrote a ProcessManager class with this functionality in .net 2003, nearly 4 years age, I don't have the code now.
View 1 Replies
Oct 17, 2010
I can't seem to find a lot on how to use events in nested objects. I suspect that I should have access to the events in the nested objects through intellisense if I had done things right. I have many objects with 50 or so properties and I would like to access them with out adding handlers for each one and additional events in parent objects.
Example:
Public Class Form1
Dim WithEvents myCombinedClass As New CombinedClass
[code]....
View 1 Replies
Oct 16, 2010
If you have a class that is a combination of other classes how are you to get the events to bubble up to the parent class?
[Code]....
View 9 Replies
Apr 21, 2010
I have two nested objects, and the form has two ListBoxes, where I want the last to respond to the selection of the former. It can even be some times deeper than 2 levels, which can make it a bit cumbersome. I solve it by raising events in any method that makes an add/delete/rename of these objects, and the form listens for these events, and when fired, clears it's lists, and loops through these objects to populate the lists again. binding lists, but this seems to introduce a few issues. First I need to keep a set of extra lists in the main BLL class, but more importantly, I feel I'm violating the layered structure between the BLL and the form, as in this case, the BLL needs to keep track of the current selected indexes of the listboxes in some variable. So that doesn't feel right, as it makes the BLL vulnerable to what the form does, and I assume is simply principally incorrect.
Following is example of object structure, where two ListBoxes should display "Company Names" and "Employee Names", and the Employee name listbox obviously change according to the selection in the Company Name listbox.
Public Class Form1
private _main as New Main
...
End Class
[code]....
View 2 Replies
Aug 27, 2009
I have an RDLC report that I am rendering directly to the Response Stream as PDF (rather than using the ReportViewer). In the code that renders the report, it's DataSource is bound to a List(Of ClassA) objects defined in a custom assembly. This seems to work for the most part. My problem is that I can't seem to handle the situation where a nested object is null. For example, given ClassA and ClassB (the nested object) defined as follows:
Public Class ClassA
Public Id As Integer
Public Name As String
[Code]....
the report displays "#Error" if TheNestedObject is null. If TheNestedObject is not null, it correctly displays the Name.
View 3 Replies
Sep 23, 2009
An old Yet Another Language Geek blog post explaining monads describes adding a SelectMany extension method to C# in order to extend the linq syntax to new types.I've tried it in C# and it works. I did a straight conversion to VB.net and it doesn't work. Does anyone know if VB.net supports this feature or how to use it?
Here is the C# code which works:
class Identity<T> {
public readonly T Value;
public Identity(T value) { this.Value = value; }
}
[code]....
View 2 Replies
Sep 24, 2010
so far i got
code
For Each item As Reflection.FieldInfo In GetType(NameSpace.ClassWithNestedClasses).GetFields
rtfAppend(item.Name & ":" & Tab & item.GetValue(Me))
Next
For Each item As Reflection.PropertyInfo In GetType(NameSpace.ClassWithNestedClasses).GetProperties()
[code]...
which gets me the simple string vars and properties of my top class, but how can i apply this to loop through all sub classes and get there vars and props?
View 1 Replies
Sep 17, 2009
I accidently wrote some code today that was like this[code]...
I immediately noticed the issue, but I had already hit the run button. It compiled successfully, I ran it through to the section and it threw an exception.
You can't do this in C#, it gives a compile error "cannot convert from 'int?' to 'int'".
Is there an 'Option Explicit' type switch that I can turn on to ensure that this sort of error does not occur again?
View 1 Replies
Dec 5, 2011
make objects from the ToolBox using code instead of changing existing objects invisible then visible later?
View 7 Replies
Jun 23, 2012
I am getting this error, Not sure why it is happening "Error The SqlParameterCollection only accepts non-null SqlParameter type objects, not Int32 objects."I have tried with all sorts of possibilties, now try to enter default data as dummy data,
Using connection As New SqlConnection
connection.ConnectionString = ConfigurationManager.ConnectionStrings("DentalDeviceConnectionString").ConnectionString
connection.Open()[code].....
View 1 Replies
Jan 29, 2011
I have a program like this.
Module Module1
Public Class Mstr
Public Property Prop1 As String
Public Property Prop2 As String[code]....
But it is not working as I expect it to. You can see it from.The DtlsB properties of all three DtlsA objects are having values from last iteration.
View 1 Replies
Jan 6, 2011
I want to let the user input objects to a richtextbox 1 object on each line, and somehow use Random.Next to select pseudorandomly a few objects, the number 'few' inputted in a textbox.
View 9 Replies
Jan 18, 2012
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using conn As New SqlConnection("Database=Clinic_Management_System;Data Source=.SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|Clinic Management System.mdf")
Dim cmdRecord As SqlCommand
[code]....
View 2 Replies
Feb 7, 2010
I have a user control that inherits the FW ListView and I need to dispose of two objects when the form's disposing of it's objects. Here's what I've concluded already, am I on the right track?
[Code]...
View 3 Replies
May 1, 2009
long story short, I have created a ListView type control, using UserControls for the parent control and the ListViewItems. Most the of the control is written and works fine, right up to the point where I tried to replicate the 'Control.SelectedItems(0).Index' property and the 'SelectedIndexChanged' event.
Each child object knows its index value, and could pass this value via the SelectedIndexChanged event (assuming this is how it works in a normal ListView control -- user clicks on an item, and that item fires an event updating the selected index value in the parent object).
How does the child object raise an event in the parent object? I have a feeling this could be done with Delegates, but I'm still learning about their usage.
View 1 Replies
Aug 9, 2011
getting the following error Unable to cast object of type 'System.Object[]' to type 'OrderService.webdirect_WebLinesRow[]'. On the line
webdirect(web_companyID, web_locationCode, web_customerNumber, web_orderNumber, web_orderReference, web_orderDate, webLinesArray.ToArray(), o_Company, o_LocationCode, o_CustomerNumber, o_OrderNumber, o_OrderStatus, o_OrdDescrip, webRespArray)
I created the webLinesArray.ToArray() array as such
Dim webLinesArray As New ArrayList()
Am I missing an additional cast or something ?
View 1 Replies
Aug 28, 2008
I want to compare two objects to check if all the properites of both the object have same value or not. for this i need to use the reflection to enumarate through all the properties of an object and check the value of the property. To try the code just i have written a Employee Class having Two Properties EmployeeNo and EmployeeName. I am creating an object of the Employee class and need to write a function that can list the values of all the properties in the class.
[Code]...
View 2 Replies
Dec 5, 2011
I have a bigger code block which I have recreated in this simpler example:
[Code]...
View 1 Replies
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
Jun 27, 2012
Can Nullable Types be used in VB.NET? If so, is it possible to have a Nullable Integer that I can use with a field that accepts NULL in SQL Server?
View 4 Replies
Aug 25, 2010
I'm converting an Access VBA app to VB.NET. It has dates defined as variants or objects to handle null values. I thought this would be a great chance to use the Nullable type. But I can't get it to work. Either it is inappropriate for what I am trying to use it for, or I am doing it wrong. Anyone know how to use it? Reader is a SqlDataReader.
[Code]...
I was hoping I didn't have to put a lot of If .. Null statements throughtout the code, but that is my only option unless someone has any other idea.
View 11 Replies
Sep 15, 2011
I have the following line of code:
CType(IIf(CBool(product.IsDiscontinued Is Nothing Or product.IsDiscontinued = True), False, True), Boolean?)
What does the Boolean? mean at the end. I have seen it used on other data types as well.
View 3 Replies
May 6, 2009
I have a Nullable DateTimePicker but it lacks a vital property, that is to be able to change its ForeColor, anyone who has some suggestion on how can this be done? Or perhaps a free nullable DateTimePicker out there that supports changing of backcolor and forecolor?This is C# but it should not be different with .Net, and I prefer posting it here since there is more traffic here over the C# section.
using System;
using System.Collections.Generic;
using System.ComponentModel;[code].....
View 2 Replies
Jan 31, 2012
Okay, none of the previous questions I have seen with this error seem to apply in this situation.tEmp is a class that contains (among other things) two nullable date fields.[code]During a routine on my form, I am attempting to see if the following conditions are true[code]I get the above error (the title of question), but when I hover over the debugger, NextReview and InsuranceEligibleDate are both Nothing (which is correct for the employee I am looking at).I am using VB2010, and the Properties in the Employee class are using the new way of declaring Properties (i.e. no set/get)
View 4 Replies
Dec 15, 2010
dim str as nullable(of string) is this syntax incorrect?
View 1 Replies
Feb 15, 2011
C#'s 'as' keyword will let you do this: int? input = value as int? Here's what I would assume the vb.net equivalent would be: Dim input As Integer? = TryCast(value, Integer?) There's an intellisense error in the TryCast stating the operand must be a reference type but Integer? is a value type.
Intellisense on Nullable(Of Integer) says 'Represents an object whose underlying type is a value type that can also be assigned null like a reference type.' It seems C#'s 'as' handles this like a reference type where TryCast doesn't have this built in. In VB10 I was able to take advantage of the new CTypeDynamic function to do the casting. Conversion.CTypeDynamic Method
Dim input As Integer? = CTypeDynamic(Of Integer?)(value)
Or:
Dim input As Integer? = CTypeDynamic(Value, GetType(Integer?))
There's a cost here as CTypeDynamic examines the type at runtime.
My question is what is the elegant way to handle this without CTypeDynamic?
View 6 Replies
Nov 15, 2011
Dim input As Integer? = TryCast(value, Integer?)There's an intellisense error in the TryCast stating the operand must be a reference type but Integer? is a value type.Intellisense on Nullable(Of Integer) says 'Represents an object whose underlying type is a value type that can also be assigned null like a reference type.'It seems C#'s 'as' handles this like a reference type where TryCast doesn't have this built in.
View 1 Replies
Nov 17, 2010
I am a c#/asp.net developer and I am having to work on a VB/asp.net. I have two variables
Dim originalDate as DateTime?
Dim newDate as DateTime?
Both nullable datetimes, originalDate is a nullable date I am getting from the database and newDate time is set in code, I need to compare them, they can either both have dates, neither have dates or one have and one not.
I have a bit of code as follows:
if origEndDate = origEndDate then
When both origEndDate and origEndDate are "nothing" this statement is false (well when I run it in the watch window it comes back as nothing)!I don't understand why this is the case because I was under the impression doing an "=" compares the two values and as they are the same surely it should be true? What syntax should I be using as in C# I can do the above as so:
if (origEndDate == origEndDate) { }
and it will come back as true.
View 4 Replies