本文整理汇总了C#中MemberBinding类的典型用法代码示例。如果您正苦于以下问题:C# MemberBinding类的具体用法?C# MemberBinding怎么用?C# MemberBinding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberBinding类属于命名空间,在下文中一共展示了MemberBinding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitMemberBinding
public override Expression VisitMemberBinding(MemberBinding memberBinding){
if (memberBinding == null) return null;
if (memberBinding.BoundMember != null){
if (!memberBinding.BoundMember.IsStatic){
//add precondition that target object is not null
}
}
return base.VisitMemberBinding(memberBinding);
}
示例2: VisitRefTypeExpression
public override Expression VisitRefTypeExpression(RefTypeExpression reftypexp) {
if (reftypexp == null) return null;
Expression result = base.VisitRefTypeExpression (reftypexp);
if (result != reftypexp) return result;
UnaryExpression refanytype = new UnaryExpression(reftypexp.Operand, NodeType.Refanytype, SystemTypes.RuntimeTypeHandle, reftypexp.SourceContext);
ExpressionList arguments = new ExpressionList(1);
arguments.Add(refanytype);
MemberBinding mb = new MemberBinding(null, Runtime.GetTypeFromHandle);
return new MethodCall(mb, arguments, NodeType.Call, SystemTypes.Type);
}
示例3: AsBinding
internal override MemberBinding AsBinding() {
switch (_action) {
case RewriteAction.None:
return _binding;
case RewriteAction.Copy:
MemberBinding[] newBindings = new MemberBinding[_bindings.Count];
for (int i = 0; i < _bindings.Count; i++) {
newBindings[i] = _bindingRewriters[i].AsBinding();
}
return Expression.MemberBind(_binding.Member, new TrueReadOnlyCollection<MemberBinding>(newBindings));
}
throw ContractUtils.Unreachable;
}
示例4: Create
internal static BindingRewriter Create(MemberBinding binding, StackSpiller spiller, Stack stack) {
switch (binding.BindingType) {
case MemberBindingType.Assignment:
MemberAssignment assign = (MemberAssignment)binding;
return new MemberAssignmentRewriter(assign, spiller, stack);
case MemberBindingType.ListBinding:
MemberListBinding list = (MemberListBinding)binding;
return new ListBindingRewriter(list, spiller, stack);
case MemberBindingType.MemberBinding:
MemberMemberBinding member = (MemberMemberBinding)binding;
return new MemberMemberBindingRewriter(member, spiller, stack);
}
throw Error.UnhandledBinding();
}
示例5: VisitMemberBinding
public override void VisitMemberBinding(MemberBinding memberBinding)
{
var method = memberBinding.BoundMember as Method;
if (method != null)
{
string message;
if (_problematicTypes.TryGetValue(method.DeclaringType.FullName, out message))
{
Problems.Add(new Problem(GetResolution(method.DeclaringType.FullName, message), memberBinding.UniqueKey.ToString()));
}
}
base.VisitMemberBinding(memberBinding);
}
示例6: VisitMemberBinding
public override Expression VisitMemberBinding(MemberBinding binding)
{
Member boundMember = binding.BoundMember;
if (boundMember is Field && !boundMember.IsStatic && boundMember.DeclaringType != null && boundMember.DeclaringType.Contract != null && boundMember.DeclaringType.Contract.FramePropertyGetter != null && boundMember != boundMember.DeclaringType.Contract.FrameField)
{
Expression target = VisitExpression(binding.TargetObject);
// Since we do not visit member bindings of assignment statements, we know/guess that this is a ldfld.
Local targetLocal = new Local(boundMember.DeclaringType);
Statement evaluateTarget = new AssignmentStatement(targetLocal, target, binding.SourceContext);
Expression guard = new MethodCall(new MemberBinding(targetLocal, boundMember.DeclaringType.Contract.FramePropertyGetter), null, NodeType.Call, SystemTypes.Guard);
Statement check = new ExpressionStatement(new MethodCall(new MemberBinding(guard, SystemTypes.Guard.GetMethod(Identifier.For("CheckIsReading"))), null, NodeType.Call, SystemTypes.Void));
Statement ldfld = new ExpressionStatement(new MemberBinding(targetLocal, boundMember, binding.SourceContext));
return new BlockExpression(new Block(new StatementList(new Statement[] {evaluateTarget, check, ldfld})), binding.Type);
}
else
{
return base.VisitMemberBinding(binding);
}
}
示例7: VisitMemberBinding
public override Expression VisitMemberBinding(MemberBinding memberBinding){
if (memberBinding == null) return null;
Field f = memberBinding.BoundMember as Field;
if (f != null){
if (f.IsLiteral){
if (f.DefaultValue != null) return f.DefaultValue;
Expression e = f.Initializer;
if (e == Evaluator.BeingEvaluated) throw new CircularConstantException();
f.Initializer = Evaluator.BeingEvaluated;
Literal lit = null;
try{
lit = this.VisitExpression(e) as Literal;
}catch(CircularConstantException){
f.Initializer = null;
throw;
}
if (lit != null){
if (f.DeclaringType is EnumNode && f.Type == f.DeclaringType) lit.Type = f.DeclaringType;
f.DefaultValue = lit;
f.Initializer = null;
return lit;
}
}else{
//Should never get here from the compiler itself, but only from runtime code paths.
if (f.IsStatic) return f.GetValue(null);
Expression targetLiteral = this.VisitExpression(memberBinding.TargetObject) as Expression;
if (targetLiteral != null){
// HACK: Unary Expressions with NodeType "AddressOf" not getting converted to Literal.
UnaryExpression uexpr = targetLiteral as UnaryExpression;
if (uexpr != null)
targetLiteral = this.VisitExpression(uexpr.Operand);
if (targetLiteral is Literal)
return f.GetValue(targetLiteral as Literal);
}
}
}
return null;
}
示例8: VisitMemberBinding
public virtual void VisitMemberBinding (MemberBinding node)
{
if (node == null)
return;
VisitExpression (node.TargetObject);
}
示例9: VisitApplyToAll
public override Expression VisitApplyToAll(ApplyToAll applyToAll) {
if (applyToAll == null) return null;
Expression collection = applyToAll.Operand1;
if (collection == null) { Debug.Assert(false); return null; }
TypeNode elemType = this.typeSystem.GetStreamElementType(collection.Type, this.TypeViewer);
bool singleTon = elemType == collection.Type;
Local loc = applyToAll.ElementLocal;
if (loc == null) loc = new Local(elemType);
if (singleTon)
applyToAll.Operand1 = this.VisitExpression(collection);
else
applyToAll.Operand1 = this.VisitEnumerableCollection(collection, loc.Type);
if (applyToAll.Operand1 == null) return null;
AnonymousNestedFunction func = applyToAll.Operand2 as AnonymousNestedFunction;
Expression expr = applyToAll.Operand2 as BlockExpression;
if (func != null || expr != null) {
this.VisitAnonymousNestedFunction(func);
if (singleTon || applyToAll.Type == SystemTypes.Void) return applyToAll;
//Create an iterator to compute stream that results from ApplyToAll
Class closureClass = this.currentMethod.Scope.ClosureClass;
Method method = new Method();
method.Name = Identifier.For("Function:"+method.UniqueKey);
method.SourceContext = collection.SourceContext;
method.Flags = MethodFlags.CompilerControlled;
method.CallingConvention = CallingConventionFlags.HasThis;
method.InitLocals = true;
method.DeclaringType = closureClass;
closureClass.Members.Add(method);
method.Scope = new MethodScope(new TypeScope(null, closureClass), null);
Parameter coll = new Parameter(StandardIds.Collection, collection.Type);
ParameterField fcoll = new ParameterField(method.Scope, null, FieldFlags.CompilerControlled, StandardIds.Collection, collection.Type, null);
fcoll.Parameter = coll;
method.Scope.Members.Add(fcoll);
Parameter closure = new Parameter(StandardIds.Closure, closureClass);
ParameterField fclosure = new ParameterField(method.Scope, null, FieldFlags.CompilerControlled, StandardIds.Closure, closureClass, null);
fclosure.Parameter = closure;
if (func != null) {
method.Scope.Members.Add(fclosure);
method.Parameters = new ParameterList(coll, closure);
} else
method.Parameters = new ParameterList(coll);
method.ReturnType = applyToAll.Type;
ForEach forEach = new ForEach();
forEach.TargetVariable = loc;
forEach.TargetVariableType = loc.Type;
forEach.SourceEnumerable = new MemberBinding(new ImplicitThis(), fcoll);
if (func != null) {
MemberBinding mb = new MemberBinding(new MemberBinding(new ImplicitThis(), fclosure), func.Method);
expr = new MethodCall(mb, new ExpressionList(loc), NodeType.Call, func.Method.ReturnType, func.SourceContext);
} else
expr = this.VisitExpression(expr);
expr = this.typeSystem.ImplicitCoercion(expr, this.typeSystem.GetStreamElementType(applyToAll.Type, this.TypeViewer), this.TypeViewer);
if (expr == null) return null;
BlockExpression bExpr = expr as BlockExpression;
if (bExpr != null && bExpr.Type == SystemTypes.Void)
forEach.Body = bExpr.Block;
else
forEach.Body = new Block(new StatementList(new Yield(expr)));
forEach.ScopeForTemporaryVariables = new BlockScope(method.Scope, forEach.Body);
method.Body = new Block(new StatementList(forEach));
applyToAll.ResultIterator = this.VisitMethod(method);
return applyToAll;
}
Debug.Assert(false);
return null;
}
示例10: GetProjectionList
public virtual void GetProjectionList(Accessor accessor, Expression source, ExpressionList list){
if (accessor == null) return;
MemberAccessor ma = accessor as MemberAccessor;
if (ma != null){
MemberBinding mb = new MemberBinding(source, ma.Member);
mb.SourceContext = source.SourceContext;
if (ma.Yield){
list.Add(mb);
}
if (ma.Next != null){
this.GetProjectionList(ma.Next, mb, list);
}
return;
}
SequenceAccessor sa = accessor as SequenceAccessor;
if (sa != null){
foreach( Accessor acc in sa.Accessors ){
this.GetProjectionList(acc, source, list);
}
return;
}
this.HandleError(source, Error.QueryProjectThroughTypeUnion);
}
示例11: EmitBinding
private void EmitBinding(MemberBinding binding, Type objectType)
{
switch (binding.BindingType)
{
case MemberBindingType.Assignment:
EmitMemberAssignment((MemberAssignment)binding, objectType);
break;
case MemberBindingType.ListBinding:
EmitMemberListBinding((MemberListBinding)binding);
break;
case MemberBindingType.MemberBinding:
EmitMemberMemberBinding((MemberMemberBinding)binding);
break;
default:
throw Error.UnknownBindingType();
}
}
示例12: VisitMemberBinding
public virtual Differences VisitMemberBinding(MemberBinding memberBinding1, MemberBinding memberBinding2){
Differences differences = new Differences(memberBinding1, memberBinding2);
if (memberBinding1 == null || memberBinding2 == null){
if (memberBinding1 != memberBinding2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
return differences;
}
MemberBinding changes = (MemberBinding)memberBinding2.Clone();
MemberBinding deletions = (MemberBinding)memberBinding2.Clone();
MemberBinding insertions = (MemberBinding)memberBinding2.Clone();
if (memberBinding1.Alignment == memberBinding2.Alignment) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
Differences diff = this.VisitMember(memberBinding1.BoundMember, memberBinding2.BoundMember);
if (diff == null){Debug.Assert(false); return differences;}
changes.BoundMember = diff.Changes as Member;
deletions.BoundMember = diff.Deletions as Member;
insertions.BoundMember = diff.Insertions as Member;
Debug.Assert(diff.Changes == changes.BoundMember && diff.Deletions == deletions.BoundMember && diff.Insertions == insertions.BoundMember);
differences.NumberOfDifferences += diff.NumberOfDifferences;
differences.NumberOfSimilarities += diff.NumberOfSimilarities;
diff = this.VisitExpression(memberBinding1.TargetObject, memberBinding2.TargetObject);
if (diff == null){Debug.Assert(false); return differences;}
changes.TargetObject = diff.Changes as Expression;
deletions.TargetObject = diff.Deletions as Expression;
insertions.TargetObject = diff.Insertions as Expression;
Debug.Assert(diff.Changes == changes.TargetObject && diff.Deletions == deletions.TargetObject && diff.Insertions == insertions.TargetObject);
differences.NumberOfDifferences += diff.NumberOfDifferences;
differences.NumberOfSimilarities += diff.NumberOfSimilarities;
if (memberBinding1.Volatile == memberBinding2.Volatile) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
if (differences.NumberOfDifferences == 0){
differences.Changes = null;
differences.Deletions = null;
differences.Insertions = null;
}else{
differences.Changes = changes;
differences.Deletions = deletions;
differences.Insertions = insertions;
}
return differences;
}
示例13: VisitMemberBinding
public override Expression VisitMemberBinding(MemberBinding memberBinding)
{
var result = base.VisitMemberBinding(memberBinding);
var mb = result as MemberBinding;
if (mb != null)
{
mb.BoundMember = this.VisitMemberReference(mb.BoundMember);
}
return result;
}
示例14: VisitMemberBinding
public virtual Expression VisitMemberBinding(MemberBinding memberBinding, bool isTargetOfAssignment) {
if (memberBinding == null) return null;
Member mem = memberBinding.BoundMember;
if (mem == null) return null;
TypeNode memType = mem.DeclaringType;
Expression originalTarget = memberBinding.TargetObject;
Expression target = originalTarget;
if (mem.IsStatic) {
this.VisitTypeReference(mem.DeclaringType);
}
if (target != null) {
QueryContext qc = target as QueryContext;
if (qc != null && qc.Type == null) {
this.HandleError(memberBinding, Error.IdentifierNotFound, mem.Name.ToString());
return null;
}
target = memberBinding.TargetObject = this.VisitExpression(target);
if (target == null) return null;
}
Property prop = mem as Property;
if (prop != null) {
Error e = Error.None;
if (isTargetOfAssignment && !(prop.Type is Reference)) {
Method setter = prop.Setter;
if (setter == null) setter = prop.GetBaseSetter();
if (setter == null) {
e = Error.NoSetter;
}
else if (setter.IsAbstract && memberBinding.TargetObject is Base)
e = Error.AbstractBaseCall;
} else {
if (prop.Getter == null) e = Error.NoGetter;
}
if (e != Error.None) {
string typeName = this.GetTypeName(mem.DeclaringType);
this.HandleError(memberBinding, e, typeName+"."+mem.Name);
return null;
}
}
TypeNode targetType = target == null ? null : TypeNode.StripModifiers(target.Type);
bool errorIfCurrentMethodIsStatic = false;
if (target is ImplicitThis) {
errorIfCurrentMethodIsStatic = !(memType is BlockScope || memType is MethodScope); //locals and parameters are excempt
if (errorIfCurrentMethodIsStatic && !this.NotAccessible(mem)) {
if (this.MayNotReferenceThisFromFieldInitializer && this.currentMethod == null && this.currentField != null && !this.currentField.IsStatic) {
this.HandleError(memberBinding, Error.ThisReferenceFromFieldInitializer, this.GetMemberSignature(mem));
return null;
}
if (!this.GetTypeView(this.currentType).IsAssignableTo(memType)) {
this.HandleError(memberBinding, Error.AccessToNonStaticOuterMember, this.GetTypeName(mem.DeclaringType), this.GetTypeName(this.currentType));
return null;
}
}
if (!this.MayReferenceThisAndBase && !(memType is Scope) && !this.insideInvariant) {
this.HandleError(memberBinding, Error.ObjectRequired, this.GetMemberSignature(mem));
return null;
}
targetType = null;
} else if (target is Base || target is This) {
if (!this.MayReferenceThisAndBase && !(this.insideInvariant && target is This)) {
if (target is Base)
this.HandleError(memberBinding, Error.BaseInBadContext, this.GetMemberSignature(mem));
else
this.HandleError(memberBinding, Error.ThisInBadContext, this.GetMemberSignature(mem));
return null;
}
targetType = null;
errorIfCurrentMethodIsStatic = true;
} else if (!mem.IsStatic && target is Literal) {
this.HandleError(memberBinding, Error.ObjectRequired, this.GetMemberSignature(mem));
return null;
} else if (target != null) {
target = memberBinding.TargetObject = this.typeSystem.ExplicitCoercion(target, memType, this.TypeViewer);
if (target == null) return null;
if (prop != null && memType != null && memType.IsValueType)
target = memberBinding.TargetObject = new UnaryExpression(target, NodeType.AddressOf, memType.GetReferenceType());
}
if (errorIfCurrentMethodIsStatic &&
((this.currentMethod != null && this.currentMethod.IsStatic) || (this.currentField != null && this.currentField.IsStatic))) {
this.HandleError(memberBinding, Error.ObjectRequired, this.GetMemberSignature(mem));
return null;
}
if (this.NotAccessible(mem, ref targetType)) {
string mname = mem.Name.ToString();
if (targetType == null && target != null && target.Type != null && !(target is ImplicitThis || target is This || target is Base))
this.HandleError(memberBinding, Error.NotVisibleViaBaseType, this.GetTypeName(mem.DeclaringType)+"."+mname,
this.GetTypeName(target.Type), this.GetTypeName(this.currentType));
else if (mem.IsSpecialName && mem is Field && ((Field)mem).Type is DelegateNode)
this.HandleError(memberBinding, Error.InaccessibleEventBackingField, this.GetTypeName(mem.DeclaringType) + "." + mname, this.GetTypeName(mem.DeclaringType));
else {
Node offendingNode = memberBinding;
QualifiedIdentifier qi = memberBinding.BoundMemberExpression as QualifiedIdentifier;
if (qi != null) offendingNode = qi.Identifier;
this.HandleError(offendingNode, Error.MemberNotVisible, this.GetTypeName(mem.DeclaringType) + "." + mname);
this.HandleRelatedError(mem);
}
return null;
} else {
string mname = mem.Name.ToString();
if (!mem.IsCompilerControlled && (this.insideMethodContract || this.insideInvariant)) {
//.........这里部分代码省略.........
示例15: VisitConstruct
public override Expression VisitConstruct(Construct cons){
if (cons == null) return cons;
cons.Owner = this.VisitExpression(cons.Owner);
cons.Constructor = this.VisitExpression(cons.Constructor);
MemberBinding mb = cons.Constructor as MemberBinding;
if (mb == null){
Literal literal = cons.Constructor as Literal;
if (literal == null) return cons;
TypeNode t = literal.Value as TypeNode;
if (t == null) return cons;
cons.Type = t;
cons.Constructor = mb = new MemberBinding(null, t);
mb.SourceContext = literal.SourceContext;
}else{
TypeNode t = mb.BoundMember as TypeNode;
if (t == null) return cons; //TODO: if the bound member is an instance initializer, use it.
cons.Type = t;
}
AnonymousNestedFunction func = null;
DelegateNode delType = cons.Type as DelegateNode;
if (delType != null && cons.Operands != null && cons.Operands.Count == 1){
Method meth = null;
Expression ob = Literal.Null;
Expression e = cons.Operands[0];
MemberBinding emb = e as MemberBinding;
if (emb != null) e = emb.BoundMemberExpression;
TemplateInstance instance = e as TemplateInstance;
TypeNodeList typeArguments = instance == null ? null : instance.TypeArguments;
if (instance != null) e = instance.Expression;
NameBinding nb = e as NameBinding;
if (nb != null){
meth = this.ChooseMethodMatchingDelegate(nb.BoundMembers, delType, typeArguments);
if (meth != null && !meth.IsStatic)
ob = new ImplicitThis();
else if (meth == null){
e = this.VisitExpression(e);
if (e.Type is DelegateNode){
meth = this.ChooseMethodMatchingDelegate(this.GetTypeView(e.Type).GetMembersNamed(StandardIds.Invoke), delType, typeArguments);
if (meth != null)
ob = e;
}
}
}else{
QualifiedIdentifier qualId = e as QualifiedIdentifier;
if (qualId != null){
ob = qualId.Qualifier = this.VisitExpression(qualId.Qualifier);
if (ob is Literal && ob.Type == SystemTypes.Type)
meth = this.ChooseMethodMatchingDelegate(this.GetTypeView((ob as Literal).Value as TypeNode).GetMembersNamed(qualId.Identifier), delType, typeArguments);
else if (ob == null)
return null;
else if (ob != null && ob.Type != null){
TypeNode oT = TypeNode.StripModifiers(ob.Type);
Reference rT = oT as Reference;
if (rT != null) oT = rT.ElementType;
while (oT != null){
meth = this.ChooseMethodMatchingDelegate(this.GetTypeView(oT).GetMembersNamed(qualId.Identifier), delType, typeArguments);
if (meth != null) break;
oT = oT.BaseType;
}
}
if (meth == null){
e = this.VisitExpression(e);
if (e.Type is DelegateNode){
meth = this.ChooseMethodMatchingDelegate(this.GetTypeView(e.Type).GetMembersNamed(StandardIds.Invoke), delType, typeArguments);
if (meth != null){
qualId.BoundMember = new MemberBinding(e, meth, qualId.Identifier);
ob = e;
}
}
}else
qualId.BoundMember = new MemberBinding(ob, meth, qualId.Identifier);
}else{
func = e as AnonymousNestedFunction;
if (func != null){
meth = func.Method;
if (meth != null){
meth.ReturnType = delType.ReturnType;
ParameterList mParams = meth.Parameters;
ParameterList dParams = delType.Parameters;
int n = mParams == null ? 0 : mParams.Count;
int m = dParams == null ? 0 : dParams.Count;
for (int i = 0; i < n; i++){
Parameter mPar = mParams[i];
if (mPar == null) return null;
if (i >= m){
if (mPar.Type == null) mPar.Type = SystemTypes.Object;
continue;
}
Parameter dPar = dParams[i];
if (mPar.Type == null){
if (dPar != null)
mPar.Type = dPar.Type;
if (mPar.Type == null)
mPar.Type = SystemTypes.Object;
}
}
if (n != m){
Node nde = new Expression(NodeType.Nop);
if (n == 0)
nde.SourceContext = cons.Constructor.SourceContext;
//.........这里部分代码省略.........