本文整理汇总了C#中Assembly.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetType方法的具体用法?C# Assembly.GetType怎么用?C# Assembly.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assembly
的用法示例。
在下文中一共展示了Assembly.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadResX
/*
* We load the ResX format stuff on demand, since the classes are in
* System.Windows.Forms (!!!) and we can't depend on that assembly in mono, yet.
*/
static void LoadResX () {
if (swf != null)
return;
try {
swf = Assembly.Load (Consts.AssemblySystem_Windows_Forms);
resxr = swf.GetType ("System.Resources.ResXResourceReader");
resxw = swf.GetType ("System.Resources.ResXResourceWriter");
} catch (Exception e) {
throw new Exception ("Cannot load support for ResX format: " + e.Message);
}
}
示例2: GetTypeTrue
static int GetTypeTrue (Assembly a)
{
string typename = "InheritanceDemand";
Type t = a.GetType (typename, true);
Console.WriteLine ("*0* Can get type '{0}' with security.", t);
return 0;
}
示例3: WithInterceptorTests
public WithInterceptorTests()
{
var assemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\DebugWithInterceptor\AssemblyToProcess.dll");
assembly = AssemblyWeaver.Weave(assemblyPath);
var methodTimeLogger = assembly.GetType("MethodTimeLogger");
methodBaseField = methodTimeLogger.GetField("MethodBase");
}
示例4: GetTypeFalse
static int GetTypeFalse (Assembly a)
{
string typename = "InheritanceDemand";
Type t = a.GetType (typename, false);
if (t == null) {
Console.WriteLine ("*1* Get null for type '{0}' with security.", typename);
return 1;
} else {
Console.WriteLine ("*0* Can get type '{0}' with security.", typename);
return 0;
}
}
示例5: InSameAssemblyTests
public InSameAssemblyTests()
{
beforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\debug\AssemblyToProcess.dll");
#if (!DEBUG)
beforeAssemblyPath = beforeAssemblyPath.Replace("debug", "Release");
#endif
afterAssemblyPath = WeaverHelper.Weave(beforeAssemblyPath);
assembly = Assembly.LoadFrom(afterAssemblyPath);
var errorHandler = assembly.GetType("AsyncErrorHandler");
exceptionField = errorHandler.GetField("Exception");
}
示例6: GetTypeTrue
static int GetTypeTrue (Assembly a)
{
try {
string typename = "InheritanceDemand";
Type t = a.GetType (typename, true);
Console.WriteLine ("*1* Can get type '{0}' with security (true).", t);
return 1;
}
catch (SecurityException se) {
Console.WriteLine ("*0* Expected SecurityException\n{0}", se);
return 0;
}
}
示例7: Create
public static ClrFuncReflectionWrap Create(Assembly assembly, String typeName, String methodName)
{
Type startupType = assembly.GetType(typeName, true, true);
ClrFuncReflectionWrap wrap = new ClrFuncReflectionWrap();
wrap.instance = System.Activator.CreateInstance(startupType, false);
wrap.invokeMethod = startupType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public);
if (wrap.invokeMethod == null)
{
throw new System.InvalidOperationException(
"Unable to access the CLR method to wrap through reflection. Make sure it is a public instance method.");
}
return wrap;
}
示例8: GetFancyName
/// <summary>
/// Gets the fancy (user friendly) name of the type.
/// </summary>
/// <returns>The fancy name.</returns>
/// <param name="name">The original full name of the type.</param>
public static string GetFancyName(Assembly assembly, string name)
{
var type = assembly.GetType(name);
if (type != null)
{
var friendAttrs = type.GetCustomAttributes(typeof(ImplementationFriendlyNameAttribute), false);
var friendAttr = friendAttrs.OfType<ImplementationFriendlyNameAttribute>().FirstOrDefault();
if (friendAttr != null)
{
return friendAttr.Name;
}
}
if (name.StartsWith("Code."))
{
name = name.Substring("Code.".Length);
}
if (name.EndsWith("Implementation"))
{
name = name.Substring(0, name.Length - "Implementation".Length);
}
if (name.EndsWith("Implementations"))
{
name = name.Substring(0, name.Length - "Implementations".Length) + "s";
}
var regex = new Regex("^(([a-z][A-Z])|([a-z][0-9])|([0-9][A-Z]))$", RegexOptions.Compiled);
for (var i = 1; i < name.Length; i++)
{
var str = name[i - 1].ToString() + name[i];
if (regex.IsMatch(str))
{
name = name.Substring(0, i) + " " + name.Substring(i);
i++;
}
}
return name;
}
示例9: EnsureMembersAreSealed
public static void EnsureMembersAreSealed(string className, Assembly assembly, params string[] memberNames)
{
foreach (var memberName in memberNames)
{
var type = assembly.GetType(className, true);
var member = type.GetMember(memberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly).First();
if (member is MethodInfo)
{
var methodInfo = (member as MethodInfo);
Assert.IsTrue(methodInfo.IsFinal, methodInfo.Name);
}
if (member is PropertyInfo)
{
var propertyInfo = member as PropertyInfo;
var setMethod = propertyInfo.GetSetMethod();
Assert.IsTrue(setMethod.IsFinal, propertyInfo.Name);
var getMethod = propertyInfo.GetGetMethod();
Assert.IsTrue(getMethod.IsFinal, propertyInfo.Name);
}
}
}
示例10: Outline
public Outline (Universe universe, Assembly mscorlib, Type t, TextWriter output, bool declared_only, bool show_private, bool filter_obsolete)
{
if (universe == null)
throw new ArgumentNullException ("universe");
if (mscorlib == null)
throw new ArgumentNullException ("mscorlib");
this.universe = universe;
this.mscorlib = mscorlib;
this.t = t;
this.o = new IndentedTextWriter (output, "\t");
this.declared_only = declared_only;
this.show_private = show_private;
this.filter_obsolete = filter_obsolete;
type_multicast_delegate = mscorlib.GetType("System.MulticastDelegate");
type_object = mscorlib.GetType ("System.Object");
type_value_type = mscorlib.GetType ("System.ValueType");
type_int = mscorlib.GetType ("System.Int32");
type_flags_attribute = mscorlib.GetType ("System.FlagsAttribute");
type_obsolete_attribute = mscorlib.GetType ("System.ObsoleteAttribute");
type_param_array_attribute = mscorlib.GetType ("System.ParamArrayAttribute");
}
示例11: CreateUsingLateBinding
static void CreateUsingLateBinding(Assembly asm)
{
Console.WriteLine("****** Call method using late binding ******");
try
{
// get meta data
Type miniVan = asm.GetType("CarLibrary.MiniVan");
// create miniVan object on the fly
object obj = Activator.CreateInstance(miniVan);
Console.WriteLine("Created a {0} using late binding!", obj);
MethodInfo mi = miniVan.GetMethod("TurboBoost");
// invoke the method
mi.Invoke(obj, null);
MethodInfo mi2 = miniVan.GetMethod("TurnOnRadio");
mi2.Invoke(obj, new object[] { true, 2 });
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
示例12: Awake
void Awake()
{
Instance = this;
// Load the fallback core
fallbackAssembly = FallbackLoader.LoadFallbackGameCore();
gameStateType = fallbackAssembly.GetType("FallbackGameState");
cropType = fallbackAssembly.GetType("FallbackCrop");
// Run the validation code to patch in the appropriate types
usingStudentCropClass = ValidateCropClass();
usingStudentGameStateClass = ValidateGameStateClass();
// Check if we are using the fallback game state
if (gameStateType.Name == "FallbackGameState")
{
ConstructorInfo gameStateConstructor = gameStateType.GetConstructor(new[] { typeof(int), typeof(System.Type) });
gameState = gameStateConstructor.Invoke(new[] { (object)NumCrops, cropType });
} // Otherwise we are using the student provided gamestate
else
{
ConstructorInfo gameStateConstructor = gameStateType.GetConstructor(new[] { typeof(int) });
gameState = gameStateConstructor.Invoke(new[] { (object)NumCrops });
}
// Retrieve the required methods for the game state
clearCropMethod = gameStateType.GetMethod("ClearCrop");
plantCropMethod = gameStateType.GetMethod("PlantCrop");
attemptToHarvestCropMethod = gameStateType.GetMethod("AttemptToHarvestCrop");
updateMethod = gameStateType.GetMethod("Update");
getCropStateMethod = gameStateType.GetMethod("GetCropState");
getInfoForCropAtIndexMethod = gameStateType.GetMethod("GetInfoForCropAtIndex");
uniqueIdForCropAtIndexMethod = gameStateType.GetMethod("UniqueIdForCropAtIndex");
moneyField = gameStateType.GetField("Money");
plantedCropsField = gameStateType.GetField("PlantedCrops");
}
示例13: LoadResearchMethods
private void LoadResearchMethods()
{
try
{
ResearchMethodsComboBox.SelectedIndexChanged -= new EventHandler(ResearchMethodsComboBox_SelectedIndexChanged);
AppDomain domain = AppDomain.CurrentDomain;
if (domain != null)
{
m_research_methods_assembly = domain.Load(m_research_assembly_name);
if (m_research_methods_assembly != null)
{
Type assembly_type = m_research_methods_assembly.GetType(m_research_assembly_name);
if (assembly_type != null)
{
MethodInfo[] method_infos = null;
if (Globals.EDITION == Edition.Research)
{
method_infos = assembly_type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
}
else
{
method_infos = assembly_type.GetMethods(BindingFlags.Static | BindingFlags.Public);
}
if (method_infos != null)
{
ResearchMethodsComboBox.Items.Clear();
foreach (MethodInfo method_info in method_infos)
{
string method_name = method_info.Name;
if (method_name.Contains("WordPart"))
{
if ((Globals.EDITION != Edition.Grammar) && (Globals.EDITION != Edition.Research))
{
continue; // skip WordPart methods
}
}
ParameterInfo[] parameters = method_info.GetParameters();
if ((parameters.Length == 2) && (parameters[0].ParameterType == typeof(Client)) && (parameters[1].ParameterType == typeof(string)))
{
ResearchMethodsComboBox.Items.Add(method_name);
}
}
}
}
if (ResearchMethodsComboBox.Items.Count > 0)
{
ResearchMethodsComboBox.SelectedIndex = 0;
ResearchMethodsComboBox_SelectedIndexChanged(null, null);
}
}
}
}
catch
{
// cannot load Research assembly, so just ignore
}
finally
{
ResearchMethodsComboBox.SelectedIndexChanged += new EventHandler(ResearchMethodsComboBox_SelectedIndexChanged);
}
}
示例14: InvokeMethodWithDynamicKeyword
// re-write using dynamic
static void InvokeMethodWithDynamicKeyword(Assembly asm)
{
Console.WriteLine("****** Call method using dynamics ******");
try
{
// get meta data
Type miniVan = asm.GetType("CarLibrary.MiniVan");
// create miniVan object on the fly
dynamic obj = Activator.CreateInstance(miniVan);
Console.WriteLine("Created a {0} using dynamics!", obj);
// invoke the method
obj.TurboBoost();
obj.TurnOnRadio(true, 0);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
示例15: GetEnumValue
public static object GetEnumValue(Assembly assembly, string typeName, string value)
{
var type = assembly.GetType(typeName);
return Enum.Parse(type, value);
}