Hi Folk,
Here is a sample java program.
I wonder why the two approaches reslut different stories. Is it a bug or kind of bitter java feature?
And I run the sample upon java 1.5
package test;
public class TestOut{
public static void main(String[] args){
**new TestIn();//it works**
// throw IllegalAccessException**
**Class.forName("t...
This is a scenario created to help understand what Im trying to achieve.
I am trying to create a method that returns the specified property of a generic object
e.g.
public object getValue<TModel>(TModel item, string propertyName) where TModel : class{
PropertyInfo p = typeof(TModel).GetProperty(propertyName);
return p.GetValue...
Hi Friends,
I want to write a code to search for method defination and methods called in a c# file.
So obviously my pattern should search for text like
1.public void xyz(blahtype blahvalue);
2.string construct = SearchData(blahvalue);
Has anyone done similar to this, is Regex helpful in this case. if yes provide me the pattern.
Any...
Hi
I'm trying to create an object Of a specific type. I've got the following code, but it fails because it can't cast the new table object to the one that is already defined. I need table to start of an IEnumerable type so I can't declare is an object.
Public sub getTable(ByVal t as Type)
Dim table As Table(Of Object)
Dim tabl...
Hello,
I need to know about good C++ Reflection API(Would be better if Microsoft API is available) which enables me to determine the types(classes,structs,enums,ints,float,doubles...)identification at runtime, declaring them and finally to call methods on those types at run time too.
Regards
Usman
...
UPDATED!
I've highlighted the line that throws the error and added the code-behind for one of my User Controls (its at the bottom).
I have the following method which allows me to dynamically add "user controls" via code behind.
Like this:
UserControl myCtrl = LoadControl( "/pathtocontrol/control.ascx", p1, p2 );
litControl.AddCont...
Let's say I have a Foo.fsx script that contains this code:
module Bar =
let foobar = "foo"+"bar"
open Bar
let a = System.Reflection.Assembly.GetExecutingAssembly()
let ty = a.GetType("Foo.Bar") // but it returns null here
How can I achieve that? Thanks!
...
using :
Dim a As [Assembly] = [Assembly].LoadFile("C:\test.exe")
Dim testTP As Type
testTP = a.GetType("SplashScreen", True, True)
obj1 = Activator.CreateInstance(testTP)
obj1.show()
my prog made reflection to test.exe > SplashScreen loaded , also obj1 filled
when SplashScreen disposed -> MainForm loaded > the obj1 isnothing...
I need to bone up on my CLR compiling knowledge, so i'm going to speak in generalities... Appologies if I'm not being specific enough.
I'm working on an application that references a COM Library dll which has a number of dlls rolled into it. My question is, is it possible using Reflection to get a reference to the sub dll's assembly, n...
Please help me on how to list all classes with a specific Attribute within an assembly in C#?
...
I meet a problem about type contraint of c# now.
I wrote a pair of methods that can convert object to string and convert string to object.
ex.
static string ConvertToString(Type type, object val) {
if (type == typeof(string)) return (string)val;
if (type == typeof(int)) return val.ToString();
if (type.IsSubclassOf(typeof(CodeObject)...
So now that we have generic Covariance and Contravariance on interfaces and delegates in C#, I was just curious if given a Type, you can figure out the covariance/contravariance of its generic arguments. I started trying to write my own implementation, which would look through all of the methods on a given type and see if the return type...
Is it possible to read the GUID from the Assembly without actually loading it in the current App Domain.
Normally Assembly.Load loads the DLL into the app domain. I just want to read the value.
The description of the GUID is
'The following GUID is for the ID of the typelib
' if this project is exposed to COM
<Assembly: Guid("DEDDE...
Hi there
I want to convert a string to a generic type
I have this:
string inputValue = myTxtBox.Text;
PropertyInfo propInfo = typeof(MyClass).GetProperty(myPropertyName);
Type propType = propInfo.PropertyType;
object propValue = ?????
I want to convert 'inputString' to the type of that property, to check if it's compatible
how...
I have several templated objects that all implement the same interface:
I.E.
MyObject<datatype1> obj1;
MyObject<datatype2> obj2;
MyObject<datatype3> obj3;
I want to store these objects in a List... I think I would do that like this:
private List<MyObject<object>> _myList;
I then want to create a function that takes 1 parameter, be...
I'm writing a routine to invoke methods, found by a name and an array of parameter Class values
Matching the Method by getName works, but when trying to match the given Class[] for parameters, and Method.getParameterTypes(), I'm having trouble.
I assumed that this would work:
Class[] searchParams = new Class[] { float.class, String.c...
Java Class java.lang.reflect.Array provides a set of tools for creating an array dynamically. However in addition to that it has a whole set of methods for accessing (get, set, and length) an array. I don't understand the point of this, since you can (and presumably would) cast your dynamically generated array as an array upon creation...
For example I have
interface ICommand {}
class MovePiece : ICommand {}
class Successful<CMD> where CMD : ICommand {}
and I want the following:
CovariantlyEqual(
typeof(Successful<ICommand>),
typeof(Successful<MovePiece>))
.ShouldEqualTrue()
Update
Eric asks below why I would want to test such a thing. Fair enough. I think t...
I am currently trying to create a generic instance factory for which takes an interface as the generic parameter (enforced in the constructor) and then lets you get instantiated objects which implement that interface from all types in all loaded assemblies.
The current implementation is as follows:
public class InstantiationFactory<T>
...
I've been looking at the php reflection methods, what i want to do is inject some code after the method is opened and before any return value, for example i want to change:
function foo($bar)
{
$foo = $bar ;
return $foo ;
}
And inject some code into it like:
function foo($bar)
{
//some code here
$foo = $bar ;
//so...