本文整理汇总了C#中System.Dynamic.Binders.MetaObject.Restrict方法的典型用法代码示例。如果您正苦于以下问题:C# MetaObject.Restrict方法的具体用法?C# MetaObject.Restrict怎么用?C# MetaObject.Restrict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Dynamic.Binders.MetaObject
的用法示例。
在下文中一共展示了MetaObject.Restrict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteMember
public MetaObject DeleteMember(string name, MetaObject target, Expression codeContext) {
ContractUtils.RequiresNotNull(name, "name");
ContractUtils.RequiresNotNull(target, "target");
return MakeDeleteMemberTarget(
new SetOrDeleteMemberInfo(
name,
codeContext
),
target.Restrict(target.LimitType)
);
}
示例2: MakeSetMemberTarget
private MetaObject MakeSetMemberTarget(SetOrDeleteMemberInfo memInfo, MetaObject target, MetaObject value) {
Type type = target.LimitType.IsCOMObject ? target.Expression.Type : target.LimitType;
Expression self = target.Expression;
target = target.Restrict(target.LimitType);
memInfo.Body.Restrictions = target.Restrictions;
if (typeof(TypeTracker).IsAssignableFrom(type)) {
type = ((TypeTracker)target.Value).Type;
self = null;
memInfo.Body.Restrictions = memInfo.Body.Restrictions.Merge(
Restrictions.GetInstanceRestriction(target.Expression, target.Value)
);
}
MakeSetMemberRule(memInfo, type, self, value);
return memInfo.Body.GetMetaObject(target, value);
}
示例3: MakeGetMemberTarget
private MetaObject MakeGetMemberTarget(GetMemberInfo getMemInfo, MetaObject target) {
Type type = target.LimitType.IsCOMObject ? target.Expression.Type : target.LimitType;
Restrictions restrictions = target.Restrictions;
Expression self = target.Expression;
target = target.Restrict(target.LimitType);
// needed for GetMember call until DynamicAction goes away
OldDynamicAction act = OldGetMemberAction.Make(
this,
getMemInfo.Name
);
// Specially recognized types: TypeTracker, NamespaceTracker, and StrongBox.
// TODO: TypeTracker and NamespaceTracker should technically be IDO's.
MemberGroup members = MemberGroup.EmptyGroup;
if (typeof(TypeTracker).IsAssignableFrom(type)) {
restrictions = restrictions.Merge(
Restrictions.GetInstanceRestriction(target.Expression, target.Value)
);
TypeGroup tg = target.Value as TypeGroup;
Type nonGen;
if (tg == null || tg.TryGetNonGenericType(out nonGen)) {
members = GetMember(act, ((TypeTracker)target.Value).Type, getMemInfo.Name);
if (members.Count > 0) {
// we have a member that's on the type associated w/ the tracker, return that...
type = ((TypeTracker)target.Value).Type;
self = null;
}
}
}
if (members.Count == 0) {
// Get the members
members = GetMember(act, type, getMemInfo.Name);
}
if (members.Count == 0) {
if (typeof(TypeTracker).IsAssignableFrom(type)) {
// ensure we don't have a non-generic type, and if we do report an error now. This matches
// the rule version of the default binder but should probably be removed long term
Type x = ((TypeTracker)target.Value).Type;
} else if (type.IsInterface) {
// all interfaces have object members
type = typeof(object);
members = GetMember(act, type, getMemInfo.Name);
}
}
Expression propSelf = self;
// if lookup failed try the strong-box type if available.
if (members.Count == 0 && typeof(IStrongBox).IsAssignableFrom(type)) {
// properties/fields need the direct value, methods hold onto the strong box.
propSelf = Ast.Field(AstUtils.Convert(self, type), type.GetField("Value"));
type = type.GetGenericArguments()[0];
members = GetMember(
act,
type,
getMemInfo.Name
);
}
MakeBodyHelper(getMemInfo, self, propSelf, type, members);
getMemInfo.Body.Restrictions = restrictions;
return getMemInfo.Body.GetMetaObject(target);
}