Exemple #1
0
        /// <summary>
        /// Creates a CallbackFunction from a MethodInfo relative to a function.
        /// </summary>
        /// <param name="script">The script.</param>
        /// <param name="mi">The MethodInfo object.</param>
        /// <param name="obj">The object to which the function applies, or null for static methods.</param>
        /// <param name="accessMode">The access mode.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">The method is not static.</exception>
        public static CallbackFunction FromMethodInfo(Script script, System.Reflection.MethodInfo mi, object obj = null, InteropAccessMode accessMode = InteropAccessMode.Default)
        {
            if (accessMode == InteropAccessMode.Default)
            {
                accessMode = m_DefaultAccessMode;
            }

            StandardUserDataMethodDescriptor descr = new StandardUserDataMethodDescriptor(mi, accessMode);

            return(descr.GetCallbackFunction(script, obj));
        }
Exemple #2
0
        /// <summary>
        /// Creates a CallbackFunction from a delegate.
        /// </summary>
        /// <param name="script">The script.</param>
        /// <param name="del">The delegate.</param>
        /// <param name="accessMode">The access mode.</param>
        /// <returns></returns>
        public static CallbackFunction FromDelegate(Script script, Delegate del, InteropAccessMode accessMode = InteropAccessMode.Default)
        {
            if (accessMode == InteropAccessMode.Default)
            {
                accessMode = m_DefaultAccessMode;
            }

            StandardUserDataMethodDescriptor descr = new StandardUserDataMethodDescriptor(del.Method, accessMode);

            return(descr.GetCallbackFunction(script, del.Target));
        }
Exemple #3
0
        /// <summary>
        /// Registers an extension Type (that is a type containing extension methods)
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="mode">The InteropAccessMode.</param>
        public static void RegisterExtensionType(Type type, InteropAccessMode mode = InteropAccessMode.Default)
        {
            lock (s_Lock)
            {
                foreach (MethodInfo mi in type.GetMethods().Where(_mi => _mi.IsStatic))
                {
                    if (!StandardUserDataMethodDescriptor.CheckMethodIsCompatible(mi, false))
                    {
                        continue;
                    }

                    if (mi.GetCustomAttributes(typeof(ExtensionAttribute), false).Length == 0)
                    {
                        continue;
                    }

                    var desc = new StandardUserDataMethodDescriptor(mi, mode);

                    s_ExtensionMethodRegistry.Add(mi.Name, desc);

                    ++s_ExtensionMethodChangeVersion;
                }
            }
        }