Пример #1
0
            /// <summary>
            /// Gets a mapped property or field value using reflection.
            /// </summary>
            /// <param name="serializer"></param>
            /// <param name="instance"></param>
            /// <param name="propertyOrField"></param>
            /// <returns></returns>
            private static IASValue GetMappedPropertyOrField(IActionScriptSerializer serializer, object instance, MemberInfo propertyOrField)
            {
                try
                {
                    // Try to get the property.
                    PropertyInfo property = propertyOrField as PropertyInfo;
                    if (property != null)
                    {
                        object   propertyValue       = property.GetValue(instance, null);
                        IASValue mappedPropertyValue = serializer.ToASValue(propertyValue);
                        return(mappedPropertyValue);
                    }

                    // Oh, it must be a field then.
                    FieldInfo field            = (FieldInfo)propertyOrField;
                    object    fieldValue       = field.GetValue(instance);
                    IASValue  mappedFieldValue = serializer.ToASValue(fieldValue);
                    return(mappedFieldValue);
                }
                catch (Exception ex)
                {
                    throw new ActionScriptException(String.Format(CultureInfo.CurrentCulture,
                                                                  "Error while getting value of property or field named '{0}' on class '{1}'",
                                                                  propertyOrField.Name, propertyOrField.ReflectedType.FullName), ex);
                }
            }
Пример #2
0
 private static IEnumerable <IASValue> GetIndexedValues(IActionScriptSerializer serializer, ICollection <T> collection)
 {
     foreach (T element in collection)
     {
         yield return(serializer.ToASValue(element));
     }
 }
Пример #3
0
 private static IEnumerable <IASValue> GetIndexedValues(IActionScriptSerializer serializer, T[] array)
 {
     foreach (T element in array)
     {
         yield return(serializer.ToASValue(element));
     }
 }
Пример #4
0
 private static IEnumerable <KeyValuePair <string, IASValue> > GetDynamicProperties(IActionScriptSerializer serializer, IDictionary <TKey, TValue> dict)
 {
     foreach (KeyValuePair <TKey, TValue> pair in dict)
     {
         string   key   = pair.Key.ToString();
         IASValue value = serializer.ToASValue(pair.Value);
         yield return(new KeyValuePair <string, IASValue>(key, value));
     }
 }
Пример #5
0
        private byte[] ToAMF(object nativeValue)
        {
            IActionScriptSerializer serializer = serializerFactory.CreateSerializer();
            IASValue      asValue    = serializer.ToASValue(nativeValue);
            MemoryStream  stream     = new MemoryStream();
            AMFDataOutput dataOutput = new AMFDataOutput(stream, serializer);

            dataOutput.ObjectEncoding = AMFObjectEncoding.AMF3;
            dataOutput.BeginObjectStream();
            dataOutput.WriteObject(asValue);
            dataOutput.EndObjectStream();

            return(stream.ToArray());
        }
Пример #6
0
 protected IASValue ToASValue(object nativeValue)
 {
     return(serializer.ToASValue(nativeValue));
 }
Пример #7
0
            /// <summary>
            /// Gets a mapped property or field value using reflection.
            /// </summary>
            /// <param name="serializer"></param>
            /// <param name="instance"></param>
            /// <param name="propertyOrField"></param>
            /// <returns></returns>
            private static IASValue GetMappedPropertyOrField(IActionScriptSerializer serializer, object instance, MemberInfo propertyOrField)
            {
                try
                {
                    // Try to get the property.
                    PropertyInfo property = propertyOrField as PropertyInfo;
                    if (property != null)
                    {
                        object propertyValue = property.GetValue(instance, null);
                        IASValue mappedPropertyValue = serializer.ToASValue(propertyValue);
                        return mappedPropertyValue;
                    }

                    // Oh, it must be a field then.
                    FieldInfo field = (FieldInfo)propertyOrField;
                    object fieldValue = field.GetValue(instance);
                    IASValue mappedFieldValue = serializer.ToASValue(fieldValue);
                    return mappedFieldValue;
                }
                catch (Exception ex)
                {
                    throw new ActionScriptException(String.Format(CultureInfo.CurrentCulture,
                        "Error while getting value of property or field named '{0}' on class '{1}'",
                        propertyOrField.Name, propertyOrField.ReflectedType.FullName), ex);
                }
            }