これらの属性を使用するカスタム属性とクラスがあります。これらの属性は、クラスオブジェクトが選択されたときにプロパティグリッドに使用されます。現在、クラスと属性は同じアセンブリ内にあります。属性内にはいくつかのFormオブジェクトがあります。これらのフォームオブジェクトのため、私は別のアセンブリに属性を保持したい。しかし、それは循環参照となる。この問題について私を助けてください。c#別のアセンブリでカスタム属性を保持する
サンプル:
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;
}
現在、両方のビジネス・オブジェクト・クラスと属性の同じアセンブリ内にあり、それらを分離する必要があります。
私はプロパティPropertyGridControlに表示できるビジネス・オブジェクトを持っています。しかし、私はできません。なぜなら、ビジネスオブジェクトのプロパティは属性名で装飾されており、参照を追加する必要があるからです。属性クラスはビジネス・オブジェクト・クラスを参照するため、参照を追加することはできません。それは明らかです。ありがとう。
なぜ属性を移動するプロジェクトが、これらの属性を使用するプロジェクトを参照していますか?依存関係の詳細を教えてください。 – user3185569
@ user3185569、plsに編集が表示されます。ありがとう。 – Tim
サンプルコードでは1つの属性クラスのみが表示され、他のクラスは参照されていません。私は何が欠けている。その属性クラスを別のアセンブリに移動してから、ドメインオブジェクトを含むプロジェクトからそのアセンブリを参照することを止めているものはありません。 – wablab