本文整理汇总了C#中DynValue.ToScalar方法的典型用法代码示例。如果您正苦于以下问题:C# DynValue.ToScalar方法的具体用法?C# DynValue.ToScalar怎么用?C# DynValue.ToScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynValue
的用法示例。
在下文中一共展示了DynValue.ToScalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetIndex
/// <summary>
/// Performs an "index" "set" operation. This tries to resolve minor variations of member names.
/// </summary>
/// <param name="script">The script originating the request</param>
/// <param name="obj">The object (null if a static request is done)</param>
/// <param name="index">The index.</param>
/// <param name="value">The value to be set</param>
/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
/// <returns></returns>
public virtual bool SetIndex(Script script, object obj, DynValue index, DynValue value, bool isDirectIndexing)
{
if (!isDirectIndexing)
{
IMemberDescriptor mdesc = m_Members
.GetOrDefault(SPECIALNAME_INDEXER_SET)
.WithAccessOrNull(MemberDescriptorAccess.CanExecute);
if (mdesc != null)
{
ExecuteIndexer(mdesc, script, obj, index, value);
return true;
}
}
index = index.ToScalar();
if (index.Type != DataType.String)
return false;
bool v = TrySetIndex(script, obj, index.String, value);
if (!v) v = TrySetIndex(script, obj, UpperFirstLetter(index.String), value);
if (!v) v = TrySetIndex(script, obj, Camelify(index.String), value);
if (!v) v = TrySetIndex(script, obj, UpperFirstLetter(Camelify(index.String)), value);
return v;
}
示例2: Index
/// <summary>
/// Performs an "index" "get" operation. This tries to resolve minor variations of member names.
/// </summary>
/// <param name="script">The script originating the request</param>
/// <param name="obj">The object (null if a static request is done)</param>
/// <param name="index">The index.</param>
/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
/// <returns></returns>
public virtual DynValue Index(Script script, object obj, DynValue index, bool isDirectIndexing)
{
if (!isDirectIndexing)
{
IMemberDescriptor mdesc = m_Members
.GetOrDefault(SPECIALNAME_INDEXER_GET)
.WithAccessOrNull(MemberDescriptorAccess.CanExecute);
if (mdesc != null)
return ExecuteIndexer(mdesc, script, obj, index, null);
}
index = index.ToScalar();
if (index.Type != DataType.String)
return null;
DynValue v = TryIndex(script, obj, index.String);
if (v == null) v = TryIndex(script, obj, UpperFirstLetter(index.String));
if (v == null) v = TryIndex(script, obj, Camelify(index.String));
if (v == null) v = TryIndex(script, obj, UpperFirstLetter(Camelify(index.String)));
if (v == null && m_ExtMethodsVersion < UserData.GetExtensionMethodsChangeVersion())
{
m_ExtMethodsVersion = UserData.GetExtensionMethodsChangeVersion();
v = TryIndexOnExtMethod(script, obj, index.String);
if (v == null) v = TryIndexOnExtMethod(script, obj, UpperFirstLetter(index.String));
if (v == null) v = TryIndexOnExtMethod(script, obj, Camelify(index.String));
if (v == null) v = TryIndexOnExtMethod(script, obj, UpperFirstLetter(Camelify(index.String)));
}
return v;
}