Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.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#在单独的程序集中保留自定义属性_C#_.net Assembly - Fatal编程技术网

c#在单独的程序集中保留自定义属性

c#在单独的程序集中保留自定义属性,c#,.net-assembly,C#,.net Assembly,我有使用这些属性的自定义属性和类。选择“类对象”时,这些属性将用于特性网格。当前,类和属性都在同一程序集中。在属性中,我有一些表单对象。由于这些表单对象,我希望将属性保留在单独的程序集中。但是,它会导致循环引用。你能帮我解决这个问题吗 样本: 我有一个业务对象,其属性可以显示在PropertyGridControl中: public class Field { public Field() { } private

我有使用这些属性的自定义属性和类。选择“类对象”时,这些属性将用于特性网格。当前,类和属性都在同一程序集中。在属性中,我有一些表单对象。由于这些表单对象,我希望将属性保留在单独的程序集中。但是,它会导致循环引用。你能帮我解决这个问题吗

样本:

我有一个业务对象,其属性可以显示在PropertyGridControl中:

    public class Field
    {
        public Field()
        {

        }

        private int _Type;

        [CustomPropertyEditorMarker(typeof(RepositoryItemForFieldDataType))]
        public int Type
        {
            get { return _Type; }
            set
            {
                _Type = value;
            }
        }
    }

    [AttributeUsage(AttributeTargets.Property)]
    public sealed class CustomPropertyEditorMarker : Attribute
    {
        public CustomPropertyEditorMarker(Type editorType)
        {
            EditorType = editorType;
        }

        public readonly Type EditorType;
    }

    public sealed class RepositoryItemForFieldDataType : RepositoryItemLookUpEdit
    {
        public RepositoryItemForFieldDataType()
        {
                // Populating LookupEdit details here
        }

        private void On_ButtonClick()
        {
            // Here initializing existing Form class and show it
        }
    }

When Field object is selected, PropertGridControl analyze selected object and checking which property has above Attribute. If yes, then initialize it.

        private void SelectObject(object obj)
        {
            this.Rows.Clear();
            this.DefaultEditors.Clear();
            this.RepositoryItems.Clear();

            if ((this.LastSelectedObject as ApplicationDomainItemBase) != null)
            {
                (this.LastSelectedObject as ApplicationDomainItemBase).IsSelected = false;
            };

            this.SelectedObject = null;

            this.SelectedObject = obj;

            if (!(this.SelectedObject is ConfigurationObjectManagerBase))
            {
                foreach (var propInfo in this.SelectedObject.GetType().GetProperties())
                {
                    object[] objFieldAtts = propInfo.GetCustomAttributes(typeof(CustomPropertyEditorMarker), true);

                    if (objFieldAtts != null && objFieldAtts.Length > 0)
                    {
                        if (this.GetRowByFieldName(propInfo.Name) != null)
                        {
                            RepositoryItem repItem = Activator.CreateInstance(((CustomPropertyEditorMarker)objFieldAtts[0]).EditorType) as RepositoryItem;
                            this.GetRowByFieldName(propInfo.Name).Properties.RowEdit = repItem;
                        };
                    };
                };
            };

            this.LastSelectedObject = obj;
        }

目前,业务对象类和属性都在同一个程序集中,需要将它们分开。但是我不能,因为业务对象属性用属性名修饰,需要添加引用。无法添加引用,因为属性类引用了业务对象类。希望一切都清楚。谢谢。

在没有看到导致您出现问题的业务对象引用的情况下,一般回答如下:


将业务对象基于接口,这些接口将在要移动属性的同一程序集中声明,或者在另一个“基本”程序集中声明。然后通过属性的接口引用属性中的业务对象。

为什么要移动属性的项目引用使用这些属性的项目?您能提供更多关于您的依赖关系的详细信息吗?@user3185569,请查看编辑。谢谢。我在示例代码中只看到一个属性类,它没有引用任何其他类。我错过了什么。我看不出是什么阻止您将该属性类移动到单独的程序集,然后从包含域对象的项目中引用该程序集。