static Glu() { assembly = Assembly.GetExecutingAssembly();//Assembly.Load("OpenTK.OpenGL"); glClass = assembly.GetType("OpenTK.OpenGL.Glu"); delegatesClass = glClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic); importsClass = glClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic); }
static GL() { glClass = typeof(GL); delegatesClass = glClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic); importsClass = glClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic); LoadAll(); // Ensure this class is loaded, since it is no longer visible to the GraphicsContext.LoadAll() method. }
static Wgl() { glClass = typeof(Wgl); delegatesClass = glClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic); importsClass = glClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic); // 'Touch' Imports class to force initialization. We don't want anything yet, just to have // this class ready. if (Imports.FunctionMap != null) { } ReloadFunctions(); }
static Wgl() { assembly = Assembly.GetExecutingAssembly(); wglClass = assembly.GetType("OpenTK.Platform.Windows.Wgl"); delegatesClass = wglClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic); importsClass = wglClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic); // Ensure core entry points are ready prior to accessing any method. // Resolves bug [#993]: "Possible bug in GraphicsContext.CreateDummyContext()" LoadAll(); }
public static void DefinePersistence(this BusConfiguration config, IDictionary<string, string> settings, Type endpointBuilderType) { if (!settings.ContainsKey("Persistence")) { settings = Persistence.Default.Settings; } var persistenceType = Type.GetType(settings["Persistence"]); var typeName = "Configure" + persistenceType.Name; var configurerType = endpointBuilderType.GetNestedType("ConfigurePersistence") ?? Type.GetType(typeName, false); if (configurerType != null) { var configurer = Activator.CreateInstance(configurerType); dynamic dc = configurer; dc.Configure(config); return; } config.UsePersistence(persistenceType); }
public static void DefineTransport(this BusConfiguration config, IDictionary<string, string> settings, Type endpointBuilderType) { if (!settings.ContainsKey("Transport")) { settings = Transports.Default.Settings; } const string typeName = "ConfigureTransport"; var transportType = Type.GetType(settings["Transport"]); var transportTypeName = "Configure" + transportType.Name; var configurerType = endpointBuilderType.GetNestedType(typeName) ?? Type.GetType(transportTypeName, false); if (configurerType != null) { var configurer = Activator.CreateInstance(configurerType); dynamic dc = configurer; dc.Configure(config); var cleanupMethod = configurer.GetType().GetMethod("Cleanup", BindingFlags.Public | BindingFlags.Instance); config.GetSettings().Set("CleanupTransport", cleanupMethod != null ? configurer : new Cleaner()); return; } config.UseTransport(transportType).ConnectionString(settings["Transport.ConnectionString"]); }
public static void DefineTransport(this BusConfiguration builder, IDictionary<string, string> settings, Type endpointBuilderType) { if (!settings.ContainsKey("Transport")) { settings = Transports.Default.Settings; } const string typeName = "ConfigureTransport"; var transportType = Type.GetType(settings["Transport"]); var transportTypeName = "Configure" + transportType.Name; var configurerType = endpointBuilderType.GetNestedType(typeName) ?? Type.GetType(transportTypeName, false); if (configurerType != null) { var configurer = Activator.CreateInstance(configurerType); dynamic dc = configurer; dc.Configure(builder); return; } builder.UseTransport(transportType).ConnectionString(settings["Transport.ConnectionString"]); }
public BehaveLibrary(string libName) { m_LibraryName = libName; m_LibraryDllName = GetLibraryDll(m_LibraryName); m_LibraryTypeName = GetLibraryType(m_LibraryName); m_LiraryAssembly = Assembly.Load(m_LibraryDllName); if (m_LiraryAssembly != null) { m_LibraryType = m_LiraryAssembly.GetType(m_LibraryTypeName); if (m_LibraryType != null) { m_TreeType = m_LibraryType.GetNestedType("TreeType"); m_InstantiateFunc = m_LibraryType.GetMethod("InstantiateTree", BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static, null, new Type[] { m_TreeType, typeof(IAgent) }, null); } } if (error == "") { InitTreeType(); InitTreeActions(); } }
/// <summary> /// Handles removing the reference to the default UdonBehaviourEditor and injecting our own custom editor UdonBehaviourOverrideEditor /// </summary> static void OverrideUdonBehaviourDrawer() { if (customEditorField == null) { Assembly editorAssembly = AppDomain.CurrentDomain.GetAssemblies().First(e => e.GetName().Name == "UnityEditor"); System.Type editorAttributesClass = editorAssembly.GetType("UnityEditor.CustomEditorAttributes"); customEditorField = editorAttributesClass.GetField("kSCustomEditors", BindingFlags.NonPublic | BindingFlags.Static); System.Type fieldType = customEditorField.FieldType; removeTypeMethod = fieldType.GetMethods(BindingFlags.Public | BindingFlags.Instance) .FirstOrDefault(e => e.Name == "Remove" && e.GetParameters().Length == 1 && e.GetParameters()[0].ParameterType == typeof(System.Type)); monoEditorTypeType = editorAttributesClass.GetNestedType("MonoEditorType", BindingFlags.NonPublic); monoEditorTypeInspectedTypeField = monoEditorTypeType.GetField("m_InspectedType", BindingFlags.Public | BindingFlags.Instance); monoEditorTypeInspectorTypeField = monoEditorTypeType.GetField("m_InspectorType", BindingFlags.Public | BindingFlags.Instance); monoEditorTypeListType = typeof(List <>).MakeGenericType(monoEditorTypeType); addTypeMethod = fieldType.GetMethods(BindingFlags.Public | BindingFlags.Instance) .FirstOrDefault(e => e.Name == "Add" && e.GetParameters().Length == 2 && e.GetParameters()[0].ParameterType == typeof(System.Type) && e.GetParameters()[1].ParameterType == monoEditorTypeListType); listAddTypeMethod = monoEditorTypeListType.GetMethods(BindingFlags.Public | BindingFlags.Instance) .FirstOrDefault(e => e.Name == "Add" && e.GetParameters().Length == 1 && e.GetParameters()[0].ParameterType == monoEditorTypeType); listClearMethod = monoEditorTypeListType.GetMethods(BindingFlags.Public | BindingFlags.Instance) .FirstOrDefault(e => e.Name == "Clear" && e.GetParameters().Length == 0); customEditorDictionary = customEditorField.GetValue(null); editorTypeObject = Activator.CreateInstance(monoEditorTypeType); monoEditorTypeInspectedTypeField.SetValue(editorTypeObject, typeof(UdonBehaviour)); monoEditorTypeInspectorTypeField.SetValue(editorTypeObject, typeof(UdonBehaviourOverrideEditor)); editorTypeList = Activator.CreateInstance(monoEditorTypeListType); listCreateParams[0] = editorTypeObject; } listClearMethod.Invoke(editorTypeList, null); listAddTypeMethod.Invoke(editorTypeList, listCreateParams); removeTypeMethod.Invoke(customEditorDictionary, udonBehaviourTypeArr); addTypeInvokeParams[1] = editorTypeList; addTypeMethod.Invoke(customEditorDictionary, addTypeInvokeParams); }
protected absOpenTKDllImportLoader(Type loader) { pDllImportClass = loader.GetNestedType("DllImports", BindingFlags.Public | BindingFlags.NonPublic); var funcs = pDllImportClass.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); //if (funcs == null) // throw new ApplicationException("Failed to find any static functions in DllImports??"); pDllImportMap = new SortedList<string, MethodInfo>(); foreach (var m in funcs) pDllImportMap.Add(m.Name, m); }
private void Drop() { Assembly assembly = typeof(Editor).Assembly; System.Type tp = assembly.GetType("UnityEditor.LayoutDropdownWindow"); System.Type mode = tp.GetNestedType("LayoutMode"); Debug.Log(mode); MethodInfo method = tp.GetMethod("DrawLayoutMode", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(Rect), mode, mode }, null); Debug.Log(method); method.Invoke(null, new object[] { new Rect(0, 0, 500, 500), 0, 0 }); }
/// <internal /> /// <summary>Loads all extensions for the specified class. This function is intended /// for OpenGL, Wgl, Glx, OpenAL etc.</summary> /// <param name="type">The class to load extensions for.</param> /// <remarks> /// <para>The Type must contain a nested class called "Delegates".</para> /// <para> /// The Type must also implement a static function called LoadDelegate with the /// following signature: /// <code>static Delegate LoadDelegate(string name, Type signature)</code> /// </para> /// <para>This function allocates memory.</para> /// </remarks> internal static void LoadExtensions(Type type) { // Using reflection is more than 3 times faster than directly loading delegates on the first // run, probably due to code generation overhead. Subsequent runs are faster with direct loading // than with reflection, but the first time is more significant. int supported = 0; Type extensions_class = type.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (extensions_class == null) throw new InvalidOperationException("The specified type does not have any loadable extensions."); FieldInfo[] delegates = extensions_class.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (delegates == null) throw new InvalidOperationException("The specified type does not have any loadable extensions."); MethodInfo load_delegate_method_info = type.GetMethod("LoadDelegate", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (load_delegate_method_info == null) throw new InvalidOperationException(type.ToString() + " does not contain a static LoadDelegate method."); LoadDelegateFunction LoadDelegate = (LoadDelegateFunction)Delegate.CreateDelegate( typeof(LoadDelegateFunction), load_delegate_method_info); Debug.Write("Load extensions for " + type.ToString() + "... "); System.Diagnostics.Stopwatch time = new System.Diagnostics.Stopwatch(); time.Reset(); time.Start(); foreach (FieldInfo f in delegates) { Delegate d = LoadDelegate(f.Name, f.FieldType); if (d != null) ++supported; f.SetValue(null, d); } FieldInfo rebuildExtensionList = type.GetField("rebuildExtensionList", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (rebuildExtensionList != null) rebuildExtensionList.SetValue(null, true); time.Stop(); Debug.Print("{0} extensions loaded in {1} ms.", supported, time.ElapsedMilliseconds); time.Reset(); }
static PopupButtonPanelHelper () { Assembly swfAssembly = Assembly.GetAssembly (typeof (Control)); pbpType = swfAssembly.GetType ("System.Windows.Forms.PopupButtonPanel"); pbType = pbpType.GetNestedType ("PopupButton", BindingFlags.NonPublic); performClickMethod = pbType.GetMethod ("PerformClick", BindingFlags.Instance | BindingFlags.NonPublic); }
static Type ResolveType(Assembly assembly, List <string> names, Func <Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { Type type = null; string name = EscapeTypeName(names [0]); // Resolve the top level type. if (typeResolver != null) { type = typeResolver(assembly, name, ignoreCase); if (type == null && throwOnError) { if (assembly == null) { throw new TypeLoadException(SR.Format(SR.TypeLoad_ResolveType, name)); } else { throw new TypeLoadException(SR.Format(SR.TypeLoad_ResolveTypeFromAssembly, name, assembly.FullName)); } } } else { if (assembly == null) { type = RuntimeType.GetType(name, throwOnError, ignoreCase, false, ref stackMark); } else { type = assembly.GetType(name, throwOnError, ignoreCase); } } if (type == null) { return(null); } // Resolve nested types. BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public; if (ignoreCase) { bindingFlags |= BindingFlags.IgnoreCase; } for (int i = 1; i < names.Count; ++i) { type = type.GetNestedType(names[i], bindingFlags); if (type == null) { if (throwOnError) { throw new TypeLoadException(SR.Format(SR.TypeLoad_ResolveNestedType, names[i], names[i - 1])); } else { break; } } } return(type); }
public static void LoadDelegates(IntPtr handle, Type type, GetFunctionAddress addressGetter) { FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public); for (int i = 0; i < fields.Length; i++) { FieldInfo f = fields[i]; if (f.FieldType == typeof(int)) { continue; } string funcName = f.FieldType.Name; IntPtr address = GetProcAddress(handle, funcName); if (address == IntPtr.Zero && addressGetter != null) { address = addressGetter(funcName); } if (address == IntPtr.Zero) { f.SetValue(null, null); } else { f.SetValue(null, Marshal.GetDelegateForFunctionPointer(address, f.FieldType)); } } Type privateType = type.GetNestedType("Private"); if (privateType != null) { LoadDelegates(handle, privateType, addressGetter); } }
private static IConstructionHelper GetConstructor(Type proxy) { Type cnt = proxy.GetNestedType("ContructionHelper", BindingFlags.NonPublic | BindingFlags.Public); if (cnt == null) { if (Bridge.Setup.Verbose) { Console.WriteLine("Can't find .NET ContructioHelper: " + proxy); } throw new JNIException("Can't find .NET ContructioHelper: " + proxy); } ConstructorInfo constructor = cnt.GetConstructor(BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.Public, null, new Type[] {}, null); if (constructor == null) { if (Bridge.Setup.Verbose) { Console.WriteLine("Can't find .NET ContructioHelper constructor: " + proxy); } throw new JNIException("Can't find .NET ContructioHelper constructor: " + proxy); } return (IConstructionHelper) constructor.Invoke(null); }
/// <internal /> /// <summary>Loads the specified extension for the specified class. This function is intended /// for OpenGL, Wgl, Glx, OpenAL etc.</summary> /// <param name="type">The class to load extensions for.</param> /// <param name="extension">The extension to load.</param> /// <remarks> /// <para>The Type must contain a nested class called "Delegates".</para> /// <para> /// The Type must also implement a static function called LoadDelegate with the /// following signature: /// <code>static Delegate LoadDelegate(string name, Type signature)</code> /// </para> /// <para>This function allocates memory.</para> /// </remarks> internal static bool TryLoadExtension(Type type, string extension) { Type extensions_class = type.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (extensions_class == null) { Debug.Print(type.ToString(), " does not contain extensions."); return false; } LoadDelegateFunction LoadDelegate = (LoadDelegateFunction)Delegate.CreateDelegate(typeof(LoadDelegateFunction), type.GetMethod("LoadDelegate", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)); if (LoadDelegate == null) { Debug.Print(type.ToString(), " does not contain a static LoadDelegate method."); return false; } FieldInfo f = extensions_class.GetField(extension, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (f == null) { Debug.Print("Extension \"", extension, "\" not found in ", type.ToString()); return false; } Delegate old = f.GetValue(null) as Delegate; Delegate @new = LoadDelegate(f.Name, f.FieldType); if ((old != null ? old.Target : null) != (@new != null ? @new.Target : null)) { f.SetValue(null, @new); FieldInfo rebuildExtensionList = type.GetField("rebuildExtensionList", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (rebuildExtensionList != null) rebuildExtensionList.SetValue(null, true); } return @new != null; }
internal Type GetNestedType(Type type, string name) { Type nestedType; DynamicType dynamicType = dynamicAssembly.GetDynamicType(type); if (dynamicType != null) nestedType = dynamicType.GetNestedType(name); else nestedType = type.GetNestedType(name, BindingFlags.Public | BindingFlags.NonPublic); if (nestedType == null) throw new InvalidOperationException(string.Format("Nested type not found: {0}+{1}", type, name)); return nestedType; }
static Type GetNestedType(Type type, string typeName) { return type.GetNestedType(typeName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); }
public object Get(string name, object instance, Type type, params object[] arguments) { #if !PocketPC && !SILVERLIGHT Type nested = type.GetNestedType(name); #else Type nested = type.GetNestedType(name, BindingFlags.Public | BindingFlags.NonPublic); #endif if (nested == null) return NoResult; return nested; }
public static void ValidateMemberSources(this Type targetType, Type sourceType) { Contract.Requires(targetType != null); Contract.Requires(sourceType != null); Contract.Requires(targetType != sourceType); var rootTargetAndSourceFullNames = Tuple.Create(targetType.FullName, sourceType.FullName); foreach (var targetField in targetType.GetFields(TestContent.BindingFlagsForWeavedMembers)) { targetField.ValidateSourceEqual(sourceType.GetField(targetField.Name, TestContent.BindingFlagsForWeavedMembers), rootTargetAndSourceFullNames); } foreach (var targetMethod in targetType.GetMethods(TestContent.BindingFlagsForWeavedMembers)) { // can't match by parameter types because some of the generic type arguments may have been redirected during mixing targetMethod.ValidateSourceEqual( sourceType.GetMethods(TestContent.BindingFlagsForWeavedMembers) .SingleOrDefault(method => targetMethod.IsSourceNameEqual(method, rootTargetAndSourceFullNames)), rootTargetAndSourceFullNames); } foreach (var targetProperty in targetType.GetProperties(TestContent.BindingFlagsForWeavedMembers)) { targetProperty.ValidateSourceEqual(sourceType.GetProperty( targetProperty.Name, TestContent.BindingFlagsForWeavedMembers, null, targetProperty.PropertyType, targetProperty.GetIndexParameters().Select(each => each.ParameterType).ToArray(), null), rootTargetAndSourceFullNames); } foreach (var targetEvent in targetType.GetEvents(TestContent.BindingFlagsForWeavedMembers)) { targetEvent.ValidateSourceEqual(sourceType.GetEvent( targetEvent.Name, TestContent.BindingFlagsForWeavedMembers), rootTargetAndSourceFullNames); } foreach (var targetNestedType in targetType.GetNestedTypes(TestContent.BindingFlagsForWeavedMembers)) { targetNestedType.ValidateSourceEqual(sourceType.GetNestedType(targetNestedType.Name, TestContent.BindingFlagsForWeavedMembers), rootTargetAndSourceFullNames); } }
internal static bool TryLoadExtension(Type type, string extension) { Type nestedType = type.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (nestedType == null) return false; Utilities.LoadDelegateFunction delegateFunction = (Utilities.LoadDelegateFunction) Delegate.CreateDelegate(typeof (Utilities.LoadDelegateFunction), type.GetMethod("LoadDelegate", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)); if (delegateFunction == null) return false; FieldInfo field1 = nestedType.GetField(extension, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field1 == null) return false; Delegate delegate1 = field1.GetValue((object) null) as Delegate; Delegate delegate2 = delegateFunction(field1.Name, field1.FieldType); if ((delegate1 != null ? delegate1.Target : (object) null) != (delegate2 != null ? delegate2.Target : (object) null)) { field1.SetValue((object) null, (object) delegate2); FieldInfo field2 = type.GetField("rebuildExtensionList", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field2 != null) field2.SetValue((object) null, (object) true); } return delegate2 != null; }
internal static void LoadExtensions(Type type) { int num = 0; Type nestedType = type.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (nestedType == null) throw new InvalidOperationException("The specified type does not have any loadable extensions."); FieldInfo[] fields = nestedType.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (fields == null) throw new InvalidOperationException("The specified type does not have any loadable extensions."); MethodInfo method = type.GetMethod("LoadDelegate", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (method == null) throw new InvalidOperationException(type.ToString() + " does not contain a static LoadDelegate method."); Utilities.LoadDelegateFunction delegateFunction = (Utilities.LoadDelegateFunction) Delegate.CreateDelegate(typeof (Utilities.LoadDelegateFunction), method); Stopwatch stopwatch = new Stopwatch(); stopwatch.Reset(); stopwatch.Start(); foreach (FieldInfo fieldInfo in fields) { Delegate @delegate = delegateFunction(fieldInfo.Name, fieldInfo.FieldType); if (@delegate != null) ++num; fieldInfo.SetValue((object) null, (object) @delegate); } FieldInfo field = type.GetField("rebuildExtensionList", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) field.SetValue((object) null, (object) true); stopwatch.Stop(); stopwatch.Reset(); }
private static void AssignImplementations(Type platformDependant, string implementationName) { Type platformImplementation = platformDependant.GetNestedType(implementationName, bindings); // if (platformImplementation == null) return; FieldInfo[] fields = platformDependant.GetFields(bindings); foreach (FieldInfo field in fields) { Type fieldType = field.FieldType; string delegateName = fieldType.Name; MethodInfo methodInfo__internal = null; FieldInfo fieldInfo__internal = null; // TODO: This is mapping sodium.crypto_box to sodium.crypto_box__Internal. Should we also map them to sodium.__Internal.crypto_box? if (implementationName == "__Internal") { if (delegateName.EndsWith("_delegate")) { // YOU now have // public static readonly crypto_box_delegate box = crypto_box; // YOU need // public static readonly crypto_box_delegate box = crypto_box__Internal; delegateName = delegateName.Substring(0, delegateName.Length - "_delegate".Length); if (delegateName.Length > 0) { methodInfo__internal = platformDependant.GetMethod(delegateName + "__Internal", bindings); } } } if (methodInfo__internal == null && platformImplementation != null) { if (delegateName.EndsWith("Delegate")) { // YOU now have // public static readonly UnmanagedLibrary LoadUnmanagedLibraryDelegate; // YOU need // public static readonly LoadUnmanagedLibraryDelegate LoadUnmanagedLibrary // = Platform.__Internal.LoadUnmanagedLibrary; delegateName = delegateName.Substring(0, delegateName.Length - "Delegate".Length); methodInfo__internal = platformImplementation.GetMethod(delegateName, bindings); } else { methodInfo__internal = platformImplementation.GetMethod(field.Name, bindings); } if (methodInfo__internal == null) { fieldInfo__internal = platformImplementation.GetField(field.Name, bindings); } } if (methodInfo__internal != null) { var delegat = Delegate.CreateDelegate(fieldType, methodInfo__internal); field.SetValue(null, delegat); } else if (fieldInfo__internal != null) { object value = fieldInfo__internal.GetValue(null); field.SetValue(null, value); } // else { field.SetValue(null, null); } } }
public static Type GetNestedTypePortable(Type type, string name) { return type.GetNestedType(name); }
internal Type ParseStaticTypeExtension(TokenStore ts, Type t, bool allowArrayType) { // check nullable if (t.IsValueType && ts.CurrentValue == "?" && NullableType.ContainsKey(t)) { t = NullableType[t]; ts.Next(); // skip "?" } // check nested type Type t2=null; while (ts.CurrentValue == "." && ts.PeekToken(1) != null && ts.PeekToken(1).tok_type == TOKEN_TYPE.IDENTIFIER && (t2 = t.GetNestedType(ts.PeekToken(1).value)) != null) { t = t2; ts.Next(); // skip '.' ts.Next(); // skip nested type } // check array: t[,][], if after new operater, do not check array here if (allowArrayType) { while (ts.CurrentValue == "[") { StringBuilder arr = new StringBuilder("["); AToken tok = ts.Next(); // skip "[" while ((tok = ts.Current) != null && tok.value != "]") arr.Append(tok.value); Assert((t = t.Assembly.GetType(t.FullName + arr.Append("]").ToString())) != null, tok); Assert(tok.value == "]", tok); tok = ts.Next(); // skip "]" } } return t; }
private void cbParser_SelectedIndexChanged(object sender, EventArgs e) { clbSubParsers.Items.Clear(); if (cbParser.SelectedIndex > -1) { m_parser = m_loader[cbParser.SelectedIndex]; var subparsers = m_parser.GetNestedType("SubParsers"); if (subparsers != null) { int index = 0; foreach (var sub in Enum.GetValues(subparsers)) { clbSubParsers.Items.Add(sub.ToString()); clbSubParsers.SetItemChecked(index++, true); } } } }
public BehaveAction(System.Type argType, string argName) { m_Type = argType; m_DataType = argType.GetNestedType("Data", BindingFlags.Instance | BindingFlags.NonPublic); m_Name = argName; }
static int MetaIndexFunctionInternal(lua_State L) { var isIndexingClassObject = IsIndexingClassObject(L); System.Type typeObject = null; if (isIndexingClassObject) { typeObject = (System.Type)Lua.ObjectAtInternal(L, 1); } object thisObject = null; if (!isIndexingClassObject) { thisObject = Lua.ObjectAtInternal(L, 1); typeObject = thisObject.GetType(); } Lua.Assert(typeObject != null, "Should have a type"); if (Api.lua_isinteger(L, 2)) { if (typeObject != null && typeObject.IsArray) { var array = (System.Array)thisObject; Lua.PushValueInternal(L, array.GetValue((int)Api.lua_tointeger(L, 2))); return(1); } else { return(Lua.IndexObjectInternal(L, thisObject, typeObject, new object[] { (int)Api.lua_tointeger(L, 2) })); } } else if (Api.lua_isstring(L, 2)) { return(Lua.GetMember(L, thisObject, typeObject, Api.lua_tostring(L, 2), false, null, null)); } else if (Api.lua_istable(L, 2)) { var host = Lua.CheckHost(L); using (var p = LuaTable.MakeRefTo(host, 2)) { var isGettingTypeObject = (bool)host.isIndexingTypeObject.Invoke1(p); if (isGettingTypeObject) { Lua.PushObjectInternal(L, typeObject); return(1); } using (var ret = host.testPrivillage.InvokeMultiRet(p)) { var name = (string)ret[1]; var hasPrivatePrivillage = (bool)ret[2]; var retrievingNestedType = (bool)ret[5]; if (retrievingNestedType) { var flags = System.Reflection.BindingFlags.Public; if (hasPrivatePrivillage) { flags |= System.Reflection.BindingFlags.NonPublic; } var nestedType = typeObject.GetNestedType(name, flags); if (nestedType != null) { Lua.PushTypeInternal(L, nestedType); } else { Api.lua_pushnil(L); } return(1); } var exactTypes = (Type[])ret[3]; var genericTypes = (Type[])ret[4]; return(Lua.GetMember(L, thisObject, typeObject, name, hasPrivatePrivillage, exactTypes, genericTypes)); } } } else { return(Lua.IndexObjectInternal(L, thisObject, typeObject, new object[] { Lua.ValueAtInternal(L, 2) })); } }
private static void AssignImplementations(Type platformDependentType, string implementationName) { BindingFlags bindings = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; // TODO: instance members Type platformNameImpl = platformDependentType.GetNestedType(implementationName, bindings); if (platformNameImpl == null) { // TODO: else fail? return; } MemberInfo[] platformMembers = platformNameImpl.GetMembers(bindings); foreach (MemberInfo platformMember in platformMembers) { // TODO: overloaded members, GetBySignature? FieldInfo member = platformDependentType.GetField(platformMember.Name, bindings); if (member == null) { // TODO: else fail? continue; } if (platformMember.MemberType == MemberTypes.Method) { // if (typeof(Delegate).IsAssignableFrom(member.FieldType)) { var delegat = Delegate.CreateDelegate(member.FieldType, (MethodInfo)platformMember); member.SetValue(null /* static */, delegat); continue; } if (platformMember.MemberType == MemberTypes.Field) { // if (member.FieldType.IsAssignableFrom(platformMember.FieldType)) { member.SetValue(null /* static */, ((FieldInfo)platformMember).GetValue(null /* static */)); continue; } // TODO: else fail? } }
// Use reflection to look at the attributes of a class, and generate a manifest for it (as UTF8) and // return the UTF8 bytes. It also sets up the code:EventData structures needed to dispatch events // at run time. 'source' is the event source to place the descriptors. If it is null, // then the descriptors are not creaed, and just the manifest is generated. private static byte[] CreateManifestAndDescriptors(Type eventSourceType, string eventSourceDllName, EventSource source) { MethodInfo[] methods = eventSourceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); EventAttribute defaultEventAttribute; int eventId = 1; // The number given to an event that does not have a explicitly given ID. EventMetadata[] eventData = null; Dictionary<string, string> eventsByName = null; if (source != null) eventData = new EventMetadata[methods.Length]; // See if we have localization information. ResourceManager resources = null; EventSourceAttribute eventSourceAttrib = (EventSourceAttribute)GetCustomAttributeHelper(eventSourceType, typeof(EventSourceAttribute)); if (eventSourceAttrib != null && eventSourceAttrib.LocalizationResources != null) resources = new ResourceManager(eventSourceAttrib.LocalizationResources, eventSourceType.Assembly); ManifestBuilder manifest = new ManifestBuilder(GetName(eventSourceType), GetGuid(eventSourceType), eventSourceDllName, resources); // Collect task, opcode, keyword and channel information #if FEATURE_MANAGED_ETW_CHANNELS foreach (var providerEnumKind in new string[] { "Keywords", "Tasks", "Opcodes", "Channels" }) #else foreach (var providerEnumKind in new string[] { "Keywords", "Tasks", "Opcodes" }) #endif { Type nestedType = eventSourceType.GetNestedType(providerEnumKind); if (nestedType != null) { foreach (FieldInfo staticField in nestedType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)) { AddProviderEnumKind(manifest, staticField, providerEnumKind); } } } for (int i = 0; i < methods.Length; i++) { MethodInfo method = methods[i]; ParameterInfo[] args = method.GetParameters(); // Get the EventDescriptor (from the Custom attributes) EventAttribute eventAttribute = (EventAttribute)GetCustomAttributeHelper(method, typeof(EventAttribute)); // Methods that don't return void can't be events. if (method.ReturnType != typeof(void)) { if (eventAttribute != null) throw new ArgumentException(Environment.GetResourceString("EventSource_AttributeOnNonVoid", method.Name)); continue; } if (method.IsVirtual || method.IsStatic) { continue; } if (eventAttribute == null) { // If we explictly mark the method as not being an event, then honor that. if (GetCustomAttributeHelper(method, typeof(NonEventAttribute)) != null) continue; defaultEventAttribute = new EventAttribute(eventId); eventAttribute = defaultEventAttribute; } else if (eventAttribute.EventId <= 0) throw new ArgumentException(Environment.GetResourceString("EventSource_NeedPositiveId")); else if ((ulong)eventAttribute.Keywords >= 0x0000100000000000UL) throw new ArgumentException(Environment.GetResourceString("EventSource_ReservedKeywords")); eventId++; // Auto-assign tasks, starting with the highest task number and working back if (eventAttribute.Opcode == EventOpcode.Info && eventAttribute.Task == EventTask.None) eventAttribute.Task = (EventTask)(0xFFFE - eventAttribute.EventId); manifest.StartEvent(method.Name, eventAttribute); for (int fieldIdx = 0; fieldIdx < args.Length; fieldIdx++) { // If the first parameter is 'RelatedActivityId' then skip it. if (fieldIdx == 0 && args[fieldIdx].ParameterType == typeof(Guid) && string.Compare(args[fieldIdx].Name, "RelatedActivityId", StringComparison.OrdinalIgnoreCase) == 0) continue; manifest.AddEventParameter(args[fieldIdx].ParameterType, args[fieldIdx].Name); } manifest.EndEvent(); if (source != null) { // Do checking for user errors (optional, but nto a big deal so we do it). DebugCheckEvent(ref eventsByName, eventData, method, eventAttribute); AddEventDescriptor(ref eventData, method.Name, eventAttribute, args); } } if (source != null) { TrimEventDescriptors(ref eventData); source.m_eventData = eventData; // officaly initialize it. We do this at most once (it is racy otherwise). } return manifest.CreateManifest(); }
private static Type ResolveType(Assembly assembly, string[] names, Func <Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { Contract.Requires(names != null && names.Length > 0); Type type = null; // both the customer provided and the default type resolvers accept escaped type names string OuterMostTypeName = EscapeTypeName(names[0]); // Resolve the top level type. if (typeResolver != null) { type = typeResolver(assembly, OuterMostTypeName, ignoreCase); if (type == null && throwOnError) { string errorString = assembly == null? Environment.GetResourceString("TypeLoad_ResolveType", OuterMostTypeName) : Environment.GetResourceString("TypeLoad_ResolveTypeFromAssembly", OuterMostTypeName, assembly.FullName); throw new TypeLoadException(errorString); } } else { if (assembly == null) { type = RuntimeType.GetType(OuterMostTypeName, throwOnError, ignoreCase, false, ref stackMark); } else { type = assembly.GetType(OuterMostTypeName, throwOnError, ignoreCase); } } // Resolve nested types. if (type != null) { BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public; if (ignoreCase) { bindingFlags |= BindingFlags.IgnoreCase; } for (int i = 1; i < names.Length; i++) { type = type.GetNestedType(names[i], bindingFlags); if (type == null) { if (throwOnError) { throw new TypeLoadException(Environment.GetResourceString("TypeLoad_ResolveNestedType", names[i], names[i - 1])); } else { break; } } } } return(type); }
/// <summary> /// Link delegates fields using import declarations. /// </summary> /// <param name="path"> /// A <see cref="System.String"/> that specifies the assembly file path containing the import functions. /// </param> /// <param name="type"> /// A <see cref="System.Type"/> that specifies the type used for detecting import declarations and delegates fields. /// </param> /// <param name="getAddress"> /// A <see cref="GetAddressDelegate"/> used for getting function pointers. This parameter is dependent on the currently running platform. /// </param> /// <param name="sImportMap"> /// A <see cref="T:SortedList{String, MethodIndo}"/> mapping a <see cref="MethodInfo"/> with the relative function name. /// </param> /// <param name="sDelegates"> /// A <see cref="T:List{FieldInfo}"/> listing <see cref="FieldInfo"/> related to function delegates. /// </param> /// <remarks> /// <para> /// The type <paramref name="type"/> shall have defined a nested class named "UnsafeNativeMethods" specifying the import declarations and a nested /// class named "Delagates" specifying the delegate fields. /// </para> /// </remarks> private static void LinkProcAddressImports(string path, Type type, GetAddressDelegate getAddress, out SortedList<string, MethodInfo> sImportMap, out List<FieldInfo> sDelegates) { Type impClass = type.GetNestedType("UnsafeNativeMethods", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); Debug.Assert(impClass != null); Type delClass = type.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic); Debug.Assert(delClass != null); // Query imports declarations MethodInfo[] iMethods = impClass.GetMethods(BindingFlags.Static | BindingFlags.NonPublic); sImportMap = new SortedList<string, MethodInfo>(iMethods.Length); foreach (MethodInfo m in iMethods) sImportMap.Add(m.Name, m); // Query delegates declarations sDelegates = new List<FieldInfo>(delClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic)); foreach (FieldInfo fi in sDelegates) { Delegate pDelegate = null; string pImportName = fi.Name.Substring(1); IntPtr mAddr = getAddress(path, pImportName); if (mAddr != IntPtr.Zero) { // Try to load external symbol if ((pDelegate = Marshal.GetDelegateForFunctionPointer(mAddr, fi.FieldType)) == null) { MethodInfo mInfo; if (sImportMap.TryGetValue(pImportName, out mInfo) == true) pDelegate = Delegate.CreateDelegate(fi.FieldType, mInfo); } if (pDelegate != null) fi.SetValue(null, pDelegate); } } }
internal Type Resolve(Func <AssemblyName, Assembly> assemblyResolver, Func <Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase) { Assembly asm = null; if (assemblyResolver == null && typeResolver == null) { return(Type.GetType(DisplayFullName, throwOnError, ignoreCase)); } if (assembly_name != null) { if (assemblyResolver != null) { asm = assemblyResolver(new AssemblyName(assembly_name)); } else { asm = Assembly.Load(assembly_name); } if (asm == null) { if (throwOnError) { throw new FileNotFoundException("Could not resolve assembly '" + assembly_name + "'"); } return(null); } } Type type = null; if (typeResolver != null) { type = typeResolver(asm, name.DisplayName, ignoreCase); } else { type = asm.GetType(name.DisplayName, false, ignoreCase); } if (type == null) { if (throwOnError) { throw new TypeLoadException("Could not resolve type '" + name + "'"); } return(null); } if (nested != null) { foreach (var n in nested) { var tmp = type.GetNestedType(n.DisplayName, BindingFlags.Public | BindingFlags.NonPublic); if (tmp == null) { if (throwOnError) { throw new TypeLoadException("Could not resolve type '" + n + "'"); } return(null); } type = tmp; } } if (generic_params != null) { Type[] args = new Type [generic_params.Count]; for (int i = 0; i < args.Length; ++i) { var tmp = generic_params [i].Resolve(assemblyResolver, typeResolver, throwOnError, ignoreCase); if (tmp == null) { if (throwOnError) { throw new TypeLoadException("Could not resolve type '" + generic_params [i].name + "'"); } return(null); } args [i] = tmp; } type = type.MakeGenericType(args); } if (modifier_spec != null) { foreach (var md in modifier_spec) { type = md.Resolve(type); } } if (is_byref) { type = type.MakeByRefType(); } return(type); }
internal static SType GetClass(SType klass, string innerClassName) => klass?.GetNestedType(innerClassName);
/// <summary> /// Find a nested type defined in this class or a base class. /// </summary> /// <param name="searchType">The class to search.</param> /// <param name="className">The name of the class to find.</param> /// <returns>The given nested type or null if not found.</returns> private static Type FindNestedType(Type searchType, string className) { Type nestedType = null; // if an enumSource type has not been defined, look up the original class hierarchy until we find it for (; nestedType == null && searchType != null; searchType = searchType.BaseType) nestedType = searchType.GetNestedType(className); return nestedType; }
private static object TranslateSurrogate(object deserializedValue,ActorSystem system,Type type) { var j = deserializedValue as JObject; if (j != null) { if (j["$"] != null) { var value = j["$"].Value<string>(); return GetValue(value); } if (j["Case"] != null) { var caseTypeName = j["Case"].Value<string>(); var caseType = type.GetNestedType(caseTypeName); var ctor = caseType.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0]; var paramTypes = ctor.GetParameters().Select(p => p.ParameterType).ToArray(); var values = j["Fields"].ToObject<object[]>() .Select((o, i) => TranslateSurrogate(o, system, paramTypes[i])) .ToArray(); var res = ctor.Invoke(values.ToArray()); return res; } } var surrogate = deserializedValue as ISurrogate; if (surrogate != null) { return surrogate.FromSurrogate(system); } return deserializedValue; }
public object Get(string name, object instance, Type type, params object[] arguments) { Type nested = type.GetNestedType(name, ObjectBinder.NestedTypeFilter); if (nested == null) return NoResult; return nested; }
private static void SetHunspellDelegate(Type marshalType, MethodInfo getDelegateMethod, string call, string delegateName) { var delegateField = marshalType.GetField(call, BindingFlags.NonPublic | BindingFlags.Static); var delegateType = marshalType.GetNestedType(delegateName, BindingFlags.NonPublic); delegateField.SetValue(null, getDelegateMethod.Invoke(null, new object[] { call, delegateType })); }
/// <summary> /// Handles removing the reference to the default UdonBehaviourEditor and injecting our own custom editor UdonBehaviourOverrideEditor /// </summary> public static void OverrideUdonBehaviourDrawer() { #if !UNITY_2019_4_OR_NEWER if (customEditorField == null) #endif { Assembly editorAssembly = typeof(UnityEditor.Editor).Assembly; System.Type editorAttributesClass = editorAssembly.GetType("UnityEditor.CustomEditorAttributes"); customEditorField = editorAttributesClass.GetField("kSCustomEditors", BindingFlags.NonPublic | BindingFlags.Static); System.Type fieldType = customEditorField.FieldType; removeTypeMethod = fieldType.GetMethods(BindingFlags.Public | BindingFlags.Instance) .FirstOrDefault(e => e.Name == "Remove" && e.GetParameters().Length == 1 && e.GetParameters()[0].ParameterType == typeof(System.Type)); monoEditorTypeType = editorAttributesClass.GetNestedType("MonoEditorType", BindingFlags.NonPublic); monoEditorTypeInspectedTypeField = monoEditorTypeType.GetField("m_InspectedType", BindingFlags.Public | BindingFlags.Instance); monoEditorTypeInspectorTypeField = monoEditorTypeType.GetField("m_InspectorType", BindingFlags.Public | BindingFlags.Instance); monoEditorTypeListType = typeof(List <>).MakeGenericType(monoEditorTypeType); addTypeMethod = fieldType.GetMethods(BindingFlags.Public | BindingFlags.Instance) .FirstOrDefault(e => e.Name == "Add" && e.GetParameters().Length == 2 && e.GetParameters()[0].ParameterType == typeof(System.Type) && e.GetParameters()[1].ParameterType == monoEditorTypeListType); listAddTypeMethod = monoEditorTypeListType.GetMethods(BindingFlags.Public | BindingFlags.Instance) .FirstOrDefault(e => e.Name == "Add" && e.GetParameters().Length == 1 && e.GetParameters()[0].ParameterType == monoEditorTypeType); listClearMethod = monoEditorTypeListType.GetMethods(BindingFlags.Public | BindingFlags.Instance) .FirstOrDefault(e => e.Name == "Clear" && e.GetParameters().Length == 0); customEditorDictionary = customEditorField.GetValue(null); editorTypeObject = Activator.CreateInstance(monoEditorTypeType); monoEditorTypeInspectedTypeField.SetValue(editorTypeObject, typeof(UdonBehaviour)); monoEditorTypeInspectorTypeField.SetValue(editorTypeObject, typeof(UdonBehaviourOverrideEditor)); editorTypeList = Activator.CreateInstance(monoEditorTypeListType); listCreateParams[0] = editorTypeObject; #if UNITY_2019_4_OR_NEWER FieldInfo initializedField = editorAttributesClass.GetField("s_Initialized", BindingFlags.Static | BindingFlags.NonPublic); if (!(bool)initializedField.GetValue(null)) { MethodInfo rebuildMethod = editorAttributesClass.GetMethod("Rebuild", BindingFlags.Static | BindingFlags.NonPublic); rebuildMethod.Invoke(null, null); initializedField.SetValue(null, true); } #endif } listClearMethod.Invoke(editorTypeList, null); listAddTypeMethod.Invoke(editorTypeList, listCreateParams); removeTypeMethod.Invoke(customEditorDictionary, udonBehaviourTypeArr); addTypeInvokeParams[1] = editorTypeList; addTypeMethod.Invoke(customEditorDictionary, addTypeInvokeParams); }