質問

い機能を加えたプロジェクトで、ユーザーの追加をよびユーザーインターフェイス特性をオブジェクト。私が自分のカスタム TypeDescriptor, PropertyDescriptorTypeDescriptorProviders す。す。関係ではないかと思います。

こちらの私の課題です。今まで働くかを作り分 TypeDescriptionProvider 各オブジェクトオブジェクトタイプのカスタム。ここでは、私の TypeDescriptionProviders のように見え

//type AClass Custom Provider
class AClassTypeProvider : TypeDescriptionProvider
{
    private static TypeDescriptionProvider defaultTypeProvider = TypeDescriptor.GetProvider(typeof(AClass));

    public AClassTypeProvider (): base(defaultTypeProvider)
    {

    }

    public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
    {
        ICustomTypeDescriptor defaultDescriptor = base.GetTypeDescriptor(objectType, instance);

        //returns a custom type descriptor based on a UserPropertyHostType enum value, and the default descriptor
        return new InfCustomTypeDescriptor(UserPropertyHostType.SiteRegion, defaultDescriptor);
    }
}


//type BClass Custom Provider
class BClassTypeProvider : TypeDescriptionProvider
{
    private static TypeDescriptionProvider defaultTypeProvider =   TypeDescriptor.GetProvider(typeof(BClass));

    public BClassTypeProvider (): base(defaultTypeProvider)
    {

    }

    public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
    {
        ICustomTypeDescriptor defaultDescriptor = base.GetTypeDescriptor(objectType, instance);

        //returns a custom type descriptor based on a UserPropertyHostType enum value, and the default descriptor
        return new InfCustomTypeDescriptor(UserPropertyHostType.Building, defaultDescriptor);
    }
}

それぞれのカスタム TypeDescriptionProviders 通話の ベース(TypeDescriptionProvider親会) ベースのコンストラクタにより広い範囲にわたってデフォルトの TypeDescriptionProvider 特定のタイプです。

GetTypeDescriptor() メソッドの呼び出し ます。GetTypeDescriptor() のデフォルトの記述子を使っているカスタムタイプの記述子を追加、カスタム。

あるものを自由に組み合わせることを単一の汎用カスタム TypeDescriptionProvider と同じ機能をもに縛られない特定のタイプ?できますかスキップの提供の親会社 TypeDescriptionProvider このコンストラクタが設定で GetTypeDescriptor() 方法がんでは、具体的には、どのような型のオブジェクトが照会される?やはりその他の多種多様なレストランがたくさんのデフォルトの記述子の型の次の呼び出し ます。GetTypeDescriptor(シリコーンコーティング処理、オブジェクトins) 方法は?

正しい解決策はありません

他のヒント

この汎用的なクラスなん:

class CustomTypeProvider<T> : TypeDescriptionProvider
{
    private static TypeDescriptionProvider defaultTypeProvider = TypeDescriptor.GetProvider(typeof(T));

    public CustomTypeProvider(): base(defaultTypeProvider)
    {

    }

    public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
    {
        ICustomTypeDescriptor defaultDescriptor = base.GetTypeDescriptor(objectType, instance);

        //returns a custom type descriptor based on a UserPropertyHostType enum value, and the default descriptor
        return new InfCustomTypeDescriptor(UserPropertyHostType.SiteRegion, defaultDescriptor);
    }
}

って取り扱うことは過去に利用汎用タイプ:

public class MyTypeDescriptionProvider<T> : TypeDescriptionProvider
{
  public MyTypeDescriptionProvider()
    : base(TypeDescriptor.GetProvider(typeof(T)))
  {
  }
}

いす対応できるので同様に非汎用型を型としてのコンストラクタのパラメータ:

public class MyTypeDescriptionProvider : TypeDescriptionProvider
{
  public MyTypeDescriptionProvider(Type t)
    : base(TypeDescriptor.GetProvider(t))
  {
  }
}

ことが好ましい必要がない場合に使用タイプのプロバイダ--な試験があります。

その後の使用時にこのプロバイダクラスの登録をとってい:

TypeDescriptor.AddProvider(new MyTypeDescriptionProvider<ClassA>(), typeof(ClassA));
TypeDescriptor.AddProvider(new MyTypeDescriptionProvider<ClassB>(), typeof(ClassB));

など。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top