gettype

asp.net, gettype() and fully qualified class names

只谈情不闲聊 提交于 2020-02-04 04:10:25
问题 I've read through a few other threads on here, though none of them really explain how to resolve my issue. I have a web application with the following page (code behind) namespace Company.Web.UI.Content { public partial class Home_LoggedOut : Company.Web.UI.CompanyPage { string _myType = this.GetType().FullName.Replace(".", "_"); } } Now I'd have hoped to get something like: Company_Web_UI_Content_Home_LoggedOut but instead I'm getting: ASP_home_loggedout_aspx I'm clearly missing something

What is a better way to check that a given object is a particular value type? [closed]

人盡茶涼 提交于 2020-01-15 05:28:09
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . Below are the 2 commonly used approaches to check before unbox. myObject.GetType() == typeof(MyValueType) IL_0001: callvirt System.Object.GetType IL_0006: ldtoken UserQuery.MyValueType IL_000B: call System.Type.GetTypeFromHandle IL_0010: call System.Type.op_Equality myObject

Using GetCurrentMethod in (supposedly) high-performance code

天涯浪子 提交于 2020-01-11 08:38:12
问题 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 that are executed potentially a hundred times a second concern me. I don't know as much as I should about reflection; but from looking briefly over the documentation, it looks to me like I could

What is the difference of getting Type by using GetType() and typeof()? [duplicate]

前提是你 提交于 2019-12-29 14:17:21
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Type Checking: typeof, GetType, or is? Which one is the preferred way to get the type? 回答1: You can only use typeof() when you know that type at compile time, and you're trying to obtain the corresponding Type object. (Although the type could be a generic type parameter, e.g. typeof(T) within a class with a type parameter T .) There don't need to be any instances of that type available to use typeof . The

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

纵然是瞬间 提交于 2019-12-24 08:13:24
问题 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 without including the trailing assembly name like this: Type.GetType(string.Format("{0}.{1}", typeToLoad.AssemblyName, typeToLoad.ClassName)); -- returns null. So, I am looking for a way to

(C#) why does Visual Studio say it's an object while GetType says it's a Func<object>?

主宰稳场 提交于 2019-12-18 17:56:33
问题 C# newbie question here. The following code (taken from the book "C# From Novice to Professional" by Christian Gross, Apress) gives an error: worksheet.Add("C3", CellFactories.DoAdd(worksheet["A2"], worksheet["B1"])); The reason is that the method DoAdd() does not accept the given arguments. public static Func<object> DoAdd(Func<object> cell1, Func<object> cell2) {...} VS claims that both args in the method call above are of type object whereas the method accepts only Func<object> . But the

When and where to use GetType() or typeof()? [duplicate]

為{幸葍}努か 提交于 2019-12-18 10:08:47
问题 This question already has answers here : What is the difference of getting Type by using GetType() and typeof()? [duplicate] (4 answers) Closed 2 years ago . Why this works if (mycontrol.GetType() == typeof(TextBox)) {} and this do not? Type tp = typeof(mycontrol); But this works Type tp = mycontrol.GetType(); I myself use is operator for checking type but my understanding fails when I use typeof() and GetType() Where and when to use GetType() or typeof() ? 回答1: typeof is an operator to

C# Is it possible to get actual type out of a string representing that type? [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 04:18:39
问题 This question already has answers here : Type.GetType(“namespace.a.b.ClassName”) returns null (16 answers) C# Getting Type out of a string variable and using it in generic method (3 answers) Closed 10 months ago . I have string "Car", and I would like to get the type Car from it. My class Car is: namespace MySolution.MyProjectA { public class Car { ... } } I trying getting type like this but it returns null: Type myType = Type.GetType("MySolution.MyProjectA.Car"); // returns null Given a

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

徘徊边缘 提交于 2019-12-13 02:22:45
问题 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 . 回答1: If the user has typed text into a textbox, that's always a string. It's never an int. You can parse the text as an integer, but the input itself is still text. You could speculatively try to parse it in different ways: int intValue; if (int.TryParse(text, out intValue) { ... use

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

只谈情不闲聊 提交于 2019-12-13 00:11:38
问题 I need an expression that gets type of every item of a collection. I have a collection like this: var collection = new List<object>{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 expression at run-time. I have to create something like myVariable dynamically, but how?! Debugger shows me value of internal expression of myVariable like this: {System.Linq.Enumerable