Skip to main content
All docs
V24.2

BindToTypePolicy.QueryBindToType Event

Allows you to spot dynamic loading of a type, check its name and assembly, and allow the type resolve operation.

Namespace: DevExpress.Utils

Assembly: DevExpress.Data.v24.2.dll

Declaration

public static event BindToTypePolicy.WeakEventHandler<BindToTypePolicy.QueryBindToTypeEventArgs> QueryBindToType

Event Data

The QueryBindToType event's data class is BindToTypePolicy.QueryBindToTypeEventArgs. The following properties provide information specific to this event:

Property Description
Assembly Gets the assembly that contains the processed type.
AssemblyName Gets the assembly name. Inherited from BindToTypePolicy.BindToTypeBaseQueryArgs.
AssemblyQualifiedTypeName Gets the assembly-qualified name of the type, which includes the name of the assembly from which this Type object is being loaded.
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
IsKnownType Gets whether the type is whitelisted (the type is safe). Inherited from BindToTypePolicy.BindToTypeBaseQueryArgs.
QueryLevel This member supports the internal infrastructure and is not intended to be used directly from your code. Inherited from BindToTypePolicy.BindToTypeBaseQueryArgs.
Type Gets or sets the type.
TypeName Gets the type name.

The event data class exposes the following methods:

Method Description
ToString() Returns a string in the following format: “Query Level: {QueryLevel.ToString()}, Requested Type: {AssemblyQualifiedTypeName}”.

Remarks

The BindToTypePolicy fires the QueryBindToType event every time DevExpress UI controls call the Type.GetType() method.

namespace DXApplication {
    internal static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            DevExpress.Utils.BindToTypePolicy.QueryBindToType += BindToTypePolicy_QueryBindToType;
            Application.Run(new Form1());
        }
        private static void BindToTypePolicy_QueryBindToType(object sender, DevExpress.Utils.BindToTypePolicy.QueryBindToTypeEventArgs e) {
            if (!e.IsKnownType) {
                // Resolves custom datasource types for DevExpress Reports.
                if (e.TypeName == "ProductsJsonDataSource")
                    e.Type = typeof(ProductsJsonDataSource);
                if (e.TypeName == "UsersJsonDataSource")
                    e.Type = typeof(UsersJsonDataSource);
            }
        }
    }
}

Note

Handle the QueryNonTrustedTypeValidation event to validate blacklisted and “unknown” types. The policy does not fire this event to whitelisted/trusted types.

Read the following topic for more information and examples: Safe Deserialization – How to Resolve Unknown Data Types.

See Also