Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DependencyObjectGenerator does not support generic classes #19540

Open
kazo0 opened this issue Feb 17, 2025 · 0 comments
Open

DependencyObjectGenerator does not support generic classes #19540

kazo0 opened this issue Feb 17, 2025 · 0 comments
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification

Comments

@kazo0
Copy link
Contributor

kazo0 commented Feb 17, 2025

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

@kazo0 kazo0 added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification area/code-generation Categorizes an issue or PR as relevant to code generation labels Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
Development

No branches or pull requests

1 participant