本文整理汇总了C#中System.Dynamic.GetIndexBinder类的典型用法代码示例。如果您正苦于以下问题:C# GetIndexBinder类的具体用法?C# GetIndexBinder怎么用?C# GetIndexBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetIndexBinder类属于System.Dynamic命名空间,在下文中一共展示了GetIndexBinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
if (indexes.Count() != 1)
{
return base.TryGetIndex(binder, indexes, out result);
}
var index = indexes.Single();
if (_props.Contains(index))
{
result = _props[index];
return true;
}
// try to access an existing member
var strinIndex = index as string;
if (strinIndex != null && TryGetMemberImpl(strinIndex, out result))
{
return true;
}
return base.TryGetIndex(binder, indexes, out result);
}
示例2: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
if (indexes.Length == 0)
throw new Exception("Missing index");
return dictionary.TryGetValue(indexes[0].ToString(), out result);
}
示例3: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
result = null;
var index = indexes.FirstOrDefault();
if (index == null)
return false;
Attempt<object> attempt;
var s = index as string;
if (s != null)
{
attempt = _row.AttemptGet(r => r[s]);
}
else
{
var isInt = index.AttemptGet(Convert.ToInt32);
if (isInt.Succeeded)
attempt = isInt.Value.AttemptGet(i => _row[i]);
else return false;
}
result = attempt.Value;
return attempt.Succeeded;
}
示例4: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder,
object[] indexes, out object result)
{
var ndx = (int)indexes[0];
result = new DynamicXml(_elements[ndx]);
return true;
}
示例5: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
if (indexes.Length > 1)
{
result = null;
return false;
}
try
{
if (indexes[0] is int)
{
result = GetMember(_record.GetName((int)indexes[0]));
return true;
}
else if (indexes[0] is string)
{
result = GetMember((string)indexes[0]);
return true;
}
else
{
result = null;
return false;
}
}
catch
{
result = null;
return false;
}
}
示例6: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
var index = indexes[0];
try
{
int i = Int32.Parse(((string)index));
var str_index = i.ToString();
if (i > length)
{
result = undefined;
return true;
}
result = Fields[str_index];
return true;
}
catch { }
try
{
int i = (int)index;
if (i > length)
{
result = undefined;
return true;
}
result = Fields[i.ToString()];
return true;
}
catch
{
result = undefined;
return true;
}
}
示例7: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
result = PySharp.PyZero;
if (indexes.Length != 1 && indexes.Length != 2)
return false;
var pyType = GetPyType();
if (indexes.Length == 2 && indexes[1] is PyType)
pyType = (PyType) indexes[1];
if (pyType == PyType.DictType)
{
if (indexes[0] is int)
result = DictionaryItem((int) indexes[0]);
if (indexes[0] is long)
result = DictionaryItem((long) indexes[0]);
if (indexes[0] is string)
result = DictionaryItem((string) indexes[0]);
if (indexes[0] is PyObject)
result = DictionaryItem((PyObject) indexes[0]);
}
else
{
// First index has be an int
if (!(indexes[0] is int))
return false;
var index = (int) indexes[0];
if (pyType == PyType.TupleType || pyType == PyType.DerivedTupleType)
result = Item(index, pyType);
else
result = Item(index);
}
return true;
}
示例8: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
if (indexes == null || indexes.Length != 1)
{
throw new ArgumentException(WebPageResources.DynamicDictionary_InvalidNumberOfIndexes);
}
result = null;
string key = indexes[0] as string;
if (key != null)
{
result = _state[key];
}
else if (indexes[0] is int)
{
result = _state[(int)indexes[0]];
}
else
{
// HttpApplicationState only supports keys of type string and int when getting values, so any attempt
// to use other types will result in an error. We throw an exception here to explain to the user what is wrong.
// Returning false will instead cause a runtime binder exception which might be confusing to the user.
throw new ArgumentException(WebPageResources.DynamicHttpApplicationState_UseOnlyStringOrIntToGet);
}
return true;
}
示例9: TryGetIndex
// Get the property value by index.
public override bool TryGetIndex(
GetIndexBinder binder, object[] indexes, out object result)
{
var key = (string)indexes[0];
result = this[key];
return true;
}
示例10: TryGetIndex
public virtual bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
// X:\jsc.svn\examples\javascript\test\TestDynamicGetIndex\TestDynamicGetIndex\Application.cs
result = default(object);
return default(bool);
}
示例11: TryGetIndex
/// <summary>
/// 子オブジェクトから取得プロパティを検索しそれを呼びます。
/// </summary>
public override bool TryGetIndex(GetIndexBinder binder,
object[] indexes,
out object result)
{
var name = indexes[0] as string;
return TryGetValue(name, out result);
}
示例12: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result) {
string key = GetKey(indexes);
result = null;
if (!String.IsNullOrEmpty(key)) {
result = GetValue(key);
}
return true;
}
示例13: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, Object[] indexes, out Object result)
{
int index = (int)indexes[0];
result = _list[index];
if (result is IDictionary<string, object>)
result = new DynamicJson(result as IDictionary<string, object>);
return true;
}
示例14: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
if(indexes.Length == 1 && indexes[0].GetType() == typeof(HttpResponseHeader)) {
result = _responseHeaders[(HttpResponseHeader)indexes[0]];
return true;
}
return base.TryGetIndex(binder, indexes, out result);
}
示例15: TryGetIndex
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
var innerResult = _inner.TryGetIndex(binder, indexes, out result);
//special case, we need to check if the result is of a non-legacy dynamic type because if it is, we need
//to return the legacy type
result = LegacyConverter.ConvertToLegacy(result);
return innerResult;
}