本文整理汇总了C#中System.Dynamic.Binders.MetaObject类的典型用法代码示例。如果您正苦于以下问题:C# MetaObject类的具体用法?C# MetaObject怎么用?C# MetaObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetaObject类属于System.Dynamic.Binders命名空间,在下文中一共展示了MetaObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindInvokeMember
public override MetaObject BindInvokeMember(InvokeMemberBinder binder, MetaObject[] args) {
ContractUtils.RequiresNotNull(binder, "binder");
if (args.Any(arg => ComBinderHelpers.IsStrongBoxArg(arg))) {
return ComBinderHelpers.RewriteStrongBoxAsRef(binder, this, args);
}
ComMethodDesc methodDesc;
if (_wrapperType.Funcs.TryGetValue(binder.Name, out methodDesc) ||
_self.TryGetMemberMethodExplicit(binder.Name, out methodDesc)) {
return new ComInvokeBinder(
binder.Arguments,
args,
IDispatchRestriction(),
Expression.Constant(methodDesc),
Expression.Property(
Expression.Convert(Expression, typeof(IDispatchComObject)),
typeof(IDispatchComObject).GetProperty("DispatchObject")
),
methodDesc
).Invoke();
}
return base.BindInvokeMember(binder, args);
}
示例2: Bind
public sealed override MetaObject Bind(MetaObject target, MetaObject[] args) {
ContractUtils.RequiresNotNull(target, "target");
ContractUtils.RequiresNotNullItems(args, "args");
ContractUtils.Requires(args.Length == 1);
return target.BindSetMember(this, args[0]);
}
示例3: BindingTarget
/// <summary>
/// Creates a new BindingTarget when the method binding has succeeded
/// </summary>
internal BindingTarget(string name, int actualArgumentCount, MethodTarget target, NarrowingLevel level, MetaObject[] restrictedArgs) {
_name = name;
_target = target;
_restrictedArgs = restrictedArgs;
_level = level;
_actualArgs = actualArgumentCount;
}
示例4: TryBindInvokeMember
public static bool TryBindInvokeMember(InvokeMemberBinder binder, ref MetaObject instance, MetaObject[] args) {
if (TryGetMetaObject(ref instance)) {
instance = instance.BindInvokeMember(binder, args);
return true;
}
return false;
}
示例5: TryBindSetIndex
public static bool TryBindSetIndex(SetIndexBinder binder, ref MetaObject instance, MetaObject[] args, MetaObject value) {
if (TryGetMetaObject(ref instance)) {
instance = instance.BindSetIndex(binder, args, value);
return true;
}
return false;
}
示例6: TryBindSetMember
public static bool TryBindSetMember(SetMemberBinder binder, ref MetaObject instance, MetaObject value) {
if (TryGetMetaObject(ref instance)) {
instance = instance.BindSetMember(binder, value);
return true;
}
return false;
}
示例7: Bind
public sealed override Expression Bind(object[] args, ReadOnlyCollection<ParameterExpression> parameters, LabelTarget returnLabel) {
if (args.Length == 0) {
throw new InvalidOperationException();
}
MetaObject[] mos;
if (args.Length != 1) {
mos = new MetaObject[args.Length - 1];
for (int i = 1; i < args.Length; i++) {
mos[i - 1] = MetaObject.ObjectToMetaObject(args[i], parameters[i]);
}
} else {
mos = MetaObject.EmptyMetaObjects;
}
MetaObject binding = Bind(
MetaObject.ObjectToMetaObject(args[0], parameters[0]),
mos
);
if (binding == null) {
throw Error.BindingCannotBeNull();
}
return GetMetaObjectRule(binding, returnLabel);
}
示例8: GetArguments
private MetaObject[] GetArguments(MetaObject[] args, IList<MetaObject> results, int metaBinderIndex) {
BinderMappingInfo indices = _metaBinders[metaBinderIndex];
MetaObject[] res = new MetaObject[indices.MappingInfo.Count];
for (int i = 0; i < res.Length; i++) {
ParameterMappingInfo mappingInfo = indices.MappingInfo[i];
if (mappingInfo.IsAction) {
// input is the result of a previous bind
res[i] = results[mappingInfo.ActionIndex];
} else if (mappingInfo.IsParameter) {
// input is one of the original arguments
res[i] = args[mappingInfo.ParameterIndex];
} else {
// input is a constant
res[i] = new MetaObject(
mappingInfo.Constant,
Restrictions.Empty,
mappingInfo.Constant.Value
);
}
}
return res;
}
示例9: GetMember
/// <summary>
/// Builds a MetaObject for performing a member get. Supports all built-in .NET members, the OperatorMethod
/// GetBoundMember, and StrongBox instances.
/// </summary>
/// <param name="name">
/// The name of the member to retrieve. This name is not processed by the DefaultBinder and
/// is instead handed off to the GetMember API which can do name mangling, case insensitive lookups, etc...
/// </param>
/// <param name="target">
/// The MetaObject from which the member is retrieved.
/// </param>
/// <param name="codeContext">
/// An expression which provides access to the CodeContext if its required for
/// accessing the member (e.g. for an extension property which takes CodeContext). By default this
/// a null CodeContext object is passed.
/// </param>
public MetaObject GetMember(string name, MetaObject target, Expression codeContext) {
return GetMember(
name,
target,
codeContext,
false
);
}
示例10: FallbackGetMember
public override MetaObject/*!*/ FallbackGetMember(MetaObject/*!*/ self, MetaObject/*!*/ onBindingError) {
var result = TryBind(_context, this, self);
if (result != null) {
return result;
}
// TODO: remove CodeContext
return ((DefaultBinder)_context.Binder).GetMember(Name, self, Ast.Constant(null, typeof(CodeContext)), true);
}
示例11: BindSetIndex
public override MetaObject BindSetIndex(SetIndexBinder binder, MetaObject[] indexes, MetaObject value) {
if (_callable.ComMethodDesc.IsPropertyPut) {
if (indexes.Any(arg => ComBinderHelpers.IsStrongBoxArg(arg))) {
return ComBinderHelpers.RewriteStrongBoxAsRef(binder, this, indexes.AddLast(value));
}
return BindComInvoke(binder.Arguments, indexes.AddLast(value));
}
return base.BindSetIndex(binder, indexes, value);
}
示例12: FallbackInvokeMember
public override MetaObject/*!*/ FallbackInvokeMember(MetaObject/*!*/ self, MetaObject/*!*/[]/*!*/ args, MetaObject/*!*/ onBindingError) {
var result = TryBind(_context, this, self, args);
if (result != null) {
return result;
}
// TODO: return ((DefaultBinder)_context.Binder).GetMember(Name, self, Ast.Null(typeof(CodeContext)), true);
throw new NotImplementedException();
}
示例13: TryAssignableConversion
/// <summary>
/// Checks if the conversion can be handled by a simple cast.
/// </summary>
private static MetaObject TryAssignableConversion(Type toType, Type type, Restrictions restrictions, MetaObject arg) {
if (toType.IsAssignableFrom(type) ||
(type == typeof(Null) && (toType.IsClass || toType.IsInterface))) {
// MakeSimpleConversionTarget handles the ConversionResultKind check
return MakeSimpleConversionTarget(toType, restrictions, arg);
}
return null;
}
示例14: TryAllConversions
/// <summary>
/// Checks if any conversions are available and if so builds the target for that conversion.
/// </summary>
private MetaObject TryAllConversions(Type toType, ConversionResultKind kind, Type knownType, Restrictions restrictions, MetaObject arg) {
return
TryAssignableConversion(toType, knownType, restrictions, arg) ?? // known type -> known type
TryExtensibleConversion(toType, knownType, restrictions, arg) ?? // Extensible<T> -> Extensible<T>.Value
TryUserDefinedConversion(kind, toType, knownType, restrictions, arg) ?? // op_Implicit
TryImplicitNumericConversion(toType, knownType, restrictions, arg) ?? // op_Implicit
TryNullableConversion(toType, kind, knownType, restrictions, arg) ?? // null -> Nullable<T> or T -> Nullable<T>
TryNullConversion(toType, knownType, restrictions); // null -> reference type
}
示例15: DeleteMember
/// <summary>
/// Builds a MetaObject for performing a member delete. Supports all built-in .NET members, the OperatorMethod
/// DeleteMember, and StrongBox instances.
/// </summary>
public MetaObject DeleteMember(string name, MetaObject target) {
ContractUtils.RequiresNotNull(name, "name");
ContractUtils.RequiresNotNull(target, "target");
return DeleteMember(
name,
target,
Ast.Constant(null, typeof(CodeContext))
);
}