이러한 특성을 사용하는 사용자 지정 특성 및 클래스가 있습니다. 이러한 속성은 클래스 객체가 선택 될 때 속성 격자에 사용됩니다. 현재 클래스와 속성은 모두 동일한 어셈블리에 있습니다. 속성 내에서 일부 Form 객체가 있습니다. 이러한 Form 개체 때문에 별도의 어셈블리에 특성을 유지하려고합니다. 그러나 그것보다는 순환 참조가 발생합니다. 이 문제에 대해 저를 도울 수 있습니까?C# 별도의 어셈블리에 사용자 지정 특성 유지
샘플 :
내가 누구의 재산 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
@ user3185569, pls 수정 사항을 참조하십시오. 감사. – Tim
예제 코드에서 하나의 특성 클래스 만보고 다른 클래스를 참조하지 않습니다. 나는 무엇이 없는가. 이 특성 클래스를 별도의 어셈블리로 이동 한 다음 도메인 개체가 포함 된 프로젝트에서 해당 어셈블리를 참조하는 것을 막을 수는 없습니다. – wablab