Esempio n. 1
0
            private IEnumerable <KeyValuePair <string, IASValue> > GetMappedDynamicProperties(IActionScriptSerializer serializer, object instance)
            {
                foreach (ActionScriptPropertyMapping mapping in dynamicPropertyMappings)
                {
                    yield return(new KeyValuePair <string, IASValue>(mapping.ASPropertyName,
                                                                     GetMappedPropertyOrField(serializer, instance, mapping.NativePropertyOrField)));
                }

                IDynamic dynamic = instance as IDynamic;

                if (dynamic != null)
                {
                    // This somewhat contorted bit of code serves to catch and report
                    // failures while getting dynamic properties from a class in a somewhat
                    // more default fashion than would be possible using a plain foreach loop
                    // because yield return cannot be used inside a try/catch.
                    IEnumerator <KeyValuePair <string, IASValue> > en;
                    try
                    {
                        en = dynamic.GetDynamicProperties(serializer).GetEnumerator();
                    }
                    catch (Exception ex)
                    {
                        throw new ActionScriptException(String.Format(CultureInfo.CurrentCulture,
                                                                      "Error while getting values of dynamic properties from class '{0}'",
                                                                      dynamic.GetType().FullName), ex);
                    }

                    for (; ;)
                    {
                        KeyValuePair <string, IASValue> pair;
                        try
                        {
                            if (!en.MoveNext())
                            {
                                break;
                            }
                            pair = en.Current;
                        }
                        catch (Exception ex)
                        {
                            throw new ActionScriptException(String.Format(CultureInfo.CurrentCulture,
                                                                          "Error while getting values of dynamic properties from class '{0}'",
                                                                          dynamic.GetType().FullName), ex);
                        }

                        yield return(pair);
                    }
                }
            }
Esempio n. 2
0
 private static void SetDynamicProperty(IDynamic dynamic, IActionScriptSerializer serializer,
                                        string propertyName, IASValue value)
 {
     try
     {
         dynamic.SetDynamicProperty(serializer, propertyName, value);
     }
     catch (Exception ex)
     {
         throw new ActionScriptException(String.Format(CultureInfo.CurrentCulture,
                                                       "Error while setting value of dynamic property '{0}' on class '{1}'",
                                                       propertyName, dynamic.GetType().FullName), ex);
     }
 }
 private static void SetDynamicProperty(IDynamic dynamic, IActionScriptSerializer serializer,
     string propertyName, IASValue value)
 {
     try
     {
         dynamic.SetDynamicProperty(serializer, propertyName, value);
     }
     catch (Exception ex)
     {
         throw new ActionScriptException(String.Format(CultureInfo.CurrentCulture,
             "Error while setting value of dynamic property '{0}' on class '{1}'",
             propertyName, dynamic.GetType().FullName), ex);
     }
 }