Skip to content

DependencyObjectGenerator does not support generic classes #19540

Open
@kazo0

Description

@kazo0

Current behavior

Defining a public partial class MyClass<T> : DependencyObject results in generating something like:

public object DataContext
{
	get => GetValue(DataContextProperty);
	set => SetValue(DataContextProperty, value);
}

// Using a DependencyProperty as the backing store for DataContext.  This enables animation, styling, binding, etc...
public static DependencyProperty DataContextProperty { get ; } =
	DependencyProperty.Register(
		name: nameof(DataContext),
		propertyType: typeof(object),
		ownerType: typeof(MyClass),
		typeMetadata: new FrameworkPropertyMetadata(
			defaultValue: null,
			options: FrameworkPropertyMetadataOptions.Inherits,
			propertyChangedCallback: (s, e) => ((MyClass)s).OnDataContextChanged(e)
		)
);

And a build error stating

error CS0305: Using the generic type 'MyClass' requires 1 type arguments

Workaround

Can get the build to pass by adding an empty non-generic MyClass definition that inherits from DependencyObject:
public partial class MyClass<T> : DependencyObject { }

UnoApp139.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/code-generationCategorizes an issue or PR as relevant to code generationdifficulty/tbdCategorizes an issue for which the difficulty level needs to be defined.kind/bugSomething isn't workingtriage/untriagedIndicates an issue requires triaging or verification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions