public DynamicObjectMemberNode(ObjectNode parent, DynamicObject item, int maxDepth, DataContextDriver dcDriver) : base(parent, item, maxDepth, dcDriver) { base.Name = "DynamicObject"; base.Summary = item.ToString(); if (base.Summary.Length > 150) { base.Summary = base.Summary.Substring(0, 150) + "..."; } IEnumerable<string> dynamicMemberNames = item.GetDynamicMemberNames(); if (dynamicMemberNames.Any<string>() && (base.CyclicReference == null)) { if (!(!base.IsAtNestingLimit() || (base.Parent is ListNode))) { base.GraphTruncated = true; } else { foreach (string str in dynamicMemberNames) { object propValue = this.GetPropValue(item, str); base.Members.Add(new MemberData(str, null, ObjectNode.Create(this, propValue, false, maxDepth, dcDriver))); } } } }
public void Dump(DynamicObject obj) { foreach (var memberName in obj.GetDynamicMemberNames()) { _appender(GetDynamicMember(obj, memberName).ToString()); Print("\n"); } }
public ExpandoObjectWrapper(object o) { if (o is DynamicObject) { _wrapped = (DynamicObject)o; } else { _wrapped = new ReflectionDynamicObject(o); } }
public NodeHttpRequest(HttpClient client, HttpRequestMessage requestMessage, object options, DynamicObject callback = null) { _client = client; _requestMessage = requestMessage; _options = options as NodeHttpRequestOptions ?? new NodeHttpRequestOptions((dynamic)options); if (callback != null) { @on("response", callback); } }
public NodeHttpRequestOptions(DynamicObject config) { host = config.GetMember<string>("host"); scheme = config.GetMember("scheme", "http"); hostname = config.GetMember<string>("hostname") ?? host; url = config.GetMember<object>("uri") ?? config.GetMember<object>("url"); method = config.GetMember<string>("method"); headers = config.GetMember<DynamicObject>("headers"); port = config.GetMember("port", Convert.ToInt32, 80); }
/// <summary> /// 获取动态类型的值 /// </summary> /// <param name="dynamicObject">实例</param> /// <param name="key">键名</param> /// <param name="value">值</param> /// <returns></returns> private bool TryGetValue(DynamicObject dynamicObject, string key, out object value) { var keys = dynamicObject.GetDynamicMemberNames(); key = keys.FirstOrDefault(item => string.Equals(item, key, StringComparison.OrdinalIgnoreCase)); if (key != null) { return dynamicObject.TryGetMember(new KeyBinder(key, false), out value); } value = null; return false; }
public static DynamicViewModel Create(DynamicObject entity) { var result = new DynamicViewModel(); foreach (var memberName in entity.GetDynamicMemberNames()) { object value; if (entity.TryGetMember(new GetBinder(memberName, false), out value)) { result.Set(memberName, value); } } return result; }
private object GetPropValue(DynamicObject item, string propName) { try { object obj2; item.TryGetMember(new MyGetMemberBinder(propName, false), out obj2); return obj2; } catch (Exception innerException) { if ((innerException is TargetInvocationException) && (innerException.InnerException != null)) { innerException = innerException.InnerException; } return innerException; } }
public RuleBuilder(IpTablesSystem system, String nfbpf, Dictionary<int, IpTablesRuleSet> ruleSets, FunctionRegistry functions = null) { if (functions == null) { functions = new FunctionRegistry(); } _system = system.System; _nfbpf = nfbpf; var chainsDict = ruleSets.Select((a) => new KeyValuePair<int, IpTablesChainSet>(a.Key, a.Value.Chains)) .ToDictionary((a) => a.Key, (a) => a.Value); _dcr = new DynamicChainRegister(system, chainsDict); _formatDb = new DynamicDictionary<object>(_mappings); _ruleSets = ruleSets; _interpreter = new Interpreter(); _interpreter.SetVariable("var", _mappings); functions.LoadFunctions(_interpreter); }
internal static void MakeRequest(DynamicObject config, DynamicObject callback, Microsoft.ClearScript.V8.V8ScriptEngine engine) { var options = new NodeHttpRequestOptions(config); var uriObj = new Uri((config.GetMember<object>("uri") ?? config.GetMember<object>("url")).ToString()); options.url = (config.GetMember<object>("uri") ?? config.GetMember<object>("url")); options.host = uriObj.Host; options.hostname = uriObj.Host; options.scheme = uriObj.Scheme; options.path = uriObj.PathAndQuery; options.port = uriObj.Port; options.method = config.GetMember("method", "GET"); options.headers = config.GetMember<DynamicObject>("headers"); bool isJson = config.GetMember("json", false); var req = new NodeHttpRequest(new HttpClient(), new HttpRequestMessage(), options); Action<NodeHttpResponse> wrapperCallback = resp => { if (callback == null) { return; } // string body = null; object body = null; var apiResp = resp.GetHttpResponseMessage(); if (apiResp.Content != null && apiResp.Content.Headers.ContentLength > 0) { if (isJson) { string xxx = apiResp.Content.ReadAsStringAsync().Result; var parser = (dynamic)engine.Evaluate("JSON.parse"); body = parser(xxx); } else { body = apiResp.Content.ReadAsStringAsync().Result; } } callback.AsDynamic().call(null, null, resp, body); }; req.@on("response", wrapperCallback); req.end(); }
public PrototypalMethodHolder(DynamicObject prototype) : base(prototype) { StaticMethodWithNoReturnValueOrParametersWasCalled = false; }
internal static bool TryGetDynamicMember(DynamicObject o, string name, out object result) { return o.TryGetMember(new Binder(name, true), out result); }
internal static object GetDynamicMember(DynamicObject obj, string name) { object result = new object(); if (TryGetDynamicMember(obj, name, out result)) { return result; } throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Column {0} was not found", name)); }
internal MetaDynamic(Expression expression, DynamicObject value) : base(expression, BindingRestrictions.Empty, value) { }
internal MetaDynamic(Expression expression, DynamicObject value) : base(expression, BindingRestrictions.Empty, value) { }
public ChainBuilder(DynamicObject originalObject, IDocumentSession session, string collection) { OriginalObject = originalObject; Session = session; CollectionName = collection; }
internal DynamicDictionaryMetaObject(Expression parameter, DynamicObject value) : base(parameter, BindingRestrictions.Empty, value) { }
public static object GetValue(string name, DynamicObject dyn, Type objType) { try { var callSite = CallSite<Func<CallSite, object, object>>.Create(Binder.GetMember(CSharpBinderFlags.None, name, objType, new[] {CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)})); return callSite.Target(callSite, dyn); } catch (RuntimeBinderException) { return null; } }
static List<PropertyItem> ParseDynamicObject(DynamicObject target) { var result = new List<PropertyItem>(); foreach (var propertyName in target.GetDynamicMemberNames()) { var value = DynamicHelper.GetValue(target, propertyName); var propertyType = value != null ? value.GetType() : typeof(object); var property = new PropertyItem(target, value, new DynamicPropertyInfo(propertyName, propertyType), false); result.Add(property); } return result; }
public PrototypalObject(DynamicObject prototype) { Prototype = prototype; }
public object GetUserInfo(DynamicObject param) { dynamic p = param; throw new System.NotImplementedException(); }