首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CodeFluent方面:如何使用实体属性设置DropDown输入

CodeFluent方面:如何使用实体属性设置DropDown输入
EN

Stack Overflow用户
提问于 2016-04-26 14:32:19
回答 1查看 71关注 0票数 3

我正在开发一个全文索引方面,并且可以将属性指定为全文索引。

然而,我想做的下一件事是在SQL全文索引语法中指定"TYPE COLUMN xx",其中"xx“是同一实体的另一个属性。

为此,我想问一下CodeFluent方面,如何将其设置为为方面输入的当前实体提供所有其他持久化属性的下拉列表?

下面是我到目前为止获得的CodeFluent方面XML代码:

代码语言:javascript
复制
        static FullTextIndexing()
        {
            Descriptor = new XmlDocument();
            Descriptor.LoadXml(
@"<cf:project xmlns:cf='http://www.softfluent.com/codefluent/2005/1' defaultNamespace='FullTextIndexing'>
    <cf:pattern name='Full Text Indexing' namespaceUri='" + NamespaceUri + @"' preferredPrefix='ftind' step='Tables'>
        <cf:message class='_doc'>CodeFluent Full Text Indexing Aspect</cf:message>
        <cf:descriptor name='fullTextIndex'
            typeName='boolean'
            category='Full Text Index'
            targets='Property'
            defaultValue='false'
            displayName='Full-Text Index'
            description='Determines if property should be a full text index.' />
        <cf:descriptor name='fullTextIndexTypeColumn'
            typeName='text'
            category='Full Text Index'
            targets='Property'
            displayName='Type Column'
            description='The type column for the full text index.' />
    </cf:pattern>
</cf:project>");
        }

这给了我一个“文本框”。我想要的是同一实体的其他属性的下拉列表。

编辑一个:

我尝试使用UITypeEditor创建下拉菜单,但似乎不起作用。"Type Column“是灰色的,并且它有一个黑框。

我可能做错了什么。

我的自定义UITypeEditor类如下所示:

代码语言:javascript
复制
namespace CodeFluent.Aspects.AspectEditors
{
    public class OtherPropertyDropDownEditor : UITypeEditor
    {
        private IWindowsFormsEditorService _editorService;
        
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            // drop down mode (we'll host a listbox in the drop down)
            return UITypeEditorEditStyle.DropDown;
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            _editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            // use a list box
            ListBox lb = new ListBox();
            lb.SelectionMode = SelectionMode.One;
            lb.SelectedValueChanged += delegate
            {
                // close the drop down as soon as something is clicked
                _editorService.CloseDropDown();
            };

            // use the Property.Name property for list box display
            lb.DisplayMember = "Name";

            // this is how we get the list of possible properties
            IEnumerable<Property> otherProperties = GetOtherPersistentProperties(context);
            foreach (Property otherProperty in otherProperties)
            {
                int index = lb.Items.Add(otherProperty);
                if (otherProperty.Equals(value))
                {
                    lb.SelectedIndex = index;
                }
            }


            // show this model stuff
            _editorService.DropDownControl(lb);
            if (lb.SelectedItem == null) // no selection, return the passed-in value as is
                return value;

            return lb.SelectedItem;
        }

        private IEnumerable<Property> GetOtherPersistentProperties(ITypeDescriptorContext context)
        {
            // context is of type ITypeDescriptorContext, got from EditValue overloads.
            var property = TypeNameEditor.GetObject<Property>(context);

            IEnumerable<Property> otherEntityProperties = null;
            if (property != null && property.Entity != null)
                otherEntityProperties = property.Entity.Properties.Where(p => p.IsPersistent && p != property);
            return otherEntityProperties;
        }
    }
}

到目前为止,我拥有的XML是这样的。注意,我添加了"editorTypeName“。

代码语言:javascript
复制
        static FullTextIndexing()
        {
            Descriptor = new XmlDocument();
            Descriptor.LoadXml(
@"<cf:project xmlns:cf='http://www.softfluent.com/codefluent/2005/1' defaultNamespace='FullTextIndexing'>
    <cf:pattern name='Full Text Indexing' namespaceUri='" + NamespaceUri + @"' preferredPrefix='ftind' step='Tables'>
        <cf:message class='_doc'>CodeFluent Full Text Indexing Aspect</cf:message>
        <cf:descriptor name='fullTextIndex'
            typeName='boolean'
            category='Full Text Index'
            targets='Property'
            defaultValue='false'
            displayName='Full-Text Index'
            description='Determines if property should be a full text index.' />
        <cf:descriptor name='fullTextIndexTypeColumn'
            category='Full Text Index'
            targets='Property'
            editorTypeName='CodeFluent.Aspects.AspectEditors.OtherPropertyDropDownEditor, CodeFluent.Aspects.AspectEditors.OtherPropertyDropDownEditor, CodeFluent.Aspects.AspectEditors'
            displayName='Type Column'
            description='The type column for the full text index.'
            />
    </cf:pattern>
</cf:project>");
        }
EN

回答 1

Stack Overflow用户

发布于 2016-04-28 07:17:58

您可以做的是将xml属性添加到您的描述符中,以定义自定义TypeConverter类型名称,例如:

代码语言:javascript
复制
<cf:descriptor name='fullTextIndexTypeColumn'
            typeName='text'
            category='Full Text Index'
            targets='Property'
            displayName='Type Column'
            description='The type column for the full text index.'
            typeConverterTypeName='ClassLibrary1.MyAspectConverter, ClassLibrary1'
            />

然后,您需要实现MyAspectConverter类(这里在ClassLibrary1.dll中),例如:

代码语言:javascript
复制
public class MyAspectConverter : StringConverter
{
    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    {
        return true;
    }

    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    {
        var list = new List<string>();
        var property = TypeNameEditor.GetObject<Property>(context);
        if (property != null && property.Entity != null)
        {
            list.AddRange(property.Entity.Properties.Where(p => p.IsPersistent).Select(p => p.Name));
        }
        return new StandardValuesCollection(list);
    }
}

ClassLibrary1需要引用CodeFluent.Runtime.dllCodeFluent.Model.Common.dllCodeFluent.Model.dll (通常来自C:\Program Files (x86)\SoftFluent\CodeFluent\Modeler)。

您需要将包含此转换器的ClassLibrary1.dll复制到Visual Studio,以便集成开发环境可以从中加载它,例如,在Visual Studio2015的C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE中。

注如果您在代码中定义方面,则可以将此转换器类放在同一DLL中,但您始终需要将其复制到Visual Studio目录中。

重新启动Visual Studio,您应该会在Visual Studio属性网格中看到类似以下内容:

正如注释中所述,如果需要更高级的编辑(使用“editorTypeName”XML属性而不是“typeConverterTypeName”属性),也可以使用相同的原则创建UITypeEditor,但字符串列表不需要该属性。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36856950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档