My type contains constructor with nullable parameter like
public class Iandmed {
public Iandmed(DateTim e? miskuup) {}
}
I tried to get its constructor parameter type name using
Type t = typeof(Iandmed) ;
ConstructorInfo c = t.GetConstructo rs()[0];
ParameterInfo p = c.GetParameters ()[0];
p.ParameterType .Name returns wrong values for nullable types, in this case
"Nullable`1 "
How to get exact type name:
"DateTime?"
Andrus. 2 7926
Andrus <ko********@hot .eewrote:
My type contains constructor with nullable parameter like
public class Iandmed {
public Iandmed(DateTim e? miskuup) {}
}
I tried to get its constructor parameter type name using
Type t = typeof(Iandmed) ;
ConstructorInfo c = t.GetConstructo rs()[0];
ParameterInfo p = c.GetParameters ()[0];
p.ParameterType .Name returns wrong values for nullable types, in this case
"Nullable`1 "
How to get exact type name:
"DateTime?"
Don't use the Name property - use other properties to get specific
parts. In particular, the FullName property gives
System.Nullable `1[[System.DateTime , mscorlib, Version=2.0.0.0 ,
Culture=neutral ,PublicKeyToken =b77a5c561934e0 89]]
Alternatively you can use
p.ParameterType .GetGenericArgu ments()[0]
to get the DateTime part on its own, or
Nullable.GetUnd erlyingType(p.P arameterType)
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
On 2007-11-11 15:28:06 -0800, "Andrus" <ko********@hot .eesaid:
[...]
p.ParameterType .Name returns wrong values for nullable types, in this case
"Nullable`1 "
How to get exact type name:
"DateTime?"
I don't have the answer off the top of my head. But I can tell you
that you are getting the correct type name. "DateTime?" is actually
equivalent to "Nullable<DateT ime>", thus the generated generic type
name.
You'll want to research how to obtain the generic paramter type
information from a concrete instance of a generic class. That will
provide the information you're looking for. Unfortunately, I don't use
reflection enough to be able to tell you the exact answer, but
hopefully that gets you pointed in the right direction.
Pete 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 specific type the nullable type is.)
The reason I'm trying this is because when I attempt to pass a nullable type
value to a SqlCommand parameter and then attempt to execute it I the
following error:
"No mapping exists from object type...
|
by: Kevin Yu |
last post by:
hi all
since the DateTime can't be assign null, the min value is set to 1901 or
something, if in a application design, the date field can be null, so in
between the UI and the DB, the business logic has to take care of the
conversion?? e.g when inserting DateTime.minvalue into db, (especially when
using store precedure, it seems that pass null parameter to a store
precedure cause problem.), the store procedure must translate the minvalue...
|
by: Mark Rae |
last post by:
Hi,
In v1.1 I used to simulate nullable datatypes with structs. e.g.
public struct NullableString
{
private readonly String pstrValue;
private readonly bool blnHasValue;
public NullableString(String strValue)
{
|
by: Steven Livingstone |
last post by:
Bit of advice here folks.
I am creating a default constructor that just initializes a new instance of
my object and a secon constructor that takes an ID and loads an object with
data from the database for the given ID. I could just leave two separate
constructors, or i could just have the default one call the second with a
"-1" as the ID. This means that the initialization of certain fields can be
based on whether my ID is -1 (for lazy...
|
by: Joe Bloggs |
last post by:
Hi,
compiling the following code:
public class App
{
static void Main()
{
int? x = 5;
bool? i = null;
| |
by: Niall |
last post by:
I'm experience problems very similar to those reported in this thread on
dotnet.framework on May 16 at
(http://groups.google.com/group/microsoft.public.dotnet.framework/browse_thread/thread/c1dd4f0a021a0e71/1ae86cd754c7b7d2?lnk=st&q=&rnum=3&hl=en&utoken=2KAcT0QAAACAT_kPml7nPanGq5_khmjXM3lTuJUrpchkk4PfyJ8QBJNg0tGVFuqI3uPOVaXa-mNYEzHwTZsVie9Lz8ynrMUKZDW0biiNx_26ZoVcD0w9aA).
Steven Cheng from MS was involved in the discussion, but it didn't seem...
|
by: senfo |
last post by:
I'm trying to pass a Nullable type as a parameter to the TryParse()
method (both int and float types) and I'm not having any luck. I've
tried casting as well as passing just the T.Value property; however,
doing this generated a compiler error indicating that it's not possible
to pass a property as an out or ref parameter.
Other than using a temporary (non-nullable) variable, I haven't been
able to come up with a solution.
Example:
|
by: =?Utf-8?B?VGVycnk=?= |
last post by:
I have a generic function I am using to check constraints, an example of
which is the following:
Public Function ValidateMinValue(Of t As IComparable)(ByVal PropertyName As
String, ByVal value As t, ByVal min As t) As Boolean
Dim newMessage As String = String.Empty
If value.CompareTo(min) < 0 Then
newMessage = String.Format("{0} must not be less then {1}, please
enter a valid value.", PropertyName, min)
|
by: jon.rea |
last post by:
Please tell me there is a better way :-D
....
public static bool IsNullableType(Type paramType)
{
return paramType.IsGenericType &&
paramType.GetGenericTypeDefinition() == typeof
(Nullable<>);
}
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |