2
我有自定義屬性和使用這些屬性的類。當選擇類對象時,這些屬性用於屬性網格。目前,這兩個類和屬性都在同一個程序集中。在屬性內我有一些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,請參閱編輯。謝謝。 – Tim
我只在示例代碼中看到一個屬性類,它不引用任何其他類。我錯過了什麼。我沒有看到阻止你將該屬性類移動到單獨的程序集,然後從包含域對象的項目中引用該程序集。 – wablab