本文整理汇总了C#中System.Dynamic.GetMemberBinder类的典型用法代码示例。如果您正苦于以下问题:C# GetMemberBinder类的具体用法?C# GetMemberBinder怎么用?C# GetMemberBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetMemberBinder类属于System.Dynamic命名空间,在下文中一共展示了GetMemberBinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetMember
/// <summary>
/// Finds text resource
/// </summary>
/// <param name="binder">GetMemberBinder with dynamic text key</param>
/// <param name="result">Text item</param>
/// <returns>Returns a value or a non existing value from the <see cref="ITextResource"/> implementation</returns>
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result =
new DynamicMemberChainer(binder.Name, this.context, this.textResource);
return true;
}
示例2: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = Repository.FindModel(binder.Name);
//result = string.Format("{{ Site.{0} }}", binder.Name); //default result;
return true;
}
示例3: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (!_dictionary.TryGetValue(binder.Name, out result))
{
// return null to avoid exception. caller can check for null this way...
result = null;
return true;
}
var dictionary = result as IDictionary<string, object>;
if (dictionary != null)
{
result = new DictionaryObject(dictionary);
return true;
}
var arrayList = result as ArrayList;
if (arrayList != null && arrayList.Count > 0)
{
if (arrayList[0] is IDictionary<string, object>)
result = new List<object>(arrayList.Cast<IDictionary<string, object>>().Select(x => new DictionaryObject(x)));
else
result = new List<object>(arrayList.Cast<object>());
}
return true;
}
示例4: TryGetMember
/// <summary>
/// Returns a value from the current DataReader record
/// If the field doesn't exist null is returned.
/// DbNull values are turned into .NET nulls.
/// </summary>
/// <param name="binder"></param>
/// <param name="result"></param>
/// <returns></returns>
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = null;
// 'Implement' common reader properties directly
if (binder.Name == "IsClosed")
result = DataReader.IsClosed;
else if (binder.Name == "RecordsAffected")
result = DataReader.RecordsAffected;
// lookup column names as fields
else
{
try
{
result = DataReader[binder.Name];
if (result == DBNull.Value)
result = null;
}
catch
{
result = null;
return false;
}
}
return true;
}
示例5: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (!this.dictionary.TryGetValue(binder.Name, out result))
{
result = null;
return true;
}
var dictionary = result as IDictionary<string, object>;
if (dictionary != null)
{
result = new DynamicJsonObject(dictionary);
return true;
}
var arrayList = result as ArrayList;
if (arrayList != null)
{
if (arrayList.Count > 0 && arrayList[0] is IDictionary<string, object>)
result = new List<object>(arrayList.Cast<IDictionary<string, object>>().Select(x => new DynamicJsonObject(x)));
else
result = new List<object>(arrayList.Cast<object>());
}
return true;
}
示例6: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
//return base.TryGetMember(binder, out result);
CurrentList = CurrentList ?? new BiggyList<dynamic>(dbName: binder.Name);
result = CurrentList;
return true;
}
示例7: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (_dictionary.TryGetValue(binder.Name, out result) == false)
if (_dictionary.TryGetValue(binder.Name.ToLower(), out result) == false)
return false;// throw new Exception("property not found " + binder.Name);
if (result is IDictionary<string, object>)
{
result = new DynamicJson(result as IDictionary<string, object>);
}
else if (result is List<object>)
{
List<object> list = new List<object>();
foreach (object item in (List<object>)result)
{
if (item is IDictionary<string, object>)
list.Add(new DynamicJson(item as IDictionary<string, object>));
else
list.Add(item);
}
result = list;
}
return _dictionary.ContainsKey(binder.Name);
}
示例8: BindGetMember
public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
ContractUtils.RequiresNotNull(binder, "binder");
string name = binder.Name;
if (name == _info.Name) {
name = "TypeLibDesc";
} else if (name != "Guid" &&
name != "Name" &&
name != "VersionMajor" &&
name != "VersionMinor") {
return binder.FallbackGetMember(this);
}
return new DynamicMetaObject(
Expression.Convert(
Expression.Property(
AstUtils.Convert(Expression, typeof(ComTypeLibInfo)),
typeof(ComTypeLibInfo).GetProperty(name)
),
typeof(object)
),
ComTypeLibInfoRestrictions(this)
);
}
示例9: TryGetMember
public override bool TryGetMember(
GetMemberBinder binder, out object result)
{
result = null;
if (binder.Name == "Value")
result = _elements[0].Value;
else if (binder.Name == "Count")
result = _elements.Count;
else
{
var attr = _elements[0].Attribute(
XName.Get(binder.Name ) );
if (attr != null)
result = attr.Value;
else
{
var items = _elements.Descendants(
XName.Get(binder.Name ) );
if (items == null || items.Count() == 0)
return false;
result = new DynamicXml( items );
}
}
return true;
}
示例10: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
try
{
Variable variable;
if(!variables.TryGetValue(binder.Name, out variable))
{
int idx = GetGlobalVarIndexByName(binder.Name);
var ptr = GetAddressOfGlobalVar(idx);
if(ptr == IntPtr.Zero)
{
result = null;
return true;
}
int tid;
GetGlobalVar(idx, out tid);
var instance = ScriptEngine.GetVariable(ptr, tid);
variables[binder.Name] = variable = new Variable(instance, ptr, tid);
}
result = ScriptEngine.GetVariable(variable.Address, variable.TypeId, variable.Instance);
return true;
}
catch(Exception ex)
{
ScriptEngine.Log ("Exception caught while fetching '{0}' variable of module '{1}': {2}.", binder.Name, Name, ex.Message);
result = null;
return false;
}
}
示例11: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
var child = elementFactory.CreateElementWithNameForParent(binder.Name, element);
element.AddChild(child);
result = DynamicElementFor(child);
return true;
}
示例12: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (binder.Name == "__Fields")
{
result = (from field in m_type.Fields where field.Type != null select new { Name = field.Name, Type = field.Type.Name }).ToArray();
return true;
}
if (binder.Name == "__StaticFields")
{
result = (from field in m_type.StaticFields where field.Type != null select new { Name = field.Name, Type = field.Type.Name }).ToArray();
return true;
}
if (binder.Name == "__ThreadStaticFields")
{
result = (from field in m_type.ThreadStaticFields where field.Type != null select new { Name = field.Name, Type = field.Type.Name }).ToArray();
return true;
}
if (binder.Name == "__Name")
{
result = m_type.Name;
return true;
}
if (GetStaticField(m_heap, m_type, binder, out result))
return true;
throw new InvalidOperationException(string.Format("Type '{0}' does not contain a static '{1}' field.", m_type.Name, binder.Name));
}
示例13: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
var propertyInfo = m_type.GetProperty(
binder.Name,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
if (propertyInfo != null)
{
result = propertyInfo.GetValue(null, null);
return true;
}
var fieldInfo = m_type.GetField(
binder.Name,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
if (fieldInfo != null)
{
result = fieldInfo.GetValue(null);
return true;
}
result = null;
return false;
}
示例14: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (cache == null) CacheLoad();
if (!cache.TryGetValue(binder.Name, out result))
result = GetDefault(binder.ReturnType);
return true;
}
示例15: TryGetMember
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
PropertyInfo propInfo = _realObject.GetType().GetProperty(binder.Name);
if (propInfo == null) {
PropertyInfo[] properties = _realObject.GetType().GetProperties();
if (properties.Length == 0) {
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
MvcResources.DynamicViewPage_NoProperties,
binder.Name)
);
}
string propNames = properties.Select(p => p.Name)
.OrderBy(name => name)
.Aggregate((left, right) => left + ", " + right);
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
MvcResources.DynamicViewPage_PropertyDoesNotExist,
binder.Name,
propNames)
);
}
result = Wrap(propInfo.GetValue(_realObject, null));
return true;
}