I am looking on how to get the object (or object type) that another object is created in. For example:
public class RootClass
{
public class A
{
public void MethodFromA()
{
}
}
public class B
{
public A A_object = new A();
public void MethodFromB() { }
}
B BObject = ...
I have a simlar requirement where in i have 3 main entities in ADO.NET entity model... I am building a framework wherein basedon incoming XML root element i have to create an instance of specific entity using reflection and set its properties..
But when it comes to child entities.. I am not able to use LINQ queries on it as the type is...
I have a peculiar problem here. I want to extract some generic types, which implements a generic interface from an assembly. I can accumulate all the types from the assembly but can not search for a particular implemented type from that type collection. Here are my code I am using, can you please point out what is the wrong with it? Or h...
Say I have a base class in Assembly A:
public class MyBaseClass{
public static Assembly GetMyAssembly(){
//determine the Assembly of my subclasses
}
}
Then I create a subclass of that class within Assembly B:
public class MySubClass : MyBaseClass {
}
From there, in my domain specific logic I invoke MySubClass.GetMyAsse...
I'm basically trying to do this, but I don't know what T will be, so I'm building things up using Reflection and Expression trees.
// Input (I don't know about "Book")
Type itemType = typeof(Book);
// Actual Code
// Build up func p => p.AuthorName == "Jon Skeet"
ParameterExpression predParam = Expression.Parameter(itemType, "p");
Expre...
I'm trying to iterate over the members of a static class and invoke all of the members that are fields. I get a MissingFieldException on the line where I attempt to invoke the member.
Something like this:
"Field 'NamespaceStuff.MyClass+MyStaticClass.A' not found."
public class MyClass {
public MyClass() {
Type type = typeo...
Is it because we shoud load class (by string for example), create instance, then search for appropriate method, pack parameters, and then just invoke method. So the most time is spent on this operations instead of explicit method invocation on an object, right?
...
Before I go on I did go through this
InternalsVisibleTo attribute ain’t workin'!
Hence the title
Okay so I had a working version of my project that was using something like the following.
[assembly: InternalsVisibleTo("Stuff.Test.Support, PublicKey="0024000004800000940000000302000000240000525341310004000001000100d158cd56401c3d90b52ca...
I am trying to load an assembly into memory and then instantiate types within that assembly. The objects are all of the same type (ITestMod). The following seems to work well:
private void LoadTestAssembly(string assemblyName)
{
try
{
Assembly assembly = Assembly.LoadFrom(@".\testmods\" + assemblyName);
...
I have a package of plug-in style modules. It looks like this:
/Plugins
/Plugins/__init__.py
/Plugins/Plugin1.py
/Plugins/Plugin2.py
etc...
Each .py file contains a class that derives from PluginBaseClass. So I need to list every module in the Plugins package and then search for any classes that implement PluginBaseClass. Ideall...
I can receive events, using the AppDomain.AssemblyLoad event, but only for a particular app domain. If I have appdomains that recursively create more appdomains, I believe my AssemblyLoad event will not work for those "grand-child" appdomains.
How can I be sure to get an AssemblyLoad event triggered, regardless of what appdomain loaded...
I'm getting a MissingMethodException thrown when I call GetExportedTypes, the code:
Assembly.LoadFrom(assemblyPath).GetExportedTypes();
The exception (names obfuscated):
System.MissingMethodException was unhandled
Message="Method not found: 'Void Namespace.IMyMethod.MyMethod(UInt32, Namespace.IMyOtherMethod ByRef, UInt32 ByRef)'."
...
Let's consider the following code :
internal class FooInternal
{
internal static void DoIt()
{
throw new NotImplementedException();
}
}
Now i have a library inside which it is reflecting the FooInternal type and for a reflected methodInfo (in this case DoIt) i have this :
if ((m...
I have a method where I need to resolve the Type of a class. This class exists in another assembly with the namespace similar to:
MyProject.Domain.Model
I am attempting to perform the following:
Type.GetType("MyProject.Domain.Model." + myClassName);
This works great if the code that is performing this action is in the same assembly...
I have dynamically created the type "FruitTypes" with these two properties
private string _apple;
public string Apple
{
get { return _apple; }
set { _apple= value; }
}
private string _pear;
public string Pear
{
get { return _pear; }
set { _pear= value; }
}
Now the second type called "Farm" shall have two proper...
Hi,
How can I find every occurrence of a custom attribute inside an assembly?
If can find all types from an assembly where the attribute is used but thats not enough. How about methods, properties, enum, enum values, fields etc.
Is there any shortcut for doing this or is the only way to do it to write code to search all parts of a typ...
I need to create a .NET control (in ASP.NET) from a string that represents the control's name.
Control myList = SomeSystemClass.GetControlByName("DropDownList");
I guess there is some reflection method in the .NET platform that allows this but I have no idea which one. Any ideas?
...
Following up on InternalsVisibleTo. I have looked at c# Instantiating Internal class with private constructor, and this has helped but I'm trying to cast the returned object as the internal type and, honestly I'm not 100% that that is possible.
I'm trying the route of Reflection to fix this issue, but I'm having a tough time trying to ...
Hi,
I have a parameterized class :
class ParameterizedClass<T extends AbstractSomething> {
}
calling:
new ParameterizedClass<Something>();
So how can I get actual type Something of T by using Java Generics?
...
I was playing around with Microsoft Entity framework 4 and at some point i want to create a fake instance of ObjectStateEntry using a proxy or FormatterServices and faced with the issues that follow:
The class has internal abstract members therefore creating a proxy ends up with type having not-implemented members. Therefore, throws ex...