Extracting functions from a script file
Is there an easier way to get a list of all the functions in a given Powershell script than matching the function signatures with a regex (in Powershell)? ...
Is there an easier way to get a list of all the functions in a given Powershell script than matching the function signatures with a regex (in Powershell)? ...
I find that Java's reflection API is exception verbose, and I often want to catch each specific exception, but just throw Exception. Is this poor practice, or do you really throw all of those exceptions on the method signature? Every method that calls that method must then deal with each of those specific exceptions in some way. Instead,...
I'd like to point a C# application at a DLL and get a list of the types defined in that DLL. What I have so far looks right on the surface, but is giving the error indicated below. using System.Reflection; ... static void Main(string[] args) { Assembly SampleAssembly; SampleAssembly = Assembly.LoadFrom("C:\\MyAssembly.dll"); /...
I have many, (15-20) different XML files that I need to load to VB.Net. They're designed as they would be in a database; they're designed in Access and bulk exported into XML files. Each file represents a different table in the database. Now, I need to load this information into VB.Net. Initially, I'd love to use DAO and access the M...
Hi. I have a generic abstract base class from which I would like to derive from a dynamic type built through reflection.emit. Also I need to customize the derived class default constructor to initialize some fields. To build the default constructor of the derived class correctly I need to obtain the default constructor of the base class...
I want to convert a string to an object property value, whose name I have as a string. I am trying to do this like so: string modelProperty = "Some Property Name"; string value = "SomeValue"; var property = entity.GetType().GetProperty(modelProperty); if (property != null) { property.SetValue(entity, Convert.ChangeType(valu...
I wish to a check if a method exists in an interface based on its signatures. The signature that the method should have is: Collection<Foo> methodName(Spam arg0, Eggs arg1, ...) I can find the methods via Class.getMethods() then find the name, parameters and return type respectively with method.getName(), method.getParameterTypes()...
private void Window_Loaded(object sender, RoutedEventArgs e) { var assm = Assembly.LoadFrom("wpflib.dll"); foreach (var t in assm.GetTypes()) { var i = t.GetInterface("test.ILib"); if (i != null) { var tmp = Activator.CreateInstance(typeof(UserControl)) as UserControl; this.stac...
I want to make a C# Dictionary in which the key is the string name of a static property in a class and the value is the value of the property. Given a static property in the class called MyResources.TOKEN_ONE, how can I get the at the name of the property rather than its value? I only care about the end part of the property name (e.g. ...
How we can manually inject an object without using the facility of containers. I did something similar through reflection as follows. Class actionClass = Class.forName("SampleClass"); Object actionObject = actionClass.newInstance(); Method reqMethod = actionClass.getMethod("setRequest", HttpServletRequest.class); reqMethod.invoke(action...
I am attempting to use Reflection in C# to determine at runtime the type of objects in a collection property. These objects are entities generated by the Entity Framework: Type t = entity.GetType(); PropertyInfo [] propInfo = t.GetProperties(); foreach(PropertyInfo pi in propInfo) { if (pi.PropertyType.IsGenericType) { ...
In .NET, are private methods and properties enforced by the runtime or just by the compiler? If you try to call another object's private methods, the compiler will throw an access exception. What if you manually manipulate the IL or try to call via reflection -- will you be able to? Also, does it vary by runtime version (1.1 vs. 2.0 vs....
I would like to select from a table using linq to sql without knowing what that table is until runtime, something like Type t = Type.GetType(myString); var results = from o in context.t select o; Obviously this doesn't work, but I was wondering if there was a way to do this. ...
Hi, I have recently been implementing a templating system for my home-grown web-site generator platform. What I'm currently trying to implement is the use of an interface throughout the template class heirarchy like so (this is just an example): interface IStyleSheet { public function StyleSheetFragment(); } abstract class Templa...
I have a bunch of IEnumerable Collections which exact number and types is subject of frequent changes (due to automatic code generation). It looks something like this: public class MyCollections { public System.Collections.Generic.IEnumerable<SomeType> SomeTypeCollection; public System.Collections.Generic.IEnumerable<OtherType>...
I have a binding to an unknown source. All I have is the binding. I have no other way of looking at the bound object. I need to figure out the Type for the bound object, even if the value is null (this is where my problem is). I was evaluating the binding by binding to an object and then using the object as a way to get the Type, but I ...
What I am trying to do is create a function that will be called from each method within a .cs file to then get all of the property names and values that are passed to the method and create a string of them. This will be used for a debug log to show what the value of each property was when the error occurred as an alternative to manually...
Hi guys, Following a sample of my code: public abstract class<T> { public List<T> GetSomething(string q) { **List<T> list = new List<T>();** Type type = typeof(T); PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance); foreach (PropertyInfo info ...
I have a Bootstrapper that looks through all Assemblies in an ASP.NET MVC application to find types that implement an IBootstrapperTask interface, and then registers them with an IOC Contrainer. The idea is that you can literaly place your IBootstrapperTasks anywhere, and organise your Projects how you please. Code for Bootstrapper: pu...
Here is some code I've been twiddling with to try and lazily fill in fields in object, mostly for object factories in JUnit but it could be quite a useful method to have. private void lazyObjectFill(Object profil) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { final Method[] list = profil.ge...