Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何克隆Nest';我自己的方法的s[String(Ignore)]属性_C#_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Nest_Custom Attributes - Fatal编程技术网 elasticsearch,nest,custom-attributes,C#,elasticsearch,Nest,Custom Attributes" /> elasticsearch,nest,custom-attributes,C#,elasticsearch,Nest,Custom Attributes" />

C# 如何克隆Nest';我自己的方法的s[String(Ignore)]属性

C# 如何克隆Nest';我自己的方法的s[String(Ignore)]属性,c#,elasticsearch,nest,custom-attributes,C#,elasticsearch,Nest,Custom Attributes,我正在尝试为保存进程日志的方法克隆Nest的[String(Ignore)]属性。我已经做了一些事情,但它不起作用 基本上,我想做的是,我想创建一个自定义属性,让我选择是否将属性保存到elasticsearch 因此,我有一个SaveUserProcessLog方法。 然后我创建一个名为MyProcessLogDetailAttribute的自定义属性,该属性从嵌套的StringAttribute继承: [AttributeUsage(AttributeTargets.Property)] pu

我正在尝试为保存进程日志的方法克隆Nest的
[String(Ignore)]
属性。我已经做了一些事情,但它不起作用

基本上,我想做的是,我想创建一个自定义属性,让我选择是否将属性保存到elasticsearch

因此,我有一个
SaveUserProcessLog
方法。 然后我创建一个名为
MyProcessLogDetailAttribute
的自定义属性,该属性从嵌套的
StringAttribute
继承:

[AttributeUsage(AttributeTargets.Property)]
public class MyUserProcessLogDetailAttribute : StringAttribute
{
    public MyUserProcessLogDetailAttribute(bool SaveProperty)
    {
        Ignore = !SaveProperty; //when true, ignore is false
    }
}
我将这个属性添加到我想要保存的属性中

[MyUserProcessLogDetail(SaveProperty:false)]
public Guid UserCode { get; set; }

[MyUserProcessLogDetail(SaveProperty:false)]
public string FullName { get; set; }
继承Nest的属性方法正确吗

为什么我不使用Nest的原始
[String(Ignore=false/true)]
属性是因为我可能想创建一个新属性来保存另一个方法的属性。例如,不要为
UserProcessLog()
方法保存
UserCode
,而是为
SaveUserAmendments()
保存


我希望我已经清楚了这一点。

我不明白这是用
[String(Ignore=true)]
来收买你的?对于派生属性,您仍然需要传递
true/false
,因此它在语义上与
StringAttribute
@RussCam的工作原理相同。例如,我不想将UserCode存储到elastic ProcessLog类型,而我可能想将其保存到elastic UserLog类型。如果我使用
[String(Ignore=true)]
Nest将始终忽略它。所以我需要创建两个不同的自定义属性。或者我可以像这样使用
[String(Ignore=true,TypeName=“UserLog”)]
[String(Ignore=false,TypeName=“ProcessLog”)]
?如果您有两个具有相同属性的模型,它们必须以不同的方式映射,那么我会对它们使用流畅的映射,而不是属性。看看