The problem:
I have a C++ class with gajillion (>100) members that behave nearly identically:
same type
in a function, each member has the same exact code done to it as other members, e.g. assignment from a map in a constructor where map key is same as member key
This identicality of behavior is repeated across many-many functions (>2...
I have many Flex objects like this one:
public class MyData {
public var time: Date;
public var label: String;
}
I am populating this object from a DB record retrieved via AMF that looks something like this:
{
label: "Label",
incident: "2009-08-15 11:12:14.12233"
}
I want to write a generic value mapper for these ob...
Hi,
No doubt elements of this question have been asked before, but I'm having trouble finding an answer. (Disclaimer: this is related, but separate from a recent question I asked).
I have a method like this:
public static void Method<T>(MethodInfo m, T value)
{
Type memberType = m.GetValueType();
if (memberType.IsAssignableFrom(...
I want the location of the current execution project i.e in VB.NET/C# or the current class file's path?
Ok,let me elaborate i got 2 projects in one solution file,lets say A,B are projects, my startup project is B ,and im accessing a class file in A ,now i need to know virtual path of B. because i need it for accessing the resource file ...
This is like a follow-up question to this one.
Basically what I'm doing is exposing some fields on some UI to some user.
These fields are established based on the parameter list of a given objects constructor. The user has the options to choose which object the UI is displaying by, oh I don't know, let's say picking an object from a dr...
When I try to get the eventinfo of a WPF 'rectangle', if the routedEvent is a native event to the object (e.g. 'MouseDown') it works (assignments are for example only).
DependencyObject d = rectangle;
string routedEvent = "MouseDown";
EventInfo eventInfo = d.GetType().GetEvent(routedEvent,
BindingFlags.Public | Binding...
This one has proven to be a little tricky for me so far. I am wondering if it is possible to type cast an object using a System.Type object.
I have illustrated below what I mean:
public interface IDataAdapter
{
object Transform(object input);
Type GetOutputType();
}
public class SomeRandomAdapter : IDataAdapter
{
public ob...
I've done some research and found that there apparently is an easy and understandable way to do this using reflection.
Type MyType = typeof(MyObject);
IList lst = (IList)Activator.CreateInstance((typeof(List<>).MakeGenericType(MyType)));
I'm getting compile error. It's telling I do in fact need to supply the type to IList...
Am I miss...
To me they are very similar structures. I was hoping there was a way to cast or convert one to the other easily.
I'm using reflection to do some magic. I've chosen the path to use parametrized constructors to create some user selected objects which they fill in values for the parameters using a UI.
The problem is one of the objects tak...
The constructor looks like this:
public NameAndValue(string name, string value)
I need to get it as a MethodInfo using Reflection. It tried the following, but it does not find the constructor (GetMethod returns null).
MethodInfo constructor = typeof(NameAndValue).GetMethod(".ctor", new[] { typeof(string), typeof(string) });
What a...
I have several methods that populate a SQLCommand objects parameter collection from an object like this
if (!String.IsNullOrEmpty(SearchObj.FirstName))
{
command.AddParameter(Fields.FirstName, SearchObj.FirstName);
}
if (!String.IsNullOrEmpty(SearchObj.LastName))
{
command.AddParameter(Fields.LastName, SearchObj.LastName);
}
if ...
Hello,
In one of my previous questions I explained about a form class that contain form field objects to save data in a user profile object (using profile provider).
The code is here bellow. Basically what I would like to accomplish is to pass as a parameter to my form field objects the field of the Profile object that they should inte...
Hello, look at the following example:
public class Test {
public int Number { get; set; }
public void TestReflection() {
Number = 99;
Type type = GetType();
PropertyInfo propertyInfo = type.GetProperty("Number");
propertyInfo.SetValue(this, null, null);
}
}
In the example I'm setting a int ...
The following F# code fails because Type.DefaultBinder does not want to bind to the generic Id method. Is there an alternative Binder that would do this?
open System
open System.Reflection
type Foo() =
member this.Id<'T>(x: 'T) : 'T = x //'
typeof<Foo>.InvokeMember (
"F",
BindingFlags.InvokeMethod,
Type.DefaultBinder,...
If I have a package (foo.bar), is there some groovy sugar that makes it easy for me to enumerate all the classes in said package?
...
MSDN docs say that only value types need boxing, but this does not apply to string, which is a value type and does not need to be boxed. I initially tried Type.IsValueType, but since that returns true for string, I can't use it to determine whether a type really needs to be boxed. Are there any other methods you are aware of? Is string t...
It seems that .NET CF is missing the very useful Reflection.Emit.
So far, I found this library as an alternative: http://www.codeplex.com/EmitCF.
However it seems to be an abandoned early version, so I'm looking for more options.
Does anyone know of another alternative to Emit?
Or perhaps someone used EmitCF and can comment on its st...
I am looking for a way to retrieve the variable name, so I don't have to use hard-coded declarations when needed (for property names etc.):
I hardly believe it's possible; maybe someone has a solution.
Note: even not variables, properties would also be a move.
'Pseudo:
Module Module1
Sub Main()
Dim variable = "asdf"
...
I'm writing an xml serialization class for objective-c.
The point is to give the class a class type and an xml file.
It should return an instance with data.
I've got it working, and it does quite a bit - handles primitives (+nsstring), user defined classes and nsarrays. Doesn't handle pointers or C-arrays.
Obviously this relies heavily ...
In this example from The Ruby Programming Language (p.270), I'm confused why the instance_eval method on the last line of the sample code defines a class method called String.empty.
Don't you use class_eval to define a class method and instance_eval when you want to define an instance method?
o.instance_eval("@x") # Return the value o...