public void NullDMO()
        {
            BinaryOperationBinder binder = Binder.BinaryOperation(
                CSharpBinderFlags.None,
                ExpressionType.Add,
                GetType(),
                new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }
                ) as BinaryOperationBinder;
            DynamicMetaObject dmo2     = new DynamicMetaObject(Expression.Parameter(typeof(object)), BindingRestrictions.Empty, 2);
            DynamicMetaObject dmoNoVal = new DynamicMetaObject(Expression.Parameter(typeof(object)), BindingRestrictions.Empty);

            AssertExtensions.Throws <ArgumentNullException>("target", () => binder.FallbackBinaryOperation(null, null));
            AssertExtensions.Throws <ArgumentNullException>("arg", () => binder.FallbackBinaryOperation(dmo2, null));
            AssertExtensions.Throws <ArgumentException>("target", () => binder.FallbackBinaryOperation(dmoNoVal, null));
            AssertExtensions.Throws <ArgumentException>("arg", () => binder.FallbackBinaryOperation(dmo2, dmoNoVal));
        }
Exemple #2
0
        /// <summary>
        /// Creates the action for a dynamic object.
        /// </summary>
        /// <param name="provider">The dynamic object.</param>
        protected virtual Delegate CreateActionForDynamic(IDynamicMetaObjectProvider provider)
        {
            // http://stackoverflow.com/a/14011692/68499

            var type = provider.GetType();
            var parameterExpression = Expression.Parameter(typeof(object), "record");

            var metaObject    = provider.GetMetaObject(parameterExpression);
            var propertyNames = metaObject.GetDynamicMemberNames();

            var delegates = new List <Delegate>();

            foreach (var propertyName in propertyNames)
            {
                var getMemberBinder     = (GetMemberBinder)Microsoft.CSharp.RuntimeBinder.Binder.GetMember(0, propertyName, type, new[] { CSharpArgumentInfo.Create(0, null) });
                var getMemberMetaObject = metaObject.BindGetMember(getMemberBinder);
                var fieldExpression     = getMemberMetaObject.Expression;
                fieldExpression = Expression.Call(Expression.Constant(this), "WriteField", new[] { typeof(object) }, fieldExpression);
                fieldExpression = Expression.Block(fieldExpression, Expression.Label(CallSiteBinder.UpdateLabel));
                var lambda = Expression.Lambda(fieldExpression, parameterExpression);
                delegates.Add(lambda.Compile());
            }

            var action = CombineDelegates(delegates);

            typeActions[type] = action;

            return(action);
        }
Exemple #3
0
 private void ensureInvokerVoid()
 {
     if (this.invoker_v == null)
     {
         this.invoker_v = CallSite <Func <CallSite, object, object> > .Create(Binder.InvokeMember(CSharpBinderFlags.ResultDiscarded, this.method, null, typeof(jxshell.dotnet4.invoker), (IEnumerable <CSharpArgumentInfo>)(new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) })));
     }
 }
        public ActionResult Body(FormCollection collection)
        {
            RoadFlow.Platform.Dictionary   dictionary = new RoadFlow.Platform.Dictionary();
            RoadFlow.Data.Model.Dictionary model      = (RoadFlow.Data.Model.Dictionary)null;
            string str1 = this.Request.QueryString["id"];

            if (str1.IsGuid())
            {
                model = dictionary.Get(str1.ToGuid(), false);
            }
            if (model == null)
            {
                model = dictionary.GetRoot();
            }
            if (collection != null)
            {
                Guid   guid;
                string str2;
                if (!(model.ParentID == Guid.Empty))
                {
                    guid = model.ParentID;
                    str2 = guid.ToString();
                }
                else
                {
                    guid = model.ID;
                    str2 = guid.ToString();
                }
                string str3 = str2;
                if (!this.Request.Form["Delete"].IsNullOrEmpty())
                {
                    int num = dictionary.DeleteAndAllChilds(model.ID);
                    dictionary.RefreshCache();
                    RoadFlow.Platform.Log.Add("删除了数据字典及其下级共" + num.ToString() + "项", model.Serialize(), RoadFlow.Platform.Log.Types.数据字典, "", "", (RoadFlow.Data.Model.Users)null);
                    // ISSUE: reference to a compiler-generated field
                    if (DictController.\u003C\u003Eo__5.\u003C\u003Ep__0 == null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        DictController.\u003C\u003Eo__5.\u003C\u003Ep__0 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "Script", typeof(DictController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                        {
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                        }));
                    }
                    // ISSUE: reference to a compiler-generated field
                    Func <CallSite, object, string, object> target = DictController.\u003C\u003Eo__5.\u003C\u003Ep__0.Target;
                    // ISSUE: reference to a compiler-generated field
                    CallSite <Func <CallSite, object, string, object> > p0 = DictController.\u003C\u003Eo__5.\u003C\u003Ep__0;
                    object   viewBag  = this.ViewBag;
                    string[] strArray = new string[7] {
                        "alert('删除成功!');parent.frames[0].reLoad('", str3, "');window.location='Body?id=", null, null, null, null
                    };
                    int index = 3;
                    guid = model.ParentID;
                    string str4 = guid.ToString();
                    strArray[index] = str4;
                    strArray[4]     = "&appid=";
                    strArray[5]     = this.Request.QueryString["appid"];
                    strArray[6]     = "';";
                    string str5 = string.Concat(strArray);
                    object obj  = target((CallSite)p0, viewBag, str5);
                    return((ActionResult)this.View((object)model));
                }
                string str6   = this.Request.Form["Title"];
                string str7   = this.Request.Form["Code"];
                string str8   = this.Request.Form["Values"];
                string str9   = this.Request.Form["Note"];
                string str10  = this.Request.Form["Other"];
                string oldXML = model.Serialize();
                model.Code  = str7.IsNullOrEmpty() ? (string)null : str7.Trim();
                model.Note  = str9.IsNullOrEmpty() ? (string)null : str9.Trim();
                model.Other = str10.IsNullOrEmpty() ? (string)null : str10.Trim();
                model.Title = str6.Trim();
                model.Value = str8.IsNullOrEmpty() ? (string)null : str8.Trim();
                dictionary.Update(model);
                dictionary.RefreshCache();
                RoadFlow.Platform.Log.Add("修改了数据字典项", "", RoadFlow.Platform.Log.Types.数据字典, oldXML, model.Serialize(), (RoadFlow.Data.Model.Users)null);
                // ISSUE: reference to a compiler-generated field
                if (DictController.\u003C\u003Eo__5.\u003C\u003Ep__1 == null)
                {
                    // ISSUE: reference to a compiler-generated field
                    DictController.\u003C\u003Eo__5.\u003C\u003Ep__1 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "Script", typeof(DictController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                    {
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                    }));
                }
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                object obj1 = DictController.\u003C\u003Eo__5.\u003C\u003Ep__1.Target((CallSite)DictController.\u003C\u003Eo__5.\u003C\u003Ep__1, this.ViewBag, "alert('保存成功!');parent.frames[0].reLoad('" + str3 + "');");
            }
            return((ActionResult)this.View((object)model));
        }
        public T GetNestedValueOrDefault <T>(string nestedProperty, T def)
        {
            if (!string.IsNullOrEmpty(nestedProperty) && !nestedProperty.Contains('.'))
            {
                return(GetValueOrDefault <T>(nestedProperty, def));
            }

            string[]      properties = nestedProperty.Split('.');
            DynamicObject iterative  = _dynamicObj;
            object        rersult    = null;

            foreach (string prop in properties)
            {
                try
                {
                    if (prop.Contains("[") && prop.Contains("]"))
                    {
                        string cleanProp = prop.Replace("[", string.Empty).Replace("]", string.Empty);
                        if (string.IsNullOrEmpty(cleanProp))
                        {
                            rersult = iterative.ToString();
                            break;
                        }

                        CallSiteBinder binder = Binder.GetIndex(CSharpBinderFlags.None, typeof(DynamicActivityBase), new[] {
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null),
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
                        });

                        int index = -1;
                        if (int.TryParse(cleanProp, out index))
                        {
                            if (!iterative.TryGetIndex(binder as GetIndexBinder, new object[] { index }, out rersult))
                            {
                                throw new ArgumentException(string.Format("Exception while accessing indexed property {0} of {1} path.", prop, nestedProperty));
                            }
                        }
                        else if (!iterative.TryGetIndex(binder as GetIndexBinder, new object[] { cleanProp }, out rersult))
                        {
                            throw new ArgumentException(string.Format("Exception while accessing indexed property {0} of {1} path.", prop, nestedProperty));
                        }
                    }
                    else
                    {
                        CallSiteBinder binder = Binder.GetMember(CSharpBinderFlags.None, prop, typeof(DynamicActivityBase), new[] {
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null)
                        });

                        if (!iterative.TryGetMember(binder as GetMemberBinder, out rersult))
                        {
                            throw new ArgumentException(string.Format("Exception while accessing indexed property {0} of {1} path.", prop, nestedProperty));
                        }
                    }

                    if (rersult is DynamicObject)
                    {
                        iterative = rersult as DynamicObject;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }

            return((T)rersult);
        }
 public bool Checkout()
 {
     try
     {
         this._task.Status = States.GetTaskState(States.TaskState.REGISTERING);
         States.WriteLogger(this._task, States.LOGGER_STATES.REGISTERING, null, "", "");
         bool flag = true;
         while (flag)
         {
             flag = false;
             try
             {
                 this._srr = this._client.Get((this._task.SupremeRegion == TaskObject.SupremeRegionEnum.EU) ? "https://london.supremenewyork.com" : "https://register.supremenewyork.com").Text();
                 continue;
             }
             catch (WebException exception)
             {
                 if (!exception.Message.Contains("504") && !exception.Message.Contains("503"))
                 {
                     throw;
                 }
                 flag = true;
                 States.WriteLogger(this._task, States.LOGGER_STATES.CRASH_DETECTED, null, "", "1");
                 Thread.Sleep(0x3e8);
                 continue;
             }
         }
         if (this._srr.Contains("Registration has closed for this release"))
         {
             goto Label_1AC4;
         }
         this._currentDoc.LoadHtml(this._srr);
         string        str          = this._currentDoc.DocumentNode.Descendants("input").First <HtmlNode>(x => ((x.Attributes["name"] != null) && (x.Attributes["name"].Value == "authenticity_token"))).Attributes["value"].Value;
         string        str2         = this._currentDoc.DocumentNode.Descendants("meta").First <HtmlNode>(x => ((x.Attributes["name"] != null) && (x.Attributes["name"].Value == "csrf-token"))).Attributes["content"].Value;
         ProfileObject profile      = this._runner.Profile;
         object        solverLocker = Global.SolverLocker;
         lock (solverLocker)
         {
             Global.CAPTCHA_QUEUE.Add(this._task);
         }
         this._task.Status = States.GetTaskState(States.TaskState.WAITING_FOR_CATPCHA);
         States.WriteLogger(this._task, States.LOGGER_STATES.WAITING_FOR_CAPTCHA, null, "", "");
         this._task.Mre = new ManualResetEvent(false);
         CaptchaWaiter waiter = new CaptchaWaiter(this._task, new DateTime?(DateTime.Now), WebsitesInfo.SUPREME_CAPTCHA_KEY, "https://www.supremenewyork.com", "Supreme");
         waiter.Start();
         this._task.Mre.WaitOne();
         if (Global.CAPTCHA_QUEUE.Any <TaskObject>(x => x.Id == this._task.Id))
         {
             solverLocker = Global.SolverLocker;
             lock (solverLocker)
             {
                 Global.CAPTCHA_QUEUE.Remove(Global.CAPTCHA_QUEUE.First <TaskObject>(x => x.Id == this._task.Id));
                 this._task.ManualSolved = false;
             }
         }
         string str3     = "";
         string cCNumber = profile.CCNumber;
         while (cCNumber.Length > 4)
         {
             str3     = str3 + cCNumber.Substring(0, 4);
             cCNumber = cCNumber.Remove(0, 4);
             str3     = str3 + " ";
         }
         str3 = str3 + cCNumber;
         this._diData.Clear();
         this._diData.Add("utf8", "✓");
         this._diData.Add("authenticity_token", str);
         this._diData.Add("customer[name]", profile.FirstName + " " + profile.LastName);
         this._diData.Add("customer[email]", profile.Email);
         this._diData.Add("customer[tel]", profile.Phone);
         if (this._task.SupremeRegion == TaskObject.SupremeRegionEnum.USA)
         {
             this._diData.Add("customer[location_preference]", this._task.VariousStringData);
         }
         this._diData.Add("customer[street]", profile.Address1);
         this._diData.Add("customer[street_2]", profile.Address2);
         this._diData.Add("customer[zip]", profile.Zip);
         this._diData.Add("customer[city]", profile.City);
         if (this._task.SupremeRegion == TaskObject.SupremeRegionEnum.USA)
         {
             this._diData.Add("customer[state]", profile.StateId);
         }
         this._diData.Add("credit_card[cn]", str3);
         this._diData.Add("credit_card[month]", int.Parse(profile.ExpiryMonth).ToString());
         this._diData.Add("credit_card[year]", profile.ExpiryYear);
         this._diData.Add("credit_card[verification_value]", profile.Cvv);
         this._diData.Add("g-recaptcha-response", waiter.Token);
         if (this._runner.Profile.OnePerWebsite && Global.SUCCESS_PROFILES.Any <KeyValuePair <string, string> >(x => ((x.Key == this._task.CheckoutId) && (x.Value == this._runner.HomeUrl))))
         {
             this._task.Status = States.GetTaskState(States.TaskState.PROFILE_USED);
             States.WriteLogger(this._task, States.LOGGER_STATES.PROFILE_ALREADY_USED, null, "", "");
             return(false);
         }
         if (this._task.CheckoutDelay > 0)
         {
             Thread.Sleep(this._task.CheckoutDelay);
         }
         this._task.Status = States.GetTaskState(States.TaskState.SUBMITTING_REGISTRATION);
         States.WriteLogger(this._task, States.LOGGER_STATES.SUBMITTING_REGISTRATION, null, "", "");
         try
         {
             if ((this._runner._watch != null) && this._runner._watch.IsRunning)
             {
                 this._runner._watch.Stop();
             }
         }
         catch
         {
         }
         flag = true;
         while (flag)
         {
             flag = false;
             try
             {
                 this._client.Session.DefaultRequestHeaders.TryAddWithoutValidation("X-CSRF-Token", str2);
                 this._client.Session.DefaultRequestHeaders.Referrer = new Uri((this._task.SupremeRegion == TaskObject.SupremeRegionEnum.EU) ? "https://london.supremenewyork.com/signup/2" : "https://register.supremenewyork.com/signup/2");
                 this._client.Session.DefaultRequestHeaders.TryAddWithoutValidation("Origin", (this._task.SupremeRegion == TaskObject.SupremeRegionEnum.EU) ? "https://london.supremenewyork.com" : "https://register.supremenewyork.com");
                 this._srr = this._client.Post((this._task.SupremeRegion == TaskObject.SupremeRegionEnum.EU) ? "https://london.supremenewyork.com/customers" : "https://register.supremenewyork.com/customers", this._diData).Text();
                 continue;
             }
             catch (WebException exception2)
             {
                 if (!exception2.Message.Contains("504") && !exception2.Message.Contains("503"))
                 {
                     throw;
                 }
                 flag = true;
                 States.WriteLogger(this._task, States.LOGGER_STATES.CRASH_DETECTED, null, "", "1");
                 Thread.Sleep(0x3e8);
                 continue;
             }
         }
         if (this._srr.Contains("Registration has closed for this release"))
         {
             goto Label_1A92;
         }
         Global.Logger.Info("SupremeInstore: " + this._srr);
         this._dynObj = Newtonsoft.Json.JsonConvert.DeserializeObject(this._srr);
         string str5 = "";
         if (< > o__10.< > p__3 == null)
         {
             CSharpArgumentInfo[] argumentInfo = new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
             < > o__10.< > p__3 = CallSite <Func <CallSite, object, bool> > .Create(Binder.UnaryOperation(CSharpBinderFlags.None, ExpressionType.IsTrue, typeof(SupremeInstore), argumentInfo));
         }
Exemple #7
0
 private void ensureInvokerP()
 {
     if (this.invoker_p == null)
     {
         this.invoker_p = CallSite <Func <CallSite, object, object, object, object, object, object, object, object, object, object, object, object> > .Create(Binder.SetIndex(CSharpBinderFlags.None, typeof(jxshell.dotnet4.invoker), (IEnumerable <CSharpArgumentInfo>)(new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) })));
     }
 }
Exemple #8
0
 private static CSharpArgumentInfo CreateStaticTypeArgInfo()
 {
     return(CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.IsStaticType, null));
 }
Exemple #9
0
        /// <summary>
        /// Gets the demanded value from the given object
        /// </summary>
        /// <param name="source">the source object from which to get the desired value</param>
        /// <param name="propertyPath">the path to the Property to read from the object</param>
        /// <returns>the value of the given property</returns>
        private static object GetObject(object source, string propertyPath)
        {
            string[] path   = TokenizePath(propertyPath);
            object   retVal = source;

            foreach (string propertyName in path)
            {
                object ret = null;
                if (retVal is IDictionary)
                {
                    IDictionary tmp = (IDictionary)retVal;
                    if (tmp.Contains(propertyName))
                    {
                        ret = tmp[propertyName];
                    }
                }
                else if (retVal is IDictionary <string, object> )
                {
                    IDictionary <string, object> tmp = (IDictionary <string, object>)retVal;
                    if (tmp.ContainsKey(propertyName))
                    {
                        ret = tmp[propertyName];
                    }
                    else
                    {
                        LogEnvironment.LogDebugEvent(null, string.Format("Property {0} is unknown", propertyName), (int)LogSeverity.Warning, null);
                    }
                }
                else if (retVal is IBasicKeyValueProvider)
                {
                    IBasicKeyValueProvider tmp = (IBasicKeyValueProvider)retVal;
                    ret = tmp[propertyName];
                }
                else if (retVal is IDataReader)
                {
                    IDataReader tmp = (IDataReader)retVal;
                    for (int i = 0; i < tmp.FieldCount; i++)
                    {
                        if (tmp.GetName(i).Equals(propertyName, StringComparison.OrdinalIgnoreCase))
                        {
                            ret = tmp[i];
                            break;
                        }
                    }
                }
                else if (retVal is DataRow)
                {
                    DataRow tmp = (DataRow)retVal;
                    if (tmp.Table != null && tmp.Table.Columns.IndexOf(propertyName) != -1)
                    {
                        ret = tmp[propertyName];
                    }
                }
                else if (retVal is DynamicObject)
                {
                    try
                    {
                        var binder = Binder.GetMember(CSharpBinderFlags.None, propertyName, retVal.GetType(),
                                                      new[]
                        {
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
                        });
                        var callsite = CallSite <Func <CallSite, object, object> > .Create(binder);

                        ret = callsite.Target(callsite, retVal);
                    }
                    catch (Exception ex)
                    {
                        LogEnvironment.LogDebugEvent(null, ex.ToString(), (int)LogSeverity.Error, null);
                        throw;
                    }
                }

                if (ret == null && retVal != null)
                {
                    Type         t    = retVal.GetType();
                    PropertyInfo info = t.GetProperty(propertyName,
                                                      BindingFlags.FlattenHierarchy | BindingFlags.GetProperty |
                                                      BindingFlags.IgnoreCase |
                                                      BindingFlags.Instance | BindingFlags.Public);
                    if (info != null)
                    {
                        try
                        {
                            ret = info.GetValue(retVal, null);
                        }
                        catch (Exception ex)
                        {
                            ret = null;
                        }
                    }
                    else if (propertyName == ".")
                    {
                        ret = retVal;
                    }
                    else
                    {
                        FieldInfo f = t.GetField(propertyName);
                        if (f != null)
                        {
                            ret = f.GetValue(retVal);
                        }
                    }
                }

                retVal = ret;
                if (retVal == null)
                {
                    break;
                }
            }

            return(retVal);
        }
Exemple #10
0
        internal MSAst GetMember(MSAst target, string memberName)
        {
            var binder = Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, memberName, null, new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });

            return(MSAst.Dynamic(binder, typeof(object), target));
        }
Exemple #11
0
        public ActionResult CustomForm(FormCollection coll)
        {
            string str1 = this.Request.QueryString["instanceid"];

            if (coll != null)
            {
                string str2  = this.Request.Form["Title"];
                string str3  = this.Request.Form["Contents"];
                string empty = string.Empty;
                int    num   = new DBHelper().Execute(str1.IsNullOrEmpty() ? "insert into TempTest_CustomForm(Title,Contents) values(@Title,@Contents)" : "update TempTest_CustomForm set Title=@Title,Contents=@Contents where id=" + str1, new SqlParameter[2] {
                    new SqlParameter("@Title", (object)str2), new SqlParameter("@Contents", (object)str3)
                }, true);
                // ISSUE: reference to a compiler-generated field
                if (TestController.\u003C\u003Eo__2.\u003C\u003Ep__0 == null)
                {
                    // ISSUE: reference to a compiler-generated field
                    TestController.\u003C\u003Eo__2.\u003C\u003Ep__0 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "title1", typeof(TestController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                    {
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                    }));
                }
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                object obj1 = TestController.\u003C\u003Eo__2.\u003C\u003Ep__0.Target((CallSite)TestController.\u003C\u003Eo__2.\u003C\u003Ep__0, this.ViewBag, str2);
                // ISSUE: reference to a compiler-generated field
                if (TestController.\u003C\u003Eo__2.\u003C\u003Ep__1 == null)
                {
                    // ISSUE: reference to a compiler-generated field
                    TestController.\u003C\u003Eo__2.\u003C\u003Ep__1 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "contents", typeof(TestController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                    {
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                    }));
                }
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                object obj2 = TestController.\u003C\u003Eo__2.\u003C\u003Ep__1.Target((CallSite)TestController.\u003C\u003Eo__2.\u003C\u003Ep__1, this.ViewBag, str3);
                // ISSUE: reference to a compiler-generated field
                if (TestController.\u003C\u003Eo__2.\u003C\u003Ep__2 == null)
                {
                    // ISSUE: reference to a compiler-generated field
                    TestController.\u003C\u003Eo__2.\u003C\u003Ep__2 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "script", typeof(TestController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                    {
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                    }));
                }
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                object obj3 = TestController.\u003C\u003Eo__2.\u003C\u003Ep__2.Target((CallSite)TestController.\u003C\u003Eo__2.\u003C\u003Ep__2, this.ViewBag, "$('#instanceid',parent.document).val('" + (object)num + "');$('#customformtitle',parent.document).val('" + str2 + "');parent.flowSaveAndSendIframe(true);");
            }
            else if (!str1.IsNullOrEmpty())
            {
                DataTable dataTable = new DBHelper().GetDataTable("select * from TempTest_CustomForm where id=" + str1);
                if (dataTable.Rows.Count > 0)
                {
                    // ISSUE: reference to a compiler-generated field
                    if (TestController.\u003C\u003Eo__2.\u003C\u003Ep__3 == null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        TestController.\u003C\u003Eo__2.\u003C\u003Ep__3 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "title1", typeof(TestController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                        {
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                        }));
                    }
                    // ISSUE: reference to a compiler-generated field
                    // ISSUE: reference to a compiler-generated field
                    object obj1 = TestController.\u003C\u003Eo__2.\u003C\u003Ep__3.Target((CallSite)TestController.\u003C\u003Eo__2.\u003C\u003Ep__3, this.ViewBag, dataTable.Rows[0]["Title"].ToString());
                    // ISSUE: reference to a compiler-generated field
                    if (TestController.\u003C\u003Eo__2.\u003C\u003Ep__4 == null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        TestController.\u003C\u003Eo__2.\u003C\u003Ep__4 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "contents", typeof(TestController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                        {
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                        }));
                    }
                    // ISSUE: reference to a compiler-generated field
                    // ISSUE: reference to a compiler-generated field
                    object obj2 = TestController.\u003C\u003Eo__2.\u003C\u003Ep__4.Target((CallSite)TestController.\u003C\u003Eo__2.\u003C\u003Ep__4, this.ViewBag, dataTable.Rows[0]["Contents"].ToString());
                }
            }
            return((ActionResult)this.View());
        }
Exemple #12
0
        internal static void SetValue(string name, object target, object value)
        {
            CallSite <Func <CallSite, object, object, object> > callSite = (CallSite <Func <CallSite, object, object, object> >)setters[name] !;

            if (callSite == null)
            {
                CallSite <Func <CallSite, object, object, object> > newSite = CallSite <Func <CallSite, object, object, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, name, typeof(CallSiteCache), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null) }));

                lock (setters)
                {
                    callSite = (CallSite <Func <CallSite, object, object, object> >)setters[name] !;
                    if (callSite == null)
                    {
                        setters[name] = callSite = newSite;
                    }
                }
            }
            callSite.Target(callSite, target, value);
        }
Exemple #13
0
        internal static object GetValue(string name, object target)
        {
            CallSite <Func <CallSite, object, object> > callSite = (CallSite <Func <CallSite, object, object> >)getters[name] !;

            if (callSite == null)
            {
                CallSite <Func <CallSite, object, object> > newSite = CallSite <Func <CallSite, object, object> > .Create(Binder.GetMember(CSharpBinderFlags.None, name, typeof(CallSiteCache), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }));

                lock (getters)
                {
                    callSite = (CallSite <Func <CallSite, object, object> >)getters[name] !;
                    if (callSite == null)
                    {
                        getters[name] = callSite = newSite;
                    }
                }
            }
            return(callSite.Target(callSite, target));
        }
Exemple #14
0
        // http://www.cnblogs.com/LoveJenny/archive/2011/07/07/2100416.html
        // http://stackoverflow.com/questions/4939508/get-value-of-c-sharp-dynamic-property-via-string
        /// <summary>
        ///
        /// </summary>
        /// <param name="target"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static object GetProperty(object target, string name)
        {
            if (target == null || name == null)
            {
                return(null);
            }

            var site = CallSite <Func <CallSite, object, object> > .Create(Binder.GetMember(0, name, target.GetType(), new[] { CSharpArgumentInfo.Create(0, null) }));

            return(site.Target(site, target));
        }
        internal override Expression GetExpression(List <ParameterExpression> parameters, Dictionary <string, ConstantExpression> locals, List <DataContainer> dataContainers, Type dynamicContext, LabelTarget label)
        {
            ExpressionType type = default(ExpressionType);

            switch (operation)
            {
            case Operator.Positive:
                return(value.GetExpression(parameters, locals, dataContainers, dynamicContext, label));

                break;

            case Operator.Negative:
                type = ExpressionType.Negate;
                break;

            case Operator.Not:
                type = ExpressionType.Not;
                break;
            }
            CallSiteBinder binder = Binder.UnaryOperation(CSharpBinderFlags.None, type, dynamicContext ?? typeof(object), new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });

            return(Expression.Dynamic(binder, typeof(object), value.GetExpression(parameters, locals, dataContainers, dynamicContext, label)));
        }
Exemple #16
0
        private static Accessor GetDynamicObjectAcessor(Type type, string attributeName)
        {
            var getterBinder   = Binder.GetMember(CSharpBinderFlags.None, attributeName, type, new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });
            var callsiteGetter = CallSite <Func <CallSite, object, object> > .Create(getterBinder);

            var setterBinder = Binder.SetMember(CSharpBinderFlags.None, attributeName, type, new[]
            {
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
            });
            var callsiteSetter = CallSite <Func <CallSite, object, object, object> > .Create(setterBinder);

            return(new Accessor
            {
                Setter = (@object, value) => callsiteSetter.Target(callsiteSetter, @object, value),
                Getter = (@object) => callsiteGetter.Target(callsiteGetter, @object)
            });
        }
Exemple #17
0
        static Func <object, object> GetGetMember(Type type, string memberName)
        {
            var key    = Tuple.Create(type, memberName);
            var cached = (Func <object, object>)GetGetMemberCache[key];

            if (cached != null)
            {
                return(cached);
            }

            var binder   = (GetMemberBinder)Microsoft.CSharp.RuntimeBinder.Binder.GetMember(0, memberName, type, new[] { CSharpArgumentInfo.Create(0, null) });
            var callSite = CallSite <Func <CallSite, object, object> > .Create(binder);

            lock (GetGetMemberCache)
            {
                cached = (Func <object, object>)GetGetMemberCache[key];
                if (cached != null)
                {
                    return(cached);
                }

                GetGetMemberCache[key] = cached = (obj => callSite.Target.Invoke(callSite, obj));
            }

            return(cached);
        }
        public static Expression <Func <dynamic, bool> > PropertyGreaterThanPredicate(string propertyName, int value)
        {
            var constant = Expression.Constant(value);

            var parameter = Expression.Parameter(typeof(object), "m");

            // Creating binder to access class member
            var binder = Binder.GetMember(CSharpBinderFlags.None, propertyName, typeof(Program), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });

            // Dynamic operation on the binder
            var dynamic = Expression.Dynamic(binder, typeof(object), parameter);

            // Converting result to same type as value to compare
            var converted = Expression.Convert(dynamic, constant.Value.GetType());

            var predicate = Expression.GreaterThan(converted, constant);

            var lambda = Expression.Lambda <Func <dynamic, bool> >(predicate, parameter);

            return(lambda);
        }
Exemple #19
0
            private static Action <IInvocation> CompileInvoker(MethodInfo method)
            {
                var methodParameters    = method.GetParameters();
                var invocationParameter = Expression.Parameter(typeof(IInvocation), "invocation");

                var targetAndArgumentInfos = Pack(
                    CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                    methodParameters.Select(
                        mp => CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.NamedArgument, mp.Name))).ToArray();

                var targetAndArguments = Pack <Expression>(
                    Expression.Coalesce(
                        Expression.Property(invocationParameter, invocationParameter.Type, "InvocationTarget"),
                        Expression.Property(invocationParameter, invocationParameter.Type, "Proxy")),
                    methodParameters.Select(
                        (mp, index) =>
                        Expression.Convert(
                            Expression.ArrayIndex(
                                Expression.Property(invocationParameter, invocationParameter.Type,
                                                    "Arguments"),
                                Expression.Constant(index)), mp.ParameterType))).ToArray();

                Expression body = null;

                if (method.IsSpecialName)
                {
                    if (method.Name.Equals("get_Item"))
                    {
                        body = Expression.Dynamic(
                            Binder.GetIndex(
                                CSharpBinderFlags.InvokeSpecialName,
                                typeof(object),
                                targetAndArgumentInfos),
                            typeof(object),
                            targetAndArguments);
                    }

                    if (body == null && method.Name.Equals("set_Item"))
                    {
                        var targetAndArgumentInfosWithoutTheNameValue = Pack(
                            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                            methodParameters.Select(
                                mp => mp.Name == "value" ? CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) : CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.NamedArgument, mp.Name)));

                        body = Expression.Dynamic(
                            Binder.SetIndex(
                                CSharpBinderFlags.InvokeSpecialName,
                                typeof(object),
                                targetAndArgumentInfosWithoutTheNameValue),
                            typeof(object),
                            targetAndArguments);
                    }

                    if (body == null && method.Name.StartsWith("get_"))
                    {
                        //  Build lambda containing the following call site:
                        //  (IInvocation invocation) => {
                        //      invocation.ReturnValue = (object) ((dynamic)invocation.InvocationTarget).{method.Name};
                        //  }
                        body = Expression.Dynamic(
                            Binder.GetMember(
                                CSharpBinderFlags.InvokeSpecialName,
                                method.Name.Substring("get_".Length),
                                typeof(object),
                                targetAndArgumentInfos),
                            typeof(object),
                            targetAndArguments);
                    }

                    if (body == null && method.Name.StartsWith("set_"))
                    {
                        body = Expression.Dynamic(
                            Binder.SetMember(
                                CSharpBinderFlags.InvokeSpecialName,
                                method.Name.Substring("set_".Length),
                                typeof(object),
                                targetAndArgumentInfos),
                            typeof(object),
                            targetAndArguments);
                    }
                }
                if (body == null)
                {
                    //  Build lambda containing the following call site:
                    //  (IInvocation invocation) => {
                    //      invocation.ReturnValue = (object) ((dynamic)invocation.InvocationTarget).{method.Name}(
                    //          {methodParameters[*].Name}: ({methodParameters[*].Type})invocation.Arguments[*],
                    //          ...);
                    //  }

                    body = Expression.Dynamic(
                        Binder.InvokeMember(
                            CSharpBinderFlags.None,
                            method.Name,
                            null,
                            typeof(object),
                            targetAndArgumentInfos),
                        typeof(object),
                        targetAndArguments);
                }

                if (method.ReturnType != typeof(void))
                {
                    body = Expression.Assign(
                        Expression.Property(invocationParameter, invocationParameter.Type, "ReturnValue"),
                        Expression.Convert(body, typeof(object)));
                }

                var lambda = Expression.Lambda <Action <IInvocation> >(body, invocationParameter);

                return(lambda.Compile());
            }
        static object GetDynamicMember(object obj, string memberName)
        {
            var binder   = Binder.GetMember(CSharpBinderFlags.None, memberName, null, new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });
            var callsite = CallSite <Func <CallSite, object, object> > .Create(binder);

            return(callsite.Target(callsite, obj));
        }
 public DynamicPropertyInfo(string name, BindingFlags bindingAttr, DynamicTypeDescription dynamictype)
 {
     this.name        = name;
     this.bindingAttr = bindingAttr;
     this.dynamictype = dynamictype;
     this.dbinder     = (GetMemberBinder)Microsoft.CSharp.RuntimeBinder.Binder.GetMember(0, name, TypeOf <DynamicPropertyInfo> .TypeID, new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.Constant, null) });
 }
Exemple #22
0
        private void ensureInvoker()
        {
            if (this.invoker == null)
            {
                if (!this.isProperty)
                {
                    this.invoker = CallSite <Func <CallSite, object, object> > .Create(Binder.InvokeMember(CSharpBinderFlags.None, this.method, null, typeof(jxshell.dotnet4.invoker), (IEnumerable <CSharpArgumentInfo>)(new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) })));

                    return;
                }
                this.invoker = CallSite <Func <CallSite, object, object> > .Create(Binder.GetMember(CSharpBinderFlags.None, this.method, typeof(jxshell.dotnet4.invoker), (IEnumerable <CSharpArgumentInfo>)(new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) })));
            }
        }
        public static CallSite <Func <CallSite, object, object> > GetMemberAccessCallSite(string memberName)
        {
            var binder = Binder.GetMember(CSharpBinderFlags.None, memberName, typeof(DynamicUtils), new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });

            return(GetMemberAccessCallSite(binder));
        }
Exemple #24
0
        private static ValueTypeAccessor CreateGetMethodForValueType(PropertyInfo prop, Type type)
        {
            var binder = Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, prop.Name, type, new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });

            return(new ValueTypeAccessor(CallSite <Func <CallSite, object, object> > .Create(binder)));
        }
        /// <summary>
        /// Builds a <see cref="JsonDeserializer{T}" /> for a <see cref="RecordSchema" />.
        /// </summary>
        /// <returns>
        /// A successful <see cref="JsonDeserializerBuilderCaseResult" /> if <paramref name="type" />
        /// is not an array or primitive type and <paramref name="schema" /> is a <see cref="RecordSchema" />;
        /// an unsuccessful <see cref="JsonDeserializerBuilderCaseResult" /> otherwise.
        /// </returns>
        /// <inheritdoc />
        public virtual JsonDeserializerBuilderCaseResult BuildExpression(Type type, Schema schema, JsonDeserializerBuilderContext context)
        {
            if (schema is RecordSchema recordSchema)
            {
                var underlying = Nullable.GetUnderlyingType(type) ?? type;

                if (!underlying.IsArray && !underlying.IsPrimitive)
                {
                    // since record deserialization is potentially recursive, create a top-level
                    // reference:
                    var parameter = Expression.Parameter(
                        Expression.GetDelegateType(context.Reader.Type.MakeByRefType(), type));

                    if (!context.References.TryGetValue((recordSchema, type), out var reference))
                    {
                        context.References.Add((recordSchema, type), reference = parameter);
                    }

                    // then build/set the delegate if it hasn’t been built yet:
                    if (parameter == reference)
                    {
                        Expression expression;

                        var loop = Expression.Label();

                        var tokenType = typeof(Utf8JsonReader)
                                        .GetProperty(nameof(Utf8JsonReader.TokenType));

                        var getUnexpectedTokenException = typeof(JsonExceptionHelper)
                                                          .GetMethod(nameof(JsonExceptionHelper.GetUnexpectedTokenException));

                        var read = typeof(Utf8JsonReader)
                                   .GetMethod(nameof(Utf8JsonReader.Read), Type.EmptyTypes);

                        var getString = typeof(Utf8JsonReader)
                                        .GetMethod(nameof(Utf8JsonReader.GetString), Type.EmptyTypes);

                        var getUnknownRecordFieldException = typeof(JsonExceptionHelper)
                                                             .GetMethod(nameof(JsonExceptionHelper.GetUnknownRecordFieldException));

                        if (GetRecordConstructor(underlying, recordSchema) is ConstructorInfo constructor)
                        {
                            var parameters = constructor.GetParameters();

                            // map constructor parameters to fields:
                            var mapping = recordSchema.Fields
                                          .Select(field =>
                            {
                                // there will be a match or we wouldn’t have made it this far:
                                var match     = parameters.Single(parameter => IsMatch(field, parameter.Name));
                                var parameter = Expression.Parameter(match.ParameterType);

                                return(
                                    Field: field,
                                    Match: match,
                                    Parameter: parameter,
                                    Assignment: (Expression)Expression.Block(
                                        Expression.Call(context.Reader, read),
                                        Expression.Assign(
                                            parameter,
                                            DeserializerBuilder.BuildExpression(match.ParameterType, field.Type, context))));
                            })
                                          .ToDictionary(r => r.Match);

                            expression = Expression.Block(
                                mapping
                                .Select(d => d.Value.Parameter),
                                Expression.IfThen(
                                    Expression.NotEqual(
                                        Expression.Property(context.Reader, tokenType),
                                        Expression.Constant(JsonTokenType.StartObject)),
                                    Expression.Throw(
                                        Expression.Call(
                                            null,
                                            getUnexpectedTokenException,
                                            context.Reader,
                                            Expression.Constant(new[] { JsonTokenType.StartObject })))),
                                Expression.Loop(
                                    Expression.Block(
                                        Expression.Call(context.Reader, read),
                                        Expression.IfThen(
                                            Expression.Equal(
                                                Expression.Property(context.Reader, tokenType),
                                                Expression.Constant(JsonTokenType.EndObject)),
                                            Expression.Break(loop)),
                                        Expression.Switch(
                                            Expression.Call(context.Reader, getString),
                                            Expression.Throw(
                                                Expression.Call(
                                                    null,
                                                    getUnknownRecordFieldException,
                                                    context.Reader)),
                                            mapping
                                            .Select(pair =>
                                                    Expression.SwitchCase(
                                                        Expression.Block(pair.Value.Assignment, Expression.Empty()),
                                                        Expression.Constant(pair.Value.Field.Name)))
                                            .ToArray())),
                                    loop),
                                Expression.New(
                                    constructor,
                                    parameters
                                    .Select(parameter => mapping.ContainsKey(parameter)
                                            ? (Expression)mapping[parameter].Parameter
                                            : Expression.Constant(parameter.DefaultValue))));
                        }
                        else
                        {
                            var members = underlying.GetMembers(MemberVisibility);

                            // support dynamic deserialization:
                            var value = Expression.Parameter(
                                underlying.IsAssignableFrom(typeof(ExpandoObject))
                                    ? typeof(ExpandoObject)
                                    : underlying);

                            expression = Expression.Block(
                                new[] { value },
                                Expression.Assign(value, Expression.New(value.Type)),
                                Expression.IfThen(
                                    Expression.NotEqual(
                                        Expression.Property(context.Reader, tokenType),
                                        Expression.Constant(JsonTokenType.StartObject)),
                                    Expression.Throw(
                                        Expression.Call(
                                            null,
                                            getUnexpectedTokenException,
                                            context.Reader,
                                            Expression.Constant(new[] { JsonTokenType.StartObject })))),
                                Expression.Loop(
                                    Expression.Block(
                                        Expression.Call(context.Reader, read),
                                        Expression.IfThen(
                                            Expression.Equal(
                                                Expression.Property(context.Reader, tokenType),
                                                Expression.Constant(JsonTokenType.EndObject)),
                                            Expression.Break(loop)),
                                        Expression.Switch(
                                            Expression.Call(context.Reader, getString),
                                            Expression.Throw(
                                                Expression.Call(
                                                    null,
                                                    getUnknownRecordFieldException,
                                                    context.Reader)),
                                            recordSchema.Fields
                                            .Select(field =>
                            {
                                var match = members.SingleOrDefault(member => IsMatch(field, member));

                                Expression expression;

                                if (match == null)
                                {
                                    // always deserialize fields to advance the reader:
                                    expression = DeserializerBuilder.BuildExpression(typeof(object), field.Type, context);

                                    // fall back to a dynamic setter if the value supports it:
                                    if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(value.Type))
                                    {
                                        var flags  = CSharpBinderFlags.None;
                                        var infos  = new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
                                        var binder = Binder.SetMember(flags, field.Name, value.Type, infos);
                                        expression = Expression.Dynamic(binder, typeof(void), value, expression);
                                    }
                                }
                                else
                                {
                                    Expression inner;

                                    try
                                    {
                                        inner = DeserializerBuilder.BuildExpression(
                                            match switch
                                        {
                                            FieldInfo fieldMatch => fieldMatch.FieldType,
                                            PropertyInfo propertyMatch => propertyMatch.PropertyType,
                                            MemberInfo unknown => throw new InvalidOperationException($"Record fields can only be mapped to fields and properties."),
                                        },
                                            field.Type,
                                            context);
                                    }
                                    catch (Exception exception)
                                    {
                                        throw new UnsupportedTypeException(type, $"The {match.Name} member on {type} could not be mapped to the {field.Name} field on {recordSchema.FullName}.", exception);
                                    }

                                    expression = Expression.Assign(
                                        Expression.PropertyOrField(value, match.Name),
                                        inner);
                                }

                                return(Expression.SwitchCase(
                                           Expression.Block(
                                               Expression.Call(context.Reader, read),
                                               expression,
                                               Expression.Empty()),
                                           Expression.Constant(field.Name)));
                            })
Exemple #26
0
        /// <summary>
        /// Gets a property of the dynamic object.
        /// </summary>
        /// <param name="source">Source object.</param>
        /// <param name="member">Member to retrieve.</param>
        /// <returns>The requested property value.</returns>
        /// <exception cref="ArgumentNullException">If source or member are null.</exception>
        public static object GetProperty(this object source, string member)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            Type scope    = source.GetType();
            var  provider = source as IDynamicMetaObjectProvider;

            if (provider != null)
            {
                var      objectType = typeof(object);
                var      cacheKey   = objectType.FullName + member;
                Delegate del;

                if (!_delegateCache.TryGetValue(cacheKey, out del))
                {
                    ParameterExpression param = Expression.Parameter(typeof(object));
                    DynamicMetaObject   mobj  = provider.GetMetaObject(param);
                    var binder               = (GetMemberBinder)Binder.GetMember(0, member, scope, new[] { CSharpArgumentInfo.Create(0, null) });
                    DynamicMetaObject ret    = mobj.BindGetMember(binder);
                    BlockExpression   final  = Expression.Block(Expression.Label(CallSiteBinder.UpdateLabel), ret.Expression);
                    LambdaExpression  lambda = Expression.Lambda(final, param);
                    del = lambda.Compile();
                    _delegateCache.TryAdd(cacheKey, del);
                }

                return(del.DynamicInvoke(source));
            }
            return(source.GetType().GetProperty(member, BindingFlags.Public | BindingFlags.Instance).GetValue(source, null));
        }
        public ActionResult Edit(FormCollection collection)
        {
            RoadFlow.Platform.WorkFlowComment   workFlowComment = new RoadFlow.Platform.WorkFlowComment();
            RoadFlow.Data.Model.WorkFlowComment model           = (RoadFlow.Data.Model.WorkFlowComment)null;
            string str1  = this.Request.QueryString["id"];
            string str2  = string.Empty;
            string str3  = string.Empty;
            string empty = string.Empty;
            bool   flag  = "1" == this.Request.QueryString["isoneself"];
            Guid   test;

            if (str1.IsGuid(out test))
            {
                model = workFlowComment.Get(test);
                str2  = model.MemberID;
                str3  = model.Comment;
                empty = model.Sort.ToString();
            }
            string oldXML = model.Serialize();

            if (collection != null)
            {
                string str4 = flag ? "u_" + RoadFlow.Platform.Users.CurrentUserID.ToString() : this.Request.Form["Member"];
                string str5 = this.Request.Form["Comment"];
                string str6 = this.Request.Form["Sort"];
                int    num  = !str1.IsGuid() ? 1 : 0;
                if (model == null)
                {
                    model      = new RoadFlow.Data.Model.WorkFlowComment();
                    model.ID   = Guid.NewGuid();
                    model.Type = flag ? 1 : 0;
                }
                model.MemberID = str4.IsNullOrEmpty() ? "" : str4.Trim();
                model.Comment  = str5.IsNullOrEmpty() ? "" : str5.Trim();
                model.Sort     = str6.IsInt() ? str6.ToInt() : workFlowComment.GetManagerMaxSort();
                if (num != 0)
                {
                    workFlowComment.Add(model);
                    RoadFlow.Platform.Log.Add("添加了流程意见", model.Serialize(), RoadFlow.Platform.Log.Types.流程相关, "", "", (RoadFlow.Data.Model.Users)null);
                }
                else
                {
                    workFlowComment.Update(model);
                    RoadFlow.Platform.Log.Add("修改了流程意见", "", RoadFlow.Platform.Log.Types.流程相关, oldXML, model.Serialize(), (RoadFlow.Data.Model.Users)null);
                }
                workFlowComment.RefreshCache();
                // ISSUE: reference to a compiler-generated field
                if (WorkFlowCommentsController.\u003C\u003Eo__4.\u003C\u003Ep__0 == null)
                {
                    // ISSUE: reference to a compiler-generated field
                    WorkFlowCommentsController.\u003C\u003Eo__4.\u003C\u003Ep__0 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "Script", typeof(WorkFlowCommentsController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                    {
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, (string)null)
                    }));
                }
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                object obj = WorkFlowCommentsController.\u003C\u003Eo__4.\u003C\u003Ep__0.Target((CallSite)WorkFlowCommentsController.\u003C\u003Eo__4.\u003C\u003Ep__0, this.ViewBag, "new RoadUI.Window().reloadOpener();alert('保存成功!');");
            }
            if (model == null)
            {
                model      = new RoadFlow.Data.Model.WorkFlowComment();
                model.Sort = workFlowComment.GetManagerMaxSort() + 5;
            }
            return((ActionResult)this.View((object)model));
        }