コード例 #1
0
        public override void MakeVirtual(IMember member)
        {
            SDRefactoringContext refactoringContext = member.CreateRefactoringContext();
            var entityDeclaration = refactoringContext.GetNode <EntityDeclaration>();

            using (Script script = refactoringContext.StartScript()) {
                script.ChangeModifier(entityDeclaration, entityDeclaration.Modifiers | Modifiers.Virt);
            }
        }
コード例 #2
0
        public override void MakePartial(ITypeDefinition td)
        {
            SDRefactoringContext refactoringContext = td.CreateRefactoringContext();
            var typeDeclaration = refactoringContext.GetNode <TypeDeclaration>();

            using (Script script = refactoringContext.StartScript()) {
                script.ChangeModifier(typeDeclaration, typeDeclaration.Modifiers | Modifiers.Shared);
            }
        }
コード例 #3
0
        public override void AddMethodAtStart(ITypeDefinition declaringType, Accessibility accessibility, IType returnType, string name)
        {
            SDRefactoringContext context = declaringType.CreateRefactoringContext();
            var typeDecl = context.GetNode <TypeDeclaration>();

            using (var script = context.StartScript()) {
                var astBuilder = context.CreateTypeSystemAstBuilder(typeDecl.FirstChild);
                var methodDecl = new MethodDeclaration();
                methodDecl.Name       = name;
                methodDecl.ReturnType = astBuilder.ConvertType(context.Compilation.Import(returnType));

                script.AddTo(typeDecl, methodDecl);
            }
        }
コード例 #4
0
        public override void AddField(ITypeDefinition declaringType, Accessibility accessibility, IType fieldType, string name)
        {
            SDRefactoringContext context = declaringType.CreateRefactoringContext();
            var typeDecl = context.GetNode <TypeDeclaration>();

            using (var script = context.StartScript()) {
                var astBuilder = context.CreateTypeSystemAstBuilder(typeDecl.FirstChild);
                var fieldDecl  = new FieldDeclaration();
                fieldDecl.Modifiers  = TypeSystemAstBuilder.ModifierFromAccessibility(accessibility);
                fieldDecl.ReturnType = astBuilder.ConvertType(context.Compilation.Import(fieldType));
                fieldDecl.Variables.Add(new VariableInitializer(name));
                script.InsertWithCursor("Add field: " + name, Script.InsertPosition.End, fieldDecl);
            }
        }