I have a scenario whereby I want n amount of classes to look at the same data and decide if any work needs to be done. Work is done by a team, and multiple teams can work on the data at the same time. I was thinking of creating a class for every team that would implement the CreateWork interface. All CreateWork classes must have their sa...
This is harder to find in the docs than I imagined. Anyway, I have some instances of Type. How can I find out if they represent classes, methods, interfaces, etc?
class Bla { ... }
typeof(Bla).GetKindOrWhatever() // need to get something like "Class"
(I'm using Mono on Linux but that shouldn't affect the question, I'm making portable...
Okay, let's say we have a class defined like
public class TestClass
{
private string MyPrivateProperty { get; set; }
// This is for testing purposes
public string GetMyProperty()
{
return MyPrivateProperty;
}
}
then we try:
TestClass t = new TestClass { MyPrivateProperty = "test" };
Compilation fails wi...
I've seen plenty of examples of people extracting all of the classes from a module, usually something like:
# foo.py
class Foo:
pass
# test.py
import inspect
import foo
for name, obj in inspect.getmembers(foo):
if inspect.isclass(obj):
print obj
Awesome.
But I can't find out how to get all of the classes from the cu...
Hello All
I am new user of interface. My problem is i have create a Generic class which have two parameter
one is object type another is interface type. Now within class i can cast object using Reflection but i am not getting the way to cast interface.
...
how know if a Type has inherited some other type ?
Type t;
// i get the t from somewhere
bool b = t.IsInhertitedFrom(typeof(BaseType));
...
Assume I have the following class:
class Example
{
function set something(value:String):void
{
trace("set something");
}
function doSomething():void
{
trace("something");
}
}
I can access the functions as objects like this:
var example:Example = new Example();
var asdf:Function = example.doSom...
Hi everyone,
I would like to know if it is possible to get attributes of the enum values and not of the enum itself? For example, suppose I have the following enum:
enum FunkyAttributesEnum
{
[Description("Name With Spaces1")]
NameWithoutSpaces1,
[Description("Name With Spaces2")]
NameWithoutSpaces2
}
What I want is given the enu...
I've encountered this situation so many times...
enum Fruit {
Apple,
Banana,
Pear,
Tomato
};
Now I have Fruit f; // banana and I want to go from f to the string "Banana"; or I have string s = "Banana" and from that I want to go to Banana // enum value or int.
So far I've been doing this.. Assuming the enum is in Fruit.h:
/...
It's a common sense when you are developing a big silverlight application that break it into many small components, to make the original XAP file relatively small and dynamically load the necessary DLLs from the server side on demand.
An easy way is to download(From WebClient) the dll in the program in the runtime accroding to the URL s...
I have a assembly. In this assembly I have a class and interface. I need to load this assembly at runtime and want to create an object of the class and also want to use the interface.
Assembly MyDALL = Assembly.Load("DALL"); // DALL is name of my dll
Type MyLoadClass = MyDALL.GetType("DALL.LoadClass"); // LoadClass is my class
object ob...
Is it possible to clone an object, when it's known to be a boxed ValueType, without writing type specific clone code?
Some code for reference
List<ValueType> values = new List<ValueType> {3, DateTime.Now, 23.4M};
DuplicateLastItem(values);
The partical issue I have is with a value stack based virtual instruction machine. (And Im too ...
Using dynamic method calls (#send or #method) the methods visibility is ignored.
is there a simple way to dynamically call a method that will fail calling a private method?
...
I've been told to use Reflection.Emit instead of PropertyInfo.GetValue / SetValue because it is faster this way.
But I don't really know what stuff from Reflection.Emit and how to use it to substitute GetValue and SetValue. Can anybody help me with this ?
...
Hello,
I have windows form with one textbox(Pname) and one button.
I have one class by name Player with no constructor.
When user enters text inside textbox (e.g. John) and clicks button, system will create and an instance of a class Player with name of an object as John.
Thanks,
Jay
...
Lets say I have a java package commands which contains classes that all inherit from ICommand can I get all of those classes somehow? I'm locking for something among the lines of:
Package p = Package.getPackage("commands");
Class<ICommand>[] c = p.getAllPackagedClasses(); //not real
Is something like that possible?
...
Is there any way to discover at runtime which subclasses exist of a given class?
Edit: From the answers so far I think I need to clarify a bit more what I am trying to do. I am aware that this is not a common practice in Cocoa, and that it may come with some caveats.
I am writing a parser using the dynamic creation pattern. (See the bo...
Hi
I used reflection many times before on public methods but never realized that private methods can be invoked too. See the link
I am still thinking why is that allowed in the first place?
Isn't that going to break the rule of "private" being "private"?
puzzled
AJ
...
Basically, I'm accepting an event name as a string, to get the EventInfo. Then, I'm discovering the event handler type and event argument type using reflection, creating a new delegate of that type (myEventHandler), and hooking it up with the event. When ever myEventHandler is invoked, I need to downcast and pass the arguments to the han...
I have a list of keyvaluepair(string,string) first string is something like class.property, second string is the value to assign to that class.property.
I'm currently looping through that list and by using reflection I set every value.
it work, but my question is there a faster way to do this?
...