ICSharpCode.NRefactory.CSharp.Refactoring.BaseRefactoringContext.GetService C# (CSharp) Method

GetService() public method

Retrieves a service from the refactoring context. If the service is not found in the Services container.
public GetService ( Type serviceType ) : object
serviceType System.Type
return object
		public object GetService(Type serviceType)
		{
			return services.GetService(serviceType);
		}
		#endregion

Usage Example

        protected static bool HidesMember(BaseRefactoringContext ctx, AstNode node, string variableName, out IMember member)
        {
            MemberCollectionService mcs = (MemberCollectionService)ctx.GetService(typeof(MemberCollectionService));

            if (mcs == null)
            {
                lock (ctx) {
                    if ((mcs = (MemberCollectionService)ctx.GetService(typeof(MemberCollectionService))) == null)
                    {
                        mcs = new MemberCollectionService();
                        ctx.Services.AddService(typeof(MemberCollectionService), mcs);
                    }
                }
            }

            var typeDecl = node.GetParent <TypeDeclaration>();

            member = null;
            if (typeDecl == null)
            {
                return(false);
            }
            var entityDecl          = node.GetParent <EntityDeclaration>();
            var memberResolveResult = ctx.Resolve(entityDecl) as MemberResolveResult;

            if (memberResolveResult == null)
            {
                return(false);
            }
            var typeResolveResult = ctx.Resolve(typeDecl) as TypeResolveResult;

            if (typeResolveResult == null)
            {
                return(false);
            }

            var sourceMember = memberResolveResult.Member;

            member = mcs.GetMembers(typeResolveResult.Type, variableName).FirstOrDefault(m2 => IsAccessible(sourceMember, m2));
            return(member != null);
        }
All Usage Examples Of ICSharpCode.NRefactory.CSharp.Refactoring.BaseRefactoringContext::GetService