本文整理汇总了C#中MemberReferenceExpression类的典型用法代码示例。如果您正苦于以下问题:C# MemberReferenceExpression类的具体用法?C# MemberReferenceExpression怎么用?C# MemberReferenceExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberReferenceExpression类属于命名空间,在下文中一共展示了MemberReferenceExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: FieldReferenceReflectionEmitter
internal FieldReferenceReflectionEmitter(MemberReferenceExpression memberReferenceExpression,
Type target,
MemberInfo member,
ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals,
bool isSetter = false)
: base(memberReferenceExpression, target, member, ilGenerator, instructionsIndexer, visitor, locals) {
FieldReference = MemberReference.Annotation<FieldReference>();
IsByRef = MemberReference.Parent is DirectionExpression;
Type = FieldReference.FieldType.GetActualType();
FieldInfo = FieldReference.GetActualField();
NonPublic = !((FieldInfo.Attributes & (_publicFieldAttributes)) == _publicFieldAttributes);
if (isSetter) {
_emitAction = EmitStoreFieldReference;
_emitPrivateAction = EmitPrivateStoreFieldReference;
}
else {
_emitAction = EmitLoadFieldReference;
_emitPrivateAction = EmitPrivateLoadFieldReference;
}
}
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:25,代码来源:FieldReferenceReflectionEmitter.cs
示例2: PropertyReferenceReflectionEmitter
public PropertyReferenceReflectionEmitter(MemberReferenceExpression memberReferenceExpression,
Type target,
MemberInfo member,
ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals,
bool isSetter = false)
: base(memberReferenceExpression, target, member, ilGenerator, instructionsIndexer, visitor, locals) {
var propertyInfo = Member as PropertyInfo;
_isSetter = isSetter;
_propertyDefinition = MemberReference.Annotation<Cecil.PropertyDefinition>();
NonPublic = !_propertyDefinition.GetMethod.IsPublic;
Type = _propertyDefinition.PropertyType.GetActualType();
if (isSetter) {
_propertyMethod = propertyInfo.GetSetMethod(NonPublic);
_emitPrivateAction = EmitPrivateStorePropertyReference;
}
else {
_propertyMethod = propertyInfo.GetGetMethod(NonPublic);
_emitPrivateAction = EmitPrivateLoadPropertyReference;
}
}
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:26,代码来源:PropertyReferenceReflectionEmitter.cs
示例3: EventReferenceReflectionEmitter
internal EventReferenceReflectionEmitter(MemberReferenceExpression memberReferenceExpression,
Type target,
MemberInfo member,
ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals)
: base(memberReferenceExpression, target, member, ilGenerator, instructionsIndexer, visitor, locals) { }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:8,代码来源:EventReferenceReflectionEmitter.cs
示例4: VisitMemberReferenceExpression
public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression)
{
if (!IsTargetOfInvocation(memberReferenceExpression)) {
var mgr = ctx.Resolve (memberReferenceExpression) as MethodGroupResolveResult;
if (mgr != null)
UsedMethods.AddRange (mgr.Methods);
}
base.VisitMemberReferenceExpression(memberReferenceExpression);
}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:9,代码来源:ParameterNotUsedIssue.cs
示例5: ToStaticMethodInvocation
AstNode ToStaticMethodInvocation(InvocationExpression invocation, MemberReferenceExpression memberReference,
CSharpInvocationResolveResult invocationRR)
{
var newArgumentList = invocation.Arguments.Select(arg => arg.Clone()).ToList();
newArgumentList.Insert(0, memberReference.Target.Clone());
var newTarget = memberReference.Clone() as MemberReferenceExpression;
newTarget.Target = new IdentifierExpression(invocationRR.Member.DeclaringType.Name);
return new InvocationExpression(newTarget, newArgumentList);
}
开发者ID:porcus,项目名称:NRefactory,代码行数:9,代码来源:ExtensionMethodInvocationToStaticMethodInvocationAction.cs
示例6: VisitMemberReferenceExpression
public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression)
{
base.VisitMemberReferenceExpression(memberReferenceExpression);
HandleMemberReference(
memberReferenceExpression, memberReferenceExpression.Target, memberReferenceExpression.MemberNameToken, memberReferenceExpression.TypeArguments, NameLookupMode.Expression,
script => {
script.Replace(memberReferenceExpression, RefactoringAstHelper.RemoveTarget(memberReferenceExpression));
});
}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:9,代码来源:RedundantNamespaceUsageIssue.cs
示例7: MultipuleAssignmentEmitter
internal MultipuleAssignmentEmitter(MemberReferenceExpression memberReferenceExpression,
Expression assignor,
ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals)
: base(memberReferenceExpression, ilGenerator, instructionsIndexer, visitor, locals) {
_assignorExpression = assignor;
}
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:9,代码来源:MultipuleAssignmentEmitter.cs
示例8: VisitMemberReferenceExpression
public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression)
{
var identifierExpression = memberReferenceExpression.Target as IdentifierExpression;
if (identifierExpression != null && identifierExpression.Identifier == _fromIdentifier)
{
memberReferenceExpression.Target = new IdentifierExpression("doc");
}
base.VisitMemberReferenceExpression(memberReferenceExpression);
}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:10,代码来源:ChangeRootReferenceVisitor.cs
示例9: AbstractMemberReferenceEmitter
internal AbstractMemberReferenceEmitter(MemberReferenceExpression memberReferenceExpression,
Type target,
MemberInfo member,
ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals)
: base(ilGenerator, instructionsIndexer, visitor, locals) {
Target = target;
Member = member;
MemberReference = memberReferenceExpression;
}
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:12,代码来源:AbstractMemberReferenceEmitter.cs
示例10: LookupAmbiguousMemberInOtherAssembly
public void LookupAmbiguousMemberInOtherAssembly()
{
_compilationUnit.UsingDirectives.Add(new UsingNamespaceDirective("System"));
var reference = new MemberReferenceExpression(new IdentifierExpression("Console"), "WriteLine");
var result = reference.Resolve(_compilationUnit.GetScope());
Assert.IsInstanceOfType(result, typeof(AmbiguousMemberResolveResult));
var memberResult = (AmbiguousMemberResolveResult)result;
Assert.AreEqual("System.Console", memberResult.Member.DeclaringType.FullName);
Assert.AreEqual("WriteLine", memberResult.Member.Name);
Assert.IsTrue(memberResult.Candidates.Count > 1);
}
开发者ID:JerreS,项目名称:AbstractCode,代码行数:12,代码来源:MemberResolutionTests.cs
示例11: VisitObjectCreateExpression
public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
{
if (objectCreateExpression.Arguments.Count() == 2) {
Expression obj = objectCreateExpression.Arguments.First();
Expression func = objectCreateExpression.Arguments.Last();
Annotation annotation = func.Annotation<Annotation>();
if (annotation != null) {
IdentifierExpression methodIdent = (IdentifierExpression)((InvocationExpression)func).Arguments.Single();
MethodReference method = methodIdent.Annotation<MethodReference>();
if (method != null) {
if (HandleAnonymousMethod(objectCreateExpression, obj, method))
return null;
// Perform the transformation to "new Action(obj.func)".
obj.Remove();
methodIdent.Remove();
if (!annotation.IsVirtual && obj is ThisReferenceExpression) {
// maybe it's getting the pointer of a base method?
if (method.DeclaringType != context.CurrentType) {
obj = new BaseReferenceExpression();
}
}
if (!annotation.IsVirtual && obj is NullReferenceExpression && !method.HasThis) {
// We're loading a static method.
// However it is possible to load extension methods with an instance, so we compare the number of arguments:
bool isExtensionMethod = false;
TypeReference delegateType = objectCreateExpression.Type.Annotation<TypeReference>();
if (delegateType != null) {
TypeDefinition delegateTypeDef = delegateType.Resolve();
if (delegateTypeDef != null) {
MethodDefinition invokeMethod = delegateTypeDef.Methods.FirstOrDefault(m => m.Name == "Invoke");
if (invokeMethod != null) {
isExtensionMethod = (invokeMethod.Parameters.Count + 1 == method.Parameters.Count);
}
}
}
if (!isExtensionMethod) {
obj = new TypeReferenceExpression { Type = AstBuilder.ConvertType(method.DeclaringType) };
}
}
// now transform the identifier into a member reference
MemberReferenceExpression mre = new MemberReferenceExpression();
mre.Target = obj;
mre.MemberName = methodIdent.Identifier;
methodIdent.TypeArguments.MoveTo(mre.TypeArguments);
mre.AddAnnotation(method);
objectCreateExpression.Arguments.Clear();
objectCreateExpression.Arguments.Add(mre);
return null;
}
}
}
return base.VisitObjectCreateExpression(objectCreateExpression, data);
}
开发者ID:stgwilli,项目名称:ILSpy,代码行数:53,代码来源:DelegateConstruction.cs
示例12: VisitMemberReferenceExpression
public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression)
{
base.VisitMemberReferenceExpression(memberReferenceExpression);
if (memberReferenceExpression == null || memberReferenceExpression.Target is ThisReferenceExpression)
// Call within current class scope using 'this' or 'base'
return;
var memberResolveResult = context.Resolve(memberReferenceExpression) as MemberResolveResult;
if (memberResolveResult == null)
return;
if (!memberResolveResult.Member.IsStatic)
return;
HandleMember(memberReferenceExpression, memberReferenceExpression.Target, memberResolveResult.Member, memberResolveResult.TargetResult);
}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:13,代码来源:ReferenceToStaticMemberViaDerivedTypeIssue.cs
示例13: VisitMemberReferenceExpression
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
const string typeToUse = "System.Threading.Thread";
const string methodToFind = "Abort";
if (_codebaseDeclarations.Any(a => a.Name == memberReferenceExpression.Target.GetIdentifier() && a.IsType(typeToUse)) || memberReferenceExpression.IsReferenceOfTypeFromScope(typeToUse))
{
if (memberReferenceExpression.MemberName == methodToFind)
{
UnlockWith(memberReferenceExpression);
}
}
return base.VisitMemberReferenceExpression(memberReferenceExpression, data);
}
开发者ID:vlad2135,项目名称:strokes,代码行数:15,代码来源:ThreadMethodschievements.cs
示例14: VisitMemberReferenceExpression
// fixes bug https://github.com/ashmind/TryRoslyn/issues/7
// todo: report this to the decompiler guys -- but does not seem like they are reading their queue
public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression)
{
StartNode(memberReferenceExpression);
var useParentheses = RequiresParenthesesWhenTargetOfMemberReference(memberReferenceExpression.Target);
if (useParentheses)
LPar();
memberReferenceExpression.Target.AcceptVisitor(this);
if (useParentheses)
RPar();
WriteToken(Roles.Dot);
WriteIdentifier(memberReferenceExpression.MemberName);
WriteTypeArguments(memberReferenceExpression.TypeArguments);
EndNode(memberReferenceExpression);
}
开发者ID:i3arnon,项目名称:TryRoslyn,代码行数:18,代码来源:DecompiledPseudoCSharpOutputVisitor.cs
示例15: VisitMemberReferenceExpression
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
if(memberReferenceExpression.MemberName == "Length")
{
var variableName = memberReferenceExpression.Target.GetIdentifier();
if(memberReferenceExpression.GetVariablesOfInitializer<ArrayCreateExpression>().Any(a => a.Name == variableName))
{
UnlockWith(memberReferenceExpression);
}
else if(_codebaseDeclarations.Any(a => a.Name == variableName && a.Initializer is ArrayCreateExpression))
{
UnlockWith(memberReferenceExpression);
}
}
return base.VisitMemberReferenceExpression(memberReferenceExpression, data);
}
开发者ID:jonasswiatek,项目名称:strokes,代码行数:16,代码来源:ArrayLengthPropertyAchievement.cs
示例16: GetActionsFromMemberReferenceExpression
IEnumerable<CodeAction> GetActionsFromMemberReferenceExpression(RefactoringContext context, MemberReferenceExpression invocation)
{
if (!(context.Resolve(invocation).IsError))
yield break;
var methodName = invocation.MemberName;
var guessedType = TypeGuessing.GuessType(context, invocation);
if (guessedType.Kind != TypeKind.Delegate)
yield break;
var invocationMethod = guessedType.GetDelegateInvokeMethod();
var state = context.GetResolverStateBefore(invocation);
if (state.CurrentTypeDefinition == null)
yield break;
ResolveResult targetResolveResult = context.Resolve(invocation.Target);
bool createInOtherType = !state.CurrentTypeDefinition.Equals(targetResolveResult.Type.GetDefinition());
bool isStatic;
if (createInOtherType) {
if (targetResolveResult.Type.GetDefinition() == null || targetResolveResult.Type.GetDefinition().Region.IsEmpty)
yield break;
isStatic = targetResolveResult is TypeResolveResult;
if (isStatic && targetResolveResult.Type.Kind == TypeKind.Interface || targetResolveResult.Type.Kind == TypeKind.Enum)
yield break;
} else {
if (state.CurrentMember == null)
yield break;
isStatic = state.CurrentMember.IsStatic || state.CurrentTypeDefinition.IsStatic;
}
// var service = (NamingConventionService)context.GetService(typeof(NamingConventionService));
// if (service != null && !service.IsValidName(methodName, AffectedEntity.Method, Modifiers.Private, isStatic)) {
// yield break;
// }
yield return CreateAction(
context,
invocation,
methodName,
context.CreateShortType(invocationMethod.ReturnType),
invocationMethod.Parameters.Select(parameter => new ParameterDeclaration(context.CreateShortType(parameter.Type), parameter.Name) {
ParameterModifier = GetModifiers(parameter)
}),
createInOtherType,
isStatic,
targetResolveResult);
}
开发者ID:qhta,项目名称:NRefactory,代码行数:46,代码来源:CreateMethodDeclarationAction.cs
示例17: GetActions
public IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
// TODO: Invert if without else
// ex. if (cond) DoSomething () == if (!cond) return; DoSomething ()
// beware of loop contexts return should be continue then.
var methodDeclaration = GetMethodDeclaration(context);
if (methodDeclaration == null)
yield break;
var resolved = context.Resolve(methodDeclaration) as MemberResolveResult;
if (resolved == null)
yield break;
var isImplementingInterface = resolved.Member.ImplementedInterfaceMembers.Any();
if (isImplementingInterface)
yield break;
yield return new CodeAction(context.TranslateString(string.Format("Make '{0}' static", methodDeclaration.Name)), script =>
{
var clonedDeclaration = (MethodDeclaration)methodDeclaration.Clone();
clonedDeclaration.Modifiers |= Modifiers.Static;
script.Replace(methodDeclaration, clonedDeclaration);
var rr = context.Resolve (methodDeclaration) as MemberResolveResult;
var method = (IMethod)rr.Member;
//method.ImplementedInterfaceMembers.Any(m => methodGroupResolveResult.Methods.Contains((IMethod)m));
script.DoGlobalOperationOn(rr.Member, (fctx, fscript, fnode) => {
if (fnode is MemberReferenceExpression) {
var memberReference = new MemberReferenceExpression (
new TypeReferenceExpression (fctx.CreateShortType (rr.Member.DeclaringType)),
rr.Member.Name
);
fscript.Replace (fnode, memberReference);
} else if (fnode is InvocationExpression) {
var invoke = (InvocationExpression)fnode;
if (!(invoke.Target is MemberReferenceExpression))
return;
var memberReference = new MemberReferenceExpression (
new TypeReferenceExpression (fctx.CreateShortType (rr.Member.DeclaringType)),
rr.Member.Name
);
fscript.Replace (invoke.Target, memberReference);
}
});
}, methodDeclaration);
}
开发者ID:handless,项目名称:NRefactory,代码行数:45,代码来源:ConvertToStaticMethodAction.cs
示例18: VisitMemberReferenceExpression
public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression)
{
base.VisitMemberReferenceExpression(memberReferenceExpression);
var targetResolveResult = context.Resolve(memberReferenceExpression.Target) as LocalResolveResult;
if (targetResolveResult == null)
return;
var variable = targetResolveResult.Variable;
var conversion = context.GetConversion(memberReferenceExpression);
if (conversion.IsMethodGroupConversion) {
AddCriterion(variable, new HasMemberCriterion(conversion.Method));
} else {
var resolveResult = context.Resolve(memberReferenceExpression);
var memberResolveResult = resolveResult as MemberResolveResult;
if (memberResolveResult != null)
AddCriterion(variable, new HasMemberCriterion(memberResolveResult.Member));
}
}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:18,代码来源:TypeCriteriaCollector.cs
示例19: GetActions
public IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
//TODO: implement variable assignment & ctor param
var varInit = context.GetNode<VariableInitializer>();
if (varInit != null) {
AstType type = varInit.GetPrevNode() as AstType;
if (type == null) yield break;
if (varInit.Parent is FieldDeclaration) yield break;
if (CannotExtractField(varInit)) yield break;
yield return new CodeAction("Extract field", s=>{
var name = varInit.Name;
FieldDeclaration field = new FieldDeclaration(){
ReturnType = type.Clone(),
Variables = { new VariableInitializer(name) }
};
AstNode nodeToRemove = RemoveDeclaration(varInit) ? varInit.Parent : type;
s.Remove(nodeToRemove, true);
s.InsertWithCursor(context.TranslateString("Extract field"),Script.InsertPosition.Before,field);
s.FormatText(varInit.Parent);
});
}
var idntf = context.GetNode<Identifier>();
if (idntf == null) yield break;
var paramDec = idntf.Parent as ParameterDeclaration;
if (paramDec != null) {
var ctor = paramDec.Parent as ConstructorDeclaration;
if (ctor == null) yield break;
MemberReferenceExpression thisField = new MemberReferenceExpression(new ThisReferenceExpression(), idntf.Name, new AstType[]{});
var assign = new AssignmentExpression(thisField, AssignmentOperatorType.Assign, new IdentifierExpression(idntf.Name));
var statement = new ExpressionStatement(assign);
var type = (idntf.GetPrevNode() as AstType).Clone();
FieldDeclaration field = new FieldDeclaration(){
ReturnType = type.Clone(),
Variables = { new VariableInitializer(idntf.Name) }
};
yield return new CodeAction("Extract field", s=>{
s.InsertWithCursor(context.TranslateString("Extract field"),Script.InsertPosition.Before,field);
s.AddTo(ctor.Body, statement);
});
}
}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:43,代码来源:ExtractFieldAction.cs
示例20: LookupArrayTypeMember
public void LookupArrayTypeMember()
{
_compilationUnit.UsingDirectives.Add(new UsingNamespaceDirective("System"));
var reference = new MemberReferenceExpression
{
Target = new ParenthesizedExpression(
new CreateArrayExpression(
new PrimitiveTypeReference(PrimitiveType.Byte),
new PrimitiveExpression(3))),
Identifier = new Identifier("Length")
};
var result = reference.Resolve(_compilationUnit.GetScope());
Assert.IsInstanceOfType(result, typeof(MemberResolveResult));
var memberResult = (MemberResolveResult)result;
Assert.AreEqual("System.Array", memberResult.Member.DeclaringType.FullName);
Assert.AreEqual("Length", memberResult.Member.Name);
Assert.AreEqual("System.Int32", memberResult.Member.MemberType.FullName);
}
开发者ID:JerreS,项目名称:AbstractCode,代码行数:19,代码来源:MemberResolutionTests.cs
注:本文中的MemberReferenceExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论