Questions tagged [gettype]

1

votes
1

answer
966

Views

How to get underlying type from typed DataSet

I've been searching a lot but I haven't found anything about this question. I'm making a log of my app and I'm printing types of variables and their values. I want to do the same for every object I receive as parameter, and for every object I return too. So I'm returning a typed dataset (MyDataSet t...
EAmez
1

votes
1

answer
1.4k

Views

How to know the data type of value entered by user at runtime in textbox?

How to know the data type of value entered by user at runtime in textbox? My simple example: I've tried it by using GetType(), but it was useless, it always shows System.String, whether I enter int or String.
user2334930
1

votes
1

answer
1.9k

Views

How to get the type of an EF dynamic proxy class without a class instance

Dynamic proxies have names like ClassName_00394CF1F92740F13E3EDBE858B6D599DFAF87AA5A089245977F61A32C75AA22 where the POCO class was simply called Classname. I know to can get the POCO type of an EF dynamic proxy instance with ObjectContext.GetObjectType(instance.GetType()), but is there an easier wa...
Gone Coding
1

votes
1

answer
730

Views

GetType When Type Is Provided As A String

I understand that C# is a staticly typed language and I already read the answers to this SO posting: initialize a class by string variable in c#? My question is a bit different, however. I'm working with a T4 template that provides me with the name of a class as a string parameter. I would give the...
Jazimov
1

votes
1

answer
223

Views

How to get properties of List Items using GetType

I am looking to get Fields / Properties of a particular object of unknown type. I have code that mostly works, but fails when attempting to expand members of a collection (a List, in this case). Here is my code: First the Class definitions: public class Claim { public String icn; public String subs...
Mark Ainsworth
1

votes
1

answer
714

Views

How to use GetType and GetFields?

I'm updating a program and there is about 40 classes. I need to create a function that takes two lists of type object as parameters. Both lists only have one item in them (A version of the item BEFORE any changes were made, and AFTER the changes happened). I'm using these objects to create a single...
MattCucco
1

votes
1

answer
584

Views

How to get class name in code as static string property

I want to get something like this: public class myclass() { public static string ClassName { get { return 'myclass'; } } } Is there a general way to substitude the string 'myclass' in the above code example with the name of the owning class? I know that we can do this in non static way: pu...
Peter Klemm
1

votes
3

answer
1k

Views

Getting type of items of a List at run-time in c#

I need an expression that gets type of every item of a collection. I have a collection like this: var collection = new List{1,2.2,'string','c'}; It's possible to get type of every item of collection like this: var myVariable= collection.Select(item => item.GetType()) But I need creation of this expr...
Merta
1

votes
1

answer
56

Views

Activate type only without knowing the namespace of the type I am trying to activate

I'm not sure this is possible, and the existing answers to this question seem to imply that you need to know the namespace. I am trying to activate a type, but would prefer to avoid specifying the Type's namespace. Is this possible? Of course I would know the Assembly ahead of time. string qualifie...
Nicholas
1

votes
2

answer
415

Views

Calling Methods dynamically

I am trying to call methods dynamically and I have issues. Could some one please help I have the following vb code Module Sub Main if user-input = RP1 then createRP1() elseif user-input = RP2 then createRP2() end if end sub sub createRP1() ... end sub sub createRP2() ,... end sub End Module The Cre...
AVSSM
1

votes
1

answer
1.1k

Views

How-to: Load a type from a referenced assembly at runtime using a string in Silverlight

I have tried this, specifying the assembly name: Type.GetType(string.Format('{0}.{1}, {0}', typeToLoad.AssemblyName, typeToLoad.ClassName)); Which throws the following: The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest Trying the same...
David Perlman
1

votes
1

answer
999

Views

Getting entities of a certain type using entity frameworks return error - LINQ to Entities does not recognize the method 'System.Type GetType()'

I am trying to filter out entities of a certain type. I am using Entity Framework, and I have a parent entity, and various children that inherit from the parent entity. I am trying to filter out one of these children. For example, I have the following structure: Address : Entity PostCode : Address...
Karan
1

votes
8

answer
221

Views

How to extract an object name

i've got a class filled with lists of subclasses: public class ClassOfKb { public List KbDatas {get;set;} public List KbProducts {get;set} } public class Data { public Guid ID {get;set;} public byte[] data {get;set;} public string Name {get;set;} } public class Product { public Guid ID {get;set;} pu...
Raymond Osterbrink
1

votes
3

answer
63

Views

Common integer representation over variable casting?

For a while i've been using: gettype(); to dynamically get the variable cast type, eg: function Type ($Value = null){ return gettype($Value); } echo Type(array()); // Echo array echo Type (1); // Echo integer echo Type(1.2); // echo doubble Whereas, i'm looking for a method to have a common and kno...
Sophie Mackeral
2

votes
1

answer
131

Views

What does (type1)+(type2) means using GetType().ToString()?

I'm writing a little Console app to test some basic MS ProjectServer interop. I can connect to the server with no problems, and I was trying to refactor one of my for (int i = 0; i < projectDataSet.Project.Count; i++) loops for a foreach (var project in projectDataSet.Project) one. When I do the fo...
Bruno Saboia
16

votes
5

answer
36.5k

Views

How to get name of a class property?

Is there anyway I can get the name of class property IntProperty? public class ClassName { public static int IntProperty { get { return 0; } } } //something like below but I want to get the string of 'IntProperty' ClassName.IntProperty.GetType().Name Basically what I want to do is to dynamically sav...
Jeff
18

votes
4

answer
10.3k

Views

Why would System.Type.GetType(“Xyz”) return null if typeof(Xyz) exists?

I have come across a strange behaviour in my (huge) .NET 4 project. At some point in the code, I am referring to a fully qualified type, say: System.Type type = typeof (Foo.Bar.Xyz); later on, I do this: System.Type type = System.Type.GetType ('Foo.Bar.Xyz'); and I get back null. I cannot make sense...
Pierre Arnaud
1

votes
1

answer
1.4k

Views

Type.GetType() visibility issue between projects (Visual C#)

I ran into a peculiarish problem. I am working on a dynamic factory project and my intention is to be able to create new objects based on an XML file. My problem is this: I have a separate project for the base classes for the factory where I have public abstract class DynamicContentFactory where T:...
Sami Anttila
1

votes
2

answer
220

Views

How to tell if ParameterInfo type is a collection?

Is there a way to check whether ParameterInfo is a Collection? I have tried this: ConstructorInfo[] constructorInfos = typeof(T).GetConstructors(); ConstructorInfo constructorInfo = constructorInfos[0]; ParameterInfo[] paramsVar = constructorInfo.GetParameters(); IEnumerable collectionParams = param...
DevDave
20

votes
2

answer
862

Views

Unexpected value of System.Type.FullName

I recently needed to build C# specific name (which must always include global:: specifier) for an arbitrary type and have come accross following issue: // 1 - value: System.String[,,,][,,][,] string unexpectedFullName = typeof( string[,][,,][,,,] ).FullName; // 2 - value: System.String[,][,,][...
Rest Wing
2

votes
5

answer
3.3k

Views

C# Generic T Class TypeOf, is this possible?

I have a class that is generic. Class and depending in the switch statement in the calling code it can be class class class The the method that returns this returns it as an object because the calling code has no idea what it is until after it is set. Is there a way to do this once I get the object...
nitefrog
2

votes
2

answer
1.4k

Views

Type.getType() can't find the class

I have a lot of static methods in a class, I want to get if a certain method is in the class X, and if it is, I want to invoke it. I checked with this: if (Type.GetType('Homework.Homework.Functions').GetMethod(methodName) == null) { Console.WriteLine('No such method.\nPress any key to restart the pr...
shoham
2

votes
4

answer
952

Views

Why does a GetType on a string-property result in a NullReferenceException?

When I call a GetType on a int- or a DateTime-property, I get the expected results, but on a string-property, I get a NullReferenceException (?) : private int PropInt { get; set; } private DateTime PropDate { get; set; } private string propString { get; set; } WriteLine(PropInt.GetTy...
11

votes
3

answer
33.4k

Views

How to get class type by its class name?

namespace Myspace { public class MyClass { } } //This class is in another file. using Myspace; static void Main(string[] args) { Regex regexViewModelKey = new Regex(RegularExpr.ViewModelKeyPattern); string viewModel = regexViewModelKey.Match(match.Value).Value; //Now, vieModel is a string, and its v...
Huan Fu
4

votes
7

answer
295

Views

Is there a way to get the type of the objects stored in a generic list?

Given a generic list of type List how do I find type T? I suppose if the list is populated I could take listInstance[0].GetType() but that seems a bit hackish. Edit: For context, I want to populate a DataTable with columns based on the Properties of an object. Where an object property is a generic l...
Phil Gan
2

votes
3

answer
6.5k

Views

c# casting to type gotten from typename as string

I want to work around the fact that my WCF servicelayer can not handle a generic method like this: public void SaveOrUpdateDomainObject(T domainObject) { domainRoot.SaveDomainObject(domainObject); } so I built this workaround method instead public void SaveOrUpdateDomainObject(object doma...
2

votes
0

answer
232

Views

How to get Type information when ReflectionTypeLoadException is thrown from Assembly.GetType() [closed]

OK, to start off, I have read both How to prevent ReflectionTypeLoadException when calling Assembly.GetTypes() and http://haacked.com/archive/2012/07/23/get-all-types-in-an-assembly.aspx but my problem is a bit more complicated. My goal is simply to see if an assembly contains classes (or types) t...
Branden Boucher
2

votes
2

answer
235

Views

Error creating runtime object of type System.Drawing.Point

I want to create a object of type System.Drawing.Point at runtime, I tried to use the code below: String typename = 'System.Drawing.Point'; Type tp = Type.GetType(typename); Object instance = Activator.CreateInstance(tp); But I always get tp == null. But, for example if I use System.Double everythin...
Rui Sebastião
2

votes
1

answer
3.4k

Views

How to get a Type from an object in another DLL?

I've got an object called 'Communication' that has a method to 'CreatePdfFromTemplate'. This method is going to be called from a Windows Service that has a SqlDependancy on a table that will notify when a new row is added by a method on a website. Into my method, I pass a list of custom objects that...
yellowbrickcode
2

votes
2

answer
921

Views

Get Enum List via GetType

I have code that gives a list of all possible values for any given enum i bound it pretty often to dropdownlists in my webpages now im trying to make a usercontrol which accepts the type name as a parameter, which in turn calls the code to create the value list as my sub expects a type parameter S...
1

votes
3

answer
655

Views

C#: Parse different classes as object and display property values the same way

I have a couple of classes in c# console application. public class Cars:List {} and: public class Drivers:List {} The goal is to render console-output always the same manner, doesn't matter if cars or drivers are parsed to rendering-method. So the parameter is of type object. Of course the properti...
Jimbo2015
3

votes
5

answer
838

Views

Get the parent class of a null object (C# Reflection)

How would I get the parent class of an object that has a value of null? For example... ClassA contains int? i which is not set to any value when the class is created. Then in some other place in the code I want to pass in i as a parameter to some function. Using i as the only info, I want to be able...
Nick
2

votes
1

answer
2.1k

Views

.NET reflection - Get Declaring class type from instance property

Is it possible to get the type of a class from a property instance I tried the following var model = new MyModel('SomeValueForMyProperty') Type declaringType = model.MyProperty.GetType().DeclaringType But the result is always not for both DeclaringType and ReflectedType
ricardo
3

votes
3

answer
1.1k

Views

Why does the gettype() say it's a double but var_dump() says float?

Why does the gettype() say it's a double but var_dump() says float? $number = 1234567890123456789; echo 'Number: {$number} is a '. gettype($number) . '\n'; var_dump($number); Response: Number: 1.23456789012E+18 is a double float(1.23456789012E+18)
Phill Pafford
28

votes
4

answer
6.4k

Views

Why GetType returns System.Int32 instead of Nullable<Int32>? [duplicate]

This question already has an answer here: Nullable type is not a nullable type? 4 answers Why is the output of this snippet System.Int32 instead of Nullable? int? x = 5; Console.WriteLine(x.GetType());
Arsen Mkrtchyan
4

votes
2

answer
11.8k

Views

How return the type of a System.__COMObject in System.Type in C#

I'm doing a program and I want to do a Reflection, but for this, I need an Object of the Type class, right? to use the .GetProperties() method... So I tryed this: Type typeName = simObjects.getType(); But the .GetType() is returning 'System.__COMObject'. And this is not helpfull. The same happens w...
Jovita
28

votes
12

answer
16.4k

Views

.NET : How do you get the Type of a null object?

I have a method with an out parameter that tries to do a type conversion. Basically: public void GetParameterValue(out object destination) { object paramVal = 'I want to return this. could be any type, not just string.'; destination = null; // default out param to null destination = Convert.ChangeTy...
CodingWithSpike
1

votes
4

answer
1.1k

Views

ASP.NET - cant GetType() of MasterPage

I have a MasterPage and get its type as follows: alt text http://www.yart.com.au/stackoverflow/masterpage.png No problem, this works Now, when I create an aspx page and try the same thing I get null: alt text http://www.yart.com.au/stackoverflow/page.png Why? How can I get this to work? NOTE The ans...
Petras
6

votes
3

answer
8.2k

Views

Using GetCurrentMethod in (supposedly) high-performance code

For logging purposes, some methods in our application include the following line: Dim Log As ILog = GetLog(Reflection.MethodBase.GetCurrentMethod().DeclaringType) I have what might be described as an irrational fear of reflection, which I try to keep in check. However, calls like this in methods tha...
Dan Tao
2

votes
1

answer
71

Views

How can i get the system type of a value i get from a form/string?

i have never tried something like this so i need your help. i have the following code: public int AddChannel(NameValueCollection FormValues) { string Keys = string.Join(',',FormValues.AllKeys); string Values = string.Join(',', FormValues.AllKeys.Select(key => String.Format('\'{0}\'', HttpContext.Cur...
Dementic

View additional questions