2

I am new to reflection and am hitting a brick wall trying to understand types.

What exactly does Assembly mean and what does Assembly.GetTypes() return? Also if you call something like GetGenericArguments() on a 'type' you get from the GetTypes() command, what does that do exactly?

Thanks

1

4 Answers 4

3

Assembly is a dll or exe file in this case.
Assembly.GetTypes() returns all types in that assembly.

If you have a generic type

public class MyType<T, V>
{
}

Type.GetGenericArguments returns the T and the V.

Sign up to request clarification or add additional context in comments.

Comments

2

Calling Assembly.GetTypes() returns all the types and interfaces that are defined in the assembly.

Calling Type.GetGenericArguments() returns all the generic parameters specified for a generic type. This might not be the clearest explanation, an example would help:

var type1 = typeof(Func<>);
type1.GetGenericArguments(); // [ typeof(TResult) ]

var type2 = typeof(Func<string>);
type2.GetGenericArguments(); // [ typeof(String) ]

var type3 = typeof(Tuple<string, int, bool>);
type3.GetGenericArguments(); // [ typeof(String), typeof(Int32), typeof(Boolean) ]

Comments

1

Assemblies contain code that runs, or stores information about objects i.e. classes/structures which have methods/properties/events.

A type is a class that describes other classes.

http://msdn.microsoft.com/en-us/library/system.type%28v=vs.71%29.aspx

Comments

1

An assembly in .NET is a *.dll file which is produced by compiling a Class Library (and other) project types

Assembly.GetTypes() returns an array of all the Types in that assembly, which is to say all the Classes & Structs inside the assembly.

Further Reading

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.