Beispiel #1
0
 public static IJSValueWriter WriteArgs <T1, T2, T3, T4>(this IJSValueWriter writer,
                                                         T1 arg1, T2 arg2, T3 arg3, T4 arg4)
 {
     writer.WriteArrayBegin();
     writer.WriteValue(arg1);
     writer.WriteValue(arg2);
     writer.WriteValue(arg3);
     writer.WriteValue(arg4);
     writer.WriteArrayEnd();
     return(writer);
 }
        public static IJSValueWriter WriteError <T>(this IJSValueWriter writer, T error)
        {
            //TODO: Combine with error writing used for IReactPromise
            var errorMessage = error as string;

            return((errorMessage != null)
       ? writer.WriteArgs(new Dictionary <string, string> {
                ["message"] = errorMessage
            })
       : writer.WriteArgs(error));
        }
Beispiel #3
0
 public static void WriteValue <T>(this IJSValueWriter writer, T?value) where T : struct
 {
     if (value.HasValue)
     {
         writer.WriteValue(value.Value);
     }
     else
     {
         writer.WriteNull();
     }
 }
        // Write JSValueObject key-value pairs to IJSValueWriter.
        public static void WriteObject(IJSValueWriter writer, IEnumerable <KeyValuePair <string, JSValue> > value)
        {
            writer.WriteObjectBegin();
            foreach (var keyValue in value)
            {
                writer.WritePropertyName(keyValue.Key);
                keyValue.Value.WriteTo(writer);
            }

            writer.WriteObjectEnd();
        }
Beispiel #5
0
 public static void WriteValue <T1>(this IJSValueWriter writer, Tuple <T1> value)
 {
     if (value != null)
     {
         writer.WriteArrayBegin();
         writer.WriteValue(value.Item1);
         writer.WriteArrayEnd();
     }
     else
     {
         writer.WriteNull();
     }
 }
Beispiel #6
0
 public static IJSValueWriter WriteArgs <T1, T2, T3, T4, T5, T6, T7>(this IJSValueWriter writer,
                                                                     T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
 {
     writer.WriteArrayBegin();
     writer.WriteValue(arg1);
     writer.WriteValue(arg2);
     writer.WriteValue(arg3);
     writer.WriteValue(arg4);
     writer.WriteValue(arg5);
     writer.WriteValue(arg6);
     writer.WriteValue(arg7);
     writer.WriteArrayEnd();
     return(writer);
 }
 // Writing discriminating union is simpler than reading.
 public static void WriteValue(this IJSValueWriter writer, OneOf2 <T2Extra, R2D2Extra> value)
 {
     writer.WriteObjectBegin();
     if (value.TryGet(out T2Extra t2))
     {
         writer.WriteObjectProperty("Kind", RobotModel.T2);
         writer.WriteObjectProperties(t2);
     }
     else if (value.TryGet(out R2D2Extra r2d2))
     {
         writer.WriteObjectProperty("Kind", RobotModel.R2D2);
         writer.WriteObjectProperties(r2d2);
     }
     writer.WriteObjectEnd();
 }
Beispiel #8
0
 public static void WriteValue <T>(this IJSValueWriter writer, IEnumerable <KeyValuePair <string, T> > value)
 {
     if (value != null)
     {
         writer.WriteObjectBegin();
         foreach (var pair in value)
         {
             writer.WriteObjectProperty(pair.Key, pair.Value);
         }
         writer.WriteObjectEnd();
     }
     else
     {
         writer.WriteNull();
     }
 }
Beispiel #9
0
 public static void WriteValue <T1, T2, T3, T4, T5>(this IJSValueWriter writer, Tuple <T1, T2, T3, T4, T5> value)
 {
     if (value != null)
     {
         writer.WriteArrayBegin();
         writer.WriteValue(value.Item1);
         writer.WriteValue(value.Item2);
         writer.WriteValue(value.Item3);
         writer.WriteValue(value.Item4);
         writer.WriteValue(value.Item5);
         writer.WriteArrayEnd();
     }
     else
     {
         writer.WriteNull();
     }
 }
Beispiel #10
0
        public static void WriteValue <T>(this IJSValueWriter writer, IEnumerable <T> value)
        {
            if (value != null)
            {
                writer.WriteArrayBegin();
                foreach (var item in value)
                {
                    writer.WriteValue(item);
                }

                writer.WriteArrayEnd();
            }
            else
            {
                writer.WriteNull();
            }
        }
Beispiel #11
0
        public void WriteTo(IJSValueWriter writer)
        {
            switch (Type)
            {
            case JSValueType.Null: writer.WriteNull(); break;

            case JSValueType.Object: WriteObject(writer, Object); break;

            case JSValueType.Array: WriteArray(writer, Array); break;

            case JSValueType.String: writer.WriteString(String); break;

            case JSValueType.Boolean: writer.WriteBoolean(Boolean); break;

            case JSValueType.Int64: writer.WriteInt64(Int64); break;

            case JSValueType.Double: writer.WriteDouble(Double); break;
            }
        }
Beispiel #12
0
        public static void WriteError(
            IJSValueWriter writer,
            string code,
            string message,
            IReadOnlyDictionary <string, JSValue> userInfo,
            string stackTrace)
        {
            writer.WriteArrayBegin();
            {
                writer.WriteObjectBegin();
                {
                    writer.WritePropertyName(ReactErrorConstants.Code);
                    writer.WriteString(code ?? ReactErrorConstants.DefaultCode);

                    writer.WritePropertyName(ReactErrorConstants.Message);
                    writer.WriteString(message ?? ReactErrorConstants.DefaultMessage);

                    // For consistency with iOS ensure userInfo key exists, even if we null it.
                    // iOS: /React/Base/RCTUtils.m -> RCTJSErrorFromCodeMessageAndNSError
                    writer.WritePropertyName(ReactErrorConstants.UserInfo);
                    if (userInfo == null)
                    {
                        writer.WriteNull();
                    }
                    else
                    {
                        writer.WriteValue(userInfo);
                    }

                    // Attach a nativeStackWindows string if an exception was passed.
                    // This matches iOS behavior - iOS adds a `nativeStackIOS` property
                    // iOS: /React/Base/RCTUtils.m -> RCTJSErrorFromCodeMessageAndNSError
                    writer.WritePropertyName(ReactErrorConstants.NativeStack);
                    writer.WriteString(stackTrace ?? string.Empty);
                }
                writer.WriteObjectEnd();
            }
            writer.WriteArrayEnd();
        }
Beispiel #13
0
 /// <summary>
 /// Connects the given task to the React Native Module resolve and reject methods.
 /// </summary>
 /// <remarks>
 /// The callback will be scheduled using the default task scheduling using the default continuation
 /// options
 /// </remarks>
 public static Task ContinueWith <T>(this Task <T> task, IJSValueWriter writer, MethodResultCallback resolve,
                                     MethodResultCallback reject)
 {
     return(task.ContinueWith(t =>
     {
         if (t.IsCompletedSuccessfully)
         {
             if (resolve != null)
             {
                 writer.WriteArgs(t.Result);
                 resolve(writer);
             }
         }
         else
         {
             if (reject != null)
             {
                 var exception = t.Exception.Flatten();
                 WriteReject(writer, exception);
                 reject(writer);
             }
         }
     }));
 }
 // Writing RobotInfo value. It could be generated instead.
 public static void WriteValue(this IJSValueWriter writer, RobotInfo value)
 {
     if (value != null)
     {
         writer.WriteObjectBegin();
         writer.WriteObjectProperty(nameof(value.Model), value.Model);
         writer.WriteObjectProperty(nameof(value.Name), value.Name);
         writer.WriteObjectProperty(nameof(value.Age), value.Age);
         writer.WriteObjectProperty(nameof(value.Shape), value.Shape);
         writer.WriteObjectProperty(nameof(value.Shape2), value.Shape2);
         writer.WriteObjectProperty(nameof(value.Shape3), value.Shape3);
         writer.WriteObjectProperty(nameof(value.Steps), value.Steps);
         writer.WriteObjectProperty(nameof(value.Dimensions), value.Dimensions);
         writer.WriteObjectProperty(nameof(value.Badges), value.Badges);
         writer.WriteObjectProperty(nameof(value.Tools), value.Tools);
         writer.WriteObjectProperty(nameof(value.Path), value.Path);
         writer.WriteObjectProperty(nameof(value.Extra), value.Extra);
         writer.WriteObjectEnd();
     }
     else
     {
         writer.WriteNull();
     }
 }
 // Writing RobotModel enum value. It could be generated instead.
 public static void WriteValue(this IJSValueWriter writer, RobotModel value)
 {
     writer.WriteValue((int)value);
 }
Beispiel #16
0
 private void Clear()
 {
     m_resolve = null;
     m_reject  = null;
     m_writer  = null;
 }
Beispiel #17
0
 public static void WriteValue <T>(this IJSValueWriter writer, T[] value)
 {
     writer.WriteValue(value as IEnumerable <T>);
 }
Beispiel #18
0
 public static void WriteValue(this IJSValueWriter writer, ICollection <KeyValuePair <string, JSValue> > value)
 {
     JSValue.WriteObject(writer, value);
 }
Beispiel #19
0
 public ReactPromise(IJSValueWriter writer, MethodResultCallback resolve, MethodResultCallback reject)
 {
     m_writer  = writer;
     m_resolve = resolve;
     m_reject  = reject;
 }
Beispiel #20
0
 public static void WriteValue(this IJSValueWriter writer, JSValue.Void _)
 {
     writer.WriteNull();
 }
Beispiel #21
0
 public static void WriteValue(this IJSValueWriter writer, IDictionary <string, JSValue> value)
 {
     JSValue.WriteObject(writer, value);
 }
Beispiel #22
0
 public static void WriteValue(this IJSValueWriter writer, JSValue value)
 {
     value.WriteTo(writer);
 }
Beispiel #23
0
 public static void WriteValue(this IJSValueWriter writer, double value)
 {
     writer.WriteDouble(value);
 }
Beispiel #24
0
 public static void WriteValue <T>(this IJSValueWriter writer, T value)
 {
     JSValueWriterOf <T> .WriteValue(writer, value);
 }
Beispiel #25
0
 public static void WriteObjectProperty <T>(this IJSValueWriter writer, string name, T value)
 {
     writer.WritePropertyName(name);
     writer.WriteValue(value);
 }
Beispiel #26
0
 public static IJSValueWriter WriteArgs(this IJSValueWriter writer)
 {
     writer.WriteArrayBegin();
     writer.WriteArrayEnd();
     return(writer);
 }
        private bool TryMakeDirectEvent(ViewManagerExportedDirectEventTypeConstantAttribute attribute, MemberInfo memberInfo, Type memberType, IJSValueWriter constantWriter, out Delegate memberValue)
        {
            if (null != attribute && null != memberInfo && TryGetEventDataType(memberType, out Type eventDataType))
            {
                var eventName    = attribute.EventName ?? "top" + memberInfo.Name;
                var callbackName = attribute.CallbackName ?? "on" + memberInfo.Name;

                constantWriter.WritePropertyName(eventName);
                constantWriter.WriteObjectBegin();
                constantWriter.WriteObjectProperty("registrationName", callbackName);
                constantWriter.WriteObjectEnd();

                memberValue = MakeEventDelegate(eventName, memberType, eventDataType);

                return(true);
            }

            memberValue = default(Delegate);

            return(false);
        }
Beispiel #28
0
 public static void WriteValue(this IJSValueWriter writer, uint value)
 {
     writer.WriteInt64(value);
 }
 public ReactConstantProvider(IJSValueWriter writer)
 {
     m_writer = writer;
 }
Beispiel #30
0
 public static void WriteValue(this IJSValueWriter writer, ulong value)
 {
     writer.WriteInt64((long)value);
 }