/// <summary> /// Looks for a static method with the RegExportFunctionAttribute /// </summary> /// <param name="type">the type you want looking for the method</param> /// <param name="method">the method when its found</param> /// <param name="attribute">the attribute when its found</param> /// <returns>true when the method was found</returns> public static bool GetRegExportAttribute(Type type, ref MethodInfo method, ref RegExportFunctionAttribute attribute) { foreach (MethodInfo item in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { object[] array = item.GetCustomAttributes(typeof(RegExportFunctionAttribute), false); if (array.Length == 1) { method = item; attribute = array[0] as RegExportFunctionAttribute; return(true); } } return(false); }
/// <summary> /// Looks for a static method with the RegExportFunctionAttribute /// </summary> /// <param name="type">the type you want looking for the method</param> /// <param name="method">the method when its found</param> /// <param name="attribute">the attribute when its found</param> /// <returns>true when the method was found</returns> public static bool GetRegExportAttribute(Type type, ref MethodInfo method, ref RegExportFunctionAttribute attribute) { foreach (MethodInfo item in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { object[] array = item.GetCustomAttributes(typeof(RegExportFunctionAttribute), false); if (array.Length == 1) { method = item; attribute = array[0] as RegExportFunctionAttribute; return true; } } return false; }
/// <summary> /// Do register export process /// </summary> /// <param name="type">addin type</param> /// <param name="addinOfficeRegistryKey">office application registry path</param> /// <param name="scope">the current installation scope</param> /// <param name="keyState">the office registry key need to create</param> public static RegExport Proceed(Type type, string[] addinOfficeRegistryKey, InstallScope scope, OfficeRegisterKeyState keyState) { try { object result = null; MethodInfo exportMethod = null; RegExportFunctionAttribute registerAttribute = null; bool registerMethodPresent = AttributeReflector.GetRegExportAttribute(type, ref exportMethod, ref registerAttribute); if (registerMethodPresent) { ParameterInfo[] arguments = exportMethod.GetParameters(); int argumentCount = arguments.Length; switch (argumentCount) { case 0: result = exportMethod.Invoke(null, new object[0]); break; case 1: result = exportMethod.Invoke(null, new object[] { scope }); break; case 2: result = exportMethod.Invoke(null, new object[] { scope, keyState }); break; case 3: exportMethod.Invoke(null, new object[] { type, scope, keyState }); break; default: break; } return(result as RegExport); } else { return(null); } } catch (System.Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Export, exception); return(null); } }