Please tell me there is a better way :-D
....
public static bool IsNullableType(Type paramType)
{
return paramType.IsGenericType &&
paramType.GetGenericTypeDefinition() == typeof
(Nullable<>);
}
public static bool IsNullableTypeMatch(Type paramType, Type
argType)
{
return IsNullableType(paramType) &&
argType.IsValueType &&
paramType.FullName.Contains(argType.FullName); //
**********Kludge***********
}
- paramType {Name = "Nullable`1" FullName = "System.Nullable`1
[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]]"} System.Type {System.RuntimeType}
- argType {Name = "Int32" FullName = "System.Int32"} System.Type
{System.RuntimeType}
IsNullableTypeMatch(...) -->
Nullable<Int32with Int32 -- returns true
Nullable<OtherValueTypewith Int32 -- returns false
Nullable<Int32with OtherValueType -- returns false
Any ideas how I can remove my kludge???
Many thanks for any help,
Jon 2 2496 jo*****@gmail.com submitted this idea :
Please tell me there is a better way :-D
...
public static bool IsNullableType(Type paramType)
{
return paramType.IsGenericType &&
paramType.GetGenericTypeDefinition() == typeof
(Nullable<>);
}
public static bool IsNullableTypeMatch(Type paramType, Type
argType)
{
return IsNullableType(paramType) &&
argType.IsValueType &&
paramType.FullName.Contains(argType.FullName); //
**********Kludge***********
}
- paramType {Name = "Nullable`1" FullName = "System.Nullable`1
[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]]"} System.Type {System.RuntimeType}
- argType {Name = "Int32" FullName = "System.Int32"} System.Type
{System.RuntimeType}
IsNullableTypeMatch(...) -->
Nullable<Int32with Int32 -- returns true
Nullable<OtherValueTypewith Int32 -- returns false
Nullable<Int32with OtherValueType -- returns false
Any ideas how I can remove my kludge???
Many thanks for any help,
Jon
This should work:
public static bool IsNullableTypeMatch(Type paramType, Type argType)
{
return IsNullableType(paramType) &&
argType.IsValueType &&
paramType.GetGenericArguments()[0] == argType;
}
Hans Kesting
Hans Kesting wrote:
jo*****@gmail.com submitted this idea :
>Please tell me there is a better way :-D
...
public static bool IsNullableType(Type paramType) { return paramType.IsGenericType && paramType.GetGenericTypeDefinition() == typeof (Nullable<>); }
public static bool IsNullableTypeMatch(Type paramType, Type argType) { return IsNullableType(paramType) && argType.IsValueType && paramType.FullName.Contains(argType.FullName); // **********Kludge*********** }
- paramType {Name = "Nullable`1" FullName = "System.Nullable`1 [[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"} System.Type {System.RuntimeType}
- argType {Name = "Int32" FullName = "System.Int32"} System.Type {System.RuntimeType}
IsNullableTypeMatch(...) -->
Nullable<Int32with Int32 -- returns true Nullable<OtherValueTypewith Int32 -- returns false Nullable<Int32with OtherValueType -- returns false
Any ideas how I can remove my kludge???
Many thanks for any help, Jon
This should work:
public static bool IsNullableTypeMatch(Type paramType, Type argType)
{
return IsNullableType(paramType) &&
argType.IsValueType &&
the IsValueType check here is unnecessary
paramType.GetGenericArguments()[0] == argType;
}
Hans Kesting
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ESPNSTI |
last post by:
Hi,
Please don't shoot me if the answer is simple, I'm new to .Net and C# :)
..
I'm attempting to convert a nullable type to it's "non-nullable" type in a
generic way (without knowing what...
|
by: shawnk |
last post by:
Given several nullable boolean flags;
bool? l_flg_01 = true;
bool? l_flg_02 = false;
bool? l_flg_03 = true;
bool? l_result_flg = null;
I would have liked...
|
by: Larry Lard |
last post by:
There seems to be something a bit lacking in the way the dataset
designer thing deals (or rather doesn't) with nullable fields in
VS2005. Maybe it's cos I'm using VB2005 Express (which is variously...
|
by: rubikzube* |
last post by:
Hi.
I'm trying to write a snippet of code to detect if a variable is a
nullable<t> struct, and I can't figure out the right syntax or if such
a thing is even possible... Below are the results...
|
by: Joe Bloggs |
last post by:
Hi,
Can someone please kindly show me how to determine if a type (read value
type) is Nullable.
MSDN has this KB:
How to: Identify a Nullable Type (C# Programming Guide)...
|
by: GG |
last post by:
I am trying to add a nullable datetime column to a datatable fails. I am
getting exception
DataSet does not support System.Nullable<>.
None of these works
dtSearchFromData.Columns.Add( new...
|
by: Sam Kong |
last post by:
Hello,
I want to define a generic class which should accept only nullable
types or reference types.
What's the best way to costrain it?
---------
class MyClass<T>{
...
|
by: MLM450 |
last post by:
Is there a way to get the address of the underlying value of a nullable
variable without copying the value? I tried the following, but the
compiler doesn't like it. I need to do this because I am...
|
by: Tony Johansson |
last post by:
Hello!
These two declarations(1 and 2) are the same I assume.
1. System.Nullable<intnullable;
2. System.Nullable<intnullable = new System.Nullable<int();
So because these 1 and 2 are the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |