PC Review


Reply
Thread Tools Rate Thread

Creating a nullable type using Activator

 
 
=?Utf-8?B?RGVyZWtH?=
Guest
Posts: n/a
 
      19th May 2006
Hi

I am trying to create an instance of a nullable type using System.Activator
for example

t is passed in from the caller and is the Type info for a nullable type or
can be a standard type i.e string, int etc.

object value = Activator.CreateInstance(t);

value always returns null


 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      19th May 2006
>value always returns null

That makes sense since you haven't specified a value for the instance.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
Giuseppe Lippolis
Guest
Posts: n/a
 
      19th May 2006
Hello DerekG,
object o = typeof(Nullable<>).MakeGenericType(new Type[] { typeof(int)
});

> Hi
>
> I am trying to create an instance of a nullable type using
> System.Activator for example
>
> t is passed in from the caller and is the Type info for a nullable
> type or can be a standard type i.e string, int etc.
>
> object value = Activator.CreateInstance(t);
>
> value always returns null
>



 
Reply With Quote
 
=?Utf-8?B?RGVyZWtH?=
Guest
Posts: n/a
 
      22nd May 2006
Hi Giuseppe,

Thanks for the reply, this has helped me solve the problem. Thanks for your
help.

"Giuseppe Lippolis" wrote:

> Hello DerekG,
> object o = typeof(Nullable<>).MakeGenericType(new Type[] { typeof(int)
> });
>
> > Hi
> >
> > I am trying to create an instance of a nullable type using
> > System.Activator for example
> >
> > t is passed in from the caller and is the Type info for a nullable
> > type or can be a standard type i.e string, int etc.
> >
> > object value = Activator.CreateInstance(t);
> >
> > value always returns null
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activator::CreateInstance( unmanaged type ) muriwai Microsoft VC .NET 2 19th Aug 2008 08:51 AM
Activator.GetObject Method (Type, String) newscorrespondent@charter.net Microsoft Dot NET Framework 5 17th Jul 2006 01:34 PM
Activator.GetObject Method (Type, String) newscorrespondent@charter.net Microsoft C# .NET 5 17th Jul 2006 01:34 PM
Activator.CreateInstance Type problem Frank Pleyer via .NET 247 Microsoft C# .NET 2 5th Aug 2004 09:17 AM
How to Activator.CreateInstance a Type from within an other assembly? Matthias Straka Microsoft Dot NET Framework 1 9th Jan 2004 06:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:28 AM.