예제 #1
0
        public static object InternalToObject(JsTypeFunction enumType, object value)
        {
            var  enumsByValue = enumsByTypeAndValue[enumType.TypeName];
            Enum result       = enumsByValue.GetOrDefault(value);

            if (result != null)
            {
                return(result);
            }
            else
            {
                // Otherwise it's an enum value that isn't represented by a declared member.  In
                // this case, we need to box the value and then force it to be recognized as the
                // enum type.
                result = Jsni.@new(Jsni.reference("Number"), value.As <JsObject>()).As <Enum>();

                foreach (var property in enumType.member("prototype"))
                {
                    result.As <JsObject>()[property] = enumType.member("prototype")[property];
                }
                foreach (var property in Jsni.type <Enum>().member("prototype"))
                {
                    result.As <JsObject>()[property] = Jsni.type <Enum>().member("prototype")[property];
                }

                result.___type = enumType;
                result.As <JsObject>().memberset("value", value.As <JsObject>());

                enumsByValue[value] = result;

                return(result);
            }
        }
예제 #2
0
 public static Event CreateCustomEvent(this Document document, string eventType, object args)
 {
     try
     {
         return(Jsni.@new(Jsni.reference("CustomEvent"), eventType, args.As <JsObject>()).As <Event>());
     }
     catch (Exception e)
     {
         var evt = document.CreateEvent("CustomEvent");
         evt.As <JsObject>().member("initCustomEvent").invoke(eventType, false, true, args.As <JsObject>());
         return(evt);
     }
 }
예제 #3
0
        /// <summary>
        /// When overridden in a derived class, sets the property value for a specified object that has the specified binding, index, and culture-specific information.
        /// </summary>
        /// <param name="obj">The object whose property value will be set. </param><param name="value">The new property value. </param><param name="invokeAttr">A bitwise combination of the following enumeration members that specify the invocation attribute: InvokeMethod, CreateInstance, Static, GetField, SetField, GetProperty, or SetProperty. You must specify a suitable invocation attribute. For example, to invoke a static member, set the Static flag. </param><param name="binder">An object that enables the binding, coercion of argument types, invocation of members, and retrieval of <see cref="T:System.Reflection.MemberInfo"/> objects through reflection. If <paramref name="binder"/> is null, the default binder is used. </param><param name="index">Optional index values for indexed properties. This value should be null for non-indexed properties. </param><param name="culture">The culture for which the resource is to be localized. If the resource is not localized for this culture, the <see cref="P:System.Globalization.CultureInfo.Parent"/> property will be called successively in search of a match. If this value is null, the culture-specific information is obtained from the <see cref="P:System.Globalization.CultureInfo.CurrentUICulture"/> property. </param><exception cref="T:System.ArgumentException">The <paramref name="index"/> array does not contain the type of arguments needed.-or- The property's set accessor is not found. </exception><exception cref="T:System.Reflection.TargetException">The object does not match the target type, or a property is an instance property but <paramref name="obj"/> is null. </exception><exception cref="T:System.Reflection.TargetParameterCountException">The number of parameters in <paramref name="index"/> does not match the number of parameters the indexed property takes. </exception><exception cref="T:System.MethodAccessException">There was an illegal attempt to access a private or protected method inside a class. </exception><exception cref="T:System.Reflection.TargetInvocationException">An error occurred while setting the property value. For example, an index value specified for an indexed property is out of range. The <see cref="P:System.Exception.InnerException"/> property indicates the reason for the error.</exception>
        public void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
        {
            if (SetMethod == null)
            {
                throw new InvalidOperationException("Property '" + DeclaringType.FullName + "." + Name + "' does not have a setter.");
            }
            var args = Jsni.@new(Jsni.reference("Array"), (1 + (index != null ? index.Length : 0)).As <JsObject>()).As <JsArray>();

//                new object[1 + (index != null ? index.Length : 0)];
            args[0] = value.As <JsObject>();
            for (var i = 1; i < args.length; i++)
            {
                args[i] = index[i - 1].As <JsObject>();
            }
            SetMethod.Invoke(obj, invokeAttr, binder, args.As <object[]>(), culture);
        }