コード例 #1
0
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return(false);
            }

            IConstructEnumerable <IFieldDeclaration> fields = FindFields(fileModel, selection);

            return(fields.Exist() && ImplementsINotifyPropertyChanged(fields.First().EnclosingClass));
        }
コード例 #2
0
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IConstructEnumerable <IFieldDeclaration> fields = FindFields(fileModel, selection);

            if (fields.Exist())
            {
                IConstructLanguage language = fields.Language;

                foreach (IFieldDeclaration field in fields)
                {
                    IPropertyDeclaration property = language.Property(
                        language.None <IDocComment>(),
                        language.None <IAttributes>(),
                        language.Modifiers(Modifiers.Public),
                        language.TypeName(field.TypeName.Type),
                        language.None <IIdentifier>());

                    NamingPolicy propertyNamingPolicy = property.PrimaryNamingPolicy(fileModel.UserSettings);
                    string       propertyName         = propertyNamingPolicy.MakeMemberNameUniqueInScope(field, field.Identifier.Name);

                    property.Identifier = language.Identifier(propertyName);

                    IAccessor getter = language.FieldGetter(field.Identifier);
                    IAccessor setter = CreateSetter(language, propertyName, field);

                    property.Accessors = language.Enumerable(new List <IAccessor>()
                    {
                        getter, setter
                    });

                    field.EnclosingClass.Insert(property);
                }
            }
        }