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 7927
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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: 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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
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...
| |