Search an assembly for all child types?
I'd like to find all the types inheriting from a base/interface. Anyone have a good method to do this? Ideas? I know this is a strange request but its something I'm playing with none-the-less. ...
I'd like to find all the types inheriting from a base/interface. Anyone have a good method to do this? Ideas? I know this is a strange request but its something I'm playing with none-the-less. ...
So i'm not really sure why this is happening but I'm running through some DataRows where I have the control name, property, and value that I want to set. Everything works fine except when I set the TEXT property of a button. For some reason, the click event is called... Here's some of the code I've got: string controlName, value, prope...
I'm digging into Reflection for the first time and I'm truely stuck. I've googled everything I can think of. I'm 90% where I wanna be now. I'm trying to return the value of a Property in a custom class through Reflection. Here's my class declaration: Public Class Class2 Private newPropertyValue2 As String Public Property NewP...
My scenario should be simple... the type I want to convert FROM is ALWAYS 'string'. What I want to convert to... could be many things - ints, DateTimes, ... strings, etc. This would be easy: string valueToConvertFrom = "123"; int blah = Convert.ToInt32(valueToConvertFrom); However... I don't know (until runtime) that the value I nee...
How to Read Schema of Flat File using Reflection in C# The brief overview that I have is- There's some server which is storing the data as flat files and I have to push data from SQL Server to these flat files. For that I need to know their schema. I have no idea about this, any help would be great. ...
Hej, assuming I have a code that looks like this: List<User> userList = GetUserByName (u => u.Name == name); DoSomethingWithTheUsers (userList.ToArray ()); Now I want to know the type of the objects in the Array in the method DoSomethingWithTheUsers (object[] myObjects) Simply done by myObjects.First ().GetType () but what is to be...
How can I use reflection to create a generic List with a custom class (List<CustomClass>)? I need to be able to add values and use propertyInfo.SetValue(..., ..., ...) to store it. Would I be better off storing these List<>'s as some other data structure? Edit: I should have specified that the object is more like this, but Marc Grave...
As we all know, when we derive a class and use polymorphism, someone, somewhere needs to know what class to instanciate. We can use factories, a big switch statement, if-else-if, etc. I just learnt from Bill K this is called Dependency Injection. My Question: Is it good practice to use reflection and attributes as the dependency injecti...
I have a function that, among other things, takes in an object and a Type, and converts the object into that Type. However, the input object is often a double, and the type some variation of int (uint, long, etc.). I want this to work if a round number is passed in as a double (like 4.0), but to throw an exception if a decimal is passe...
Having a strange issue with some C# code - the Getter method for a property is showing up as virtual when not explicitly marked. The problem exhibits with the DbKey property on this class (code in full): public class ProcessingContextKey : BusinessEntityKey, IProcessingContextKey { public ProcessingContextKey() { // Not...
Edit: Of course my real code doesn't look exactly like this. I tried to write semi-pseudo code to make it more clear of whay I wanted to do. Looks like it just messed things up instead. So, what I actually would like to do is this: Method<Interface1>(); Method<Interface2>(); Method<Interface3>(); ... Well ... I thought that maybe I...
I'm using reflection to loop through a Type's properties and set certain types to their default. Now, I could do a switch on the type and set the default(Type) explicitly, but I'd rather do it in one line. Is there a programmatic equivalent of default? ...
I am trying to get a MethodInfo object for the method: Any<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>) The problem I'm having is working out how you specify the type parameter for the Func bit... MethodInfo method = typeof(Enumerable).GetMethod("Any", new[] { typeof(Func<what goes here?, Boolean>) }); Help appreciated. ...
I have a python module that defines a number of classes: class A(object): def __call__(self): print "ran a" class B(object): def __call__(self): print "ran b" class C(object): def __call__(self): print "ran c" From within the module, how might I add an attribute that gives me all of the classes? ...
I've seen some methods of checking if a PEFile is a .NET assembly by examining the binary structure. Is that the fastest method to test multiple files? I assume that trying to load each file (e.g. via Assembly.ReflectionOnlyLoad) file might be pretty slow since it'll be loading file type information. Note: I'm looking for a way to chec...
Hi All, How do I call the correct overloaded function given a reference to an object based on the actual type of the object. For example... class Test { object o1 = new object(); object o2 = new string("ABCD"); MyToString(o1); MyToString(o2);//I want this to call the second overloaded function void MyToString(object o) { Cons...
I have a class Customer in app_code folder in asp.net web site, how can I create an instance using reflection, for example using Activator.CreateInstance(assemblyName, typeName)? Because the app_code is dynamically compiled, I don't know the assembly in design time? Thanks Fred The question is should be how get a full name of type in d...
Hello, I've got a name of a method: "Garden.Plugins.Code.Beta.Business.CalculateRest" How to run it? I think about this fancy reflection based solution like RunMethod(string MethodName) ...
Is there any way to have a look at signatures of anonymous functions in ActionScript 3 during runtime? I would like to validate Function objects passed in as arguments to other functions and make sure that they accept the correct number of arguments (with the correct types) and return a value of the correct type. flash.utils.describeTy...
Say I have some code like namespace Portal { public class Author { public Author() { } private void SomeMethod(){ string myMethodName = ""; // myMethodName = "Portal.Author.SomeMethod()"; } } } Can I find out the name of the method I am using? In my example I'ld like to programma...