Tuesday, December 06, 2005 - Posts
Here is an interesting blog entry on the limitations of Generics polymorphism:
http://www.geekswithblogs.net/michelotti/archive/2005/12/05/62273.aspx
.
R
Right now there are only two books out there that cover Generics, and out of the two only one is dedicated to Generics. I ordered
Professional .NET 2.0 Generics
last week and it should be arriving in the mail any day now. I am in the process of reading Juval Lowy's book. As I finish the books, I will provide feedback.
For an updated listing of .NET Generic books, please visit the
StrongTypes.com books section
.
Professional .NET 2.0 Generics (Programmer to Programmer)
by Tod Golding
The power and elegance of generic types have long been acknowledged. Generics allow developers to parameterize data types much like you would parameterize a method. This brings a new dimension of reusability to your types without compromising expressiveness, type-safety, or efficiency.
Programming .NET Components, 2nd Edition (Paperback)
by Juval Löwy
Brilliantly compiled by author Juval Lowy, Programming .NET Components, Second Edition is the consummate introduction to the Microsoft .NET Framework--the technology of choice for building components on Windows platforms.
R
The .NET Framwork 2.0 introduces
Eval()
.
Eval()
is a shortcut for
Container.DataItem()
. Since
Eval()
uses Reflection, it causes overhead. From a optimization standpoint, it is better to use
Container.DataItem()
.
VB.NET
Container.DataItem()
C#
DataReader:
((System.Data.Common.DbDataRecord)Container.DataItem)[]
DataSet:
((System.Data.DataRowView)Container.DataItem)[]
R
I just published an article on Generic Collections. It demonstrates a basic use of a Generic collection as well as compares non-Generic and Generic collections.
Generic Collections Article
R
C# Version 3.0 Specifications
Have you ever wondered what the next version of C# (3.0) has to offer? Microsoft has published the specifications and they can be downloaded at
http://tinyurl.com/baoh8
.
R
Lets say you have multiple DataKeys assigned to the DataKeyNames property of the GridView control where only one DataKey will have a value and the rest will be null. Based on the non-null value, you want to trigger a conditional. I've discovered an easy to accomplish this is using Reflection and a GridView event. In this example, the value of my DataKeys are all of type integer.
VB.NET
Private Sub
GridView_Created(
ByVal
sender
As Object
,
ByVal
e
As
GridViewRowEventArgs
)
If
e.Row.RowType = DataControlRowType.DataRow
Then
Dim
nKeyVal
As Integer
If
g
ridView.DataKeys(e.Row.RowIndex).Values(
"K
eyName1"
).GetType() ==
Type
.GetType(
"System.Int32
"
)
Then
nKeyVal =
g
ridView
.DataKeys(e.Row.RowIndex).Values
(
"K
eyName1"
)
' Do something
End If
If
g
ridView.DataKeys(e.Row.RowIndex).Values
(
"K
eyName2"
).GetType() ==
Type
.GetType(
"System.Int32
"
)
Then
nKeyVal =
g
ridView
.DataKeys(e.Row.RowIndex).Values
(
"K
eyName2"
)
' Do something
End If
If
gridView.DataKeys(e.Row.RowIndex).Values
(
"K
eyName3"
).GetType() ==
Type
.GetType(
"System.Int32
"
)
Then
nKeyVal =
gridView
.DataKeys(e.Row.RowIndex).Values(
"K
eyName3"
)
' Do something
End If
End If
End Sub
C#
private
void
GridView_Created(
object
sender,
GridViewRowEventArgs
e)
{
if
(e.Row.RowType == DataControlRowType.DataRow)
{
int
nKeyVal;
if
(
g
ridView.DataKeys[e.Row.RowIndex].Values[
"K
eyName1"
].GetType() ==
Type
.GetType(
"System.Int32
"
))
{
nKeyVal = (
int
)
g
ridView
.DataKeys[e.Row.RowIndex].Values[
"K
eyName1"
];
// Do something
}
if
(
g
ridView.DataKeys[e.Row.RowIndex].Values[
"K
eyName2"
].GetType() ==
Type
.GetType(
"System.Int32
"
))
{
nKeyVal = (
int
)
g
ridView
.DataKeys[e.Row.RowIndex].Values[
"K
eyName2"
];
// Do something
}
if
(gridView.DataKeys[e.Row.RowIndex].Values[
"K
eyName3"
].GetType() ==
Type
.GetType(
"System.Int32
"
))
{
nKeyVal = (
int
)
gridView
.DataKeys[e.Row.RowIndex].Values[
"K
eyName3"
];
// Do something
}
}
}
Note:
gridView is the ID of the GridView control.
R
I just published a new article on LearnAsp.com that demonstrates using a Generics List Collection in C# to store the retrieval of all folders, subfolder, and folders within subfolders.
Folders File System Article
R
More Posts