Exemplo n.º 1
0
        /// <summary>
        /// Tries to create a new StandardUserDataFieldDescriptor, returning <c>null</c> in case the field is not
        /// visible to script code.
        /// </summary>
        /// <param name="fi">The FieldInfo.</param>
        /// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
        /// <returns>A new StandardUserDataFieldDescriptor or null.</returns>
        public static StandardUserDataFieldDescriptor TryCreateIfVisible(FieldInfo fi, InteropAccessMode accessMode)
        {
            if (StandardUserDataDescriptor.GetVisibilityFromAttributes(fi) ?? fi.IsPublic)
            {
                return(new StandardUserDataFieldDescriptor(fi, accessMode));
            }

            return(null);
        }
        /// <summary>
        /// Tries to create a new StandardUserDataEventDescriptor, returning <c>null</c> in case the method is not
        /// visible to script code.
        /// </summary>
        /// <param name="ei">The EventInfo.</param>
        /// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
        /// <returns>A new StandardUserDataEventDescriptor or null.</returns>
        public static StandardUserDataEventDescriptor TryCreateIfVisible(EventInfo ei, InteropAccessMode accessMode)
        {
            if (!CheckEventIsCompatible(ei, false))
            {
                return(null);
            }

            if (StandardUserDataDescriptor.GetVisibilityFromAttributes(ei) ?? (ei.GetAddMethod().IsPublic&& ei.GetRemoveMethod().IsPublic))
            {
                return(new StandardUserDataEventDescriptor(ei, accessMode));
            }

            return(null);
        }
        /// <summary>
        /// Tries to create a new StandardUserDataMethodDescriptor, returning <c>null</c> in case the method is not
        /// visible to script code.
        /// </summary>
        /// <param name="methodBase">The MethodBase.</param>
        /// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
        /// <returns>A new StandardUserDataMethodDescriptor or null.</returns>
        public static StandardUserDataMethodDescriptor TryCreateIfVisible(MethodBase methodBase, InteropAccessMode accessMode)
        {
            if (!CheckMethodIsCompatible(methodBase, false))
            {
                return(null);
            }

            if (StandardUserDataDescriptor.GetVisibilityFromAttributes(methodBase) ?? methodBase.IsPublic)
            {
                return(new StandardUserDataMethodDescriptor(methodBase, accessMode));
            }

            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Tries to create a new StandardUserDataPropertyDescriptor, returning <c>null</c> in case the property is not
        /// visible to script code.
        /// </summary>
        /// <param name="pi">The PropertyInfo.</param>
        /// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
        /// <returns>A new StandardUserDataPropertyDescriptor or null.</returns>
        public static StandardUserDataPropertyDescriptor TryCreateIfVisible(PropertyInfo pi, InteropAccessMode accessMode)
        {
            MethodInfo getter = pi.GetGetMethod(true);
            MethodInfo setter = pi.GetSetMethod(true);

            bool?pvisible = StandardUserDataDescriptor.GetVisibilityFromAttributes(pi);
            bool?gvisible = StandardUserDataDescriptor.GetVisibilityFromAttributes(getter);
            bool?svisible = StandardUserDataDescriptor.GetVisibilityFromAttributes(setter);

            if (pvisible.HasValue)
            {
                return(StandardUserDataPropertyDescriptor.TryCreate(pi, accessMode,
                                                                    (gvisible ?? pvisible.Value) ? getter : null,
                                                                    (svisible ?? pvisible.Value) ? setter : null));
            }
            else
            {
                return(StandardUserDataPropertyDescriptor.TryCreate(pi, accessMode,
                                                                    (gvisible ?? getter.IsPublic) ? getter : null,
                                                                    (svisible ?? setter.IsPublic) ? setter : null));
            }
        }