我正在开发全文索引方面,现在我可以将属性指定为全文索引。
但是,我接下来要做的是在SQL全文索引语法中指定“ TYPE COLUMN xx”,其中“ xx”是同一实体的另一个属性。
为此,我想问一下CodeFluent方面,如何设置它以提供方面输入的当前实体所有其他持久属性的下拉列表?
这是我到目前为止拥有的CodeFluent Aspect XML代码:
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进行下拉,但似乎不起作用。 “类型列”显示为灰色,并带有一个黑框。
我可能做错了。
我的自定义UITypeEditor类如下:
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”。
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>");
}
最佳答案
您可以做的是在描述符中添加xml属性,以定义自定义TypeConverter类型名称,例如:
<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中),例如这样的示例:
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.dll
,CodeFluent.Model.Common.dll
和CodeFluent.Model.dll
(通常从C:\Program Files (x86)\SoftFluent\CodeFluent\Modeler
开始)。您需要将包含此转换器的
ClassLibrary1.dll
复制到IDE可以从中加载它的Visual Studio,例如在Visual Studio 2015的C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
中。请注意,如果您在代码中定义了方面,则可以将此转换器类放在同一DLL中,但是始终需要将其复制到Visual Studio目录中。
重新启动Visual Studio,您应该在Visual Studio属性网格中看到以下内容:
如注释中所述,如果您需要更高级的编辑(并使用'
editorTypeName
'XML属性而不是'typeConverterTypeName
'属性),则也可以使用相同的原理创建UITypeEditor,但对于字符串列表。关于codefluent - CodeFluent方面:如何使用实体属性设置下拉输入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36856950/