CPF/CPF.Mac/Mac/Foundation/ExportAttribute.cs
2023-11-21 23:05:03 +08:00

79 lines
1.3 KiB
C#

using CPF.Mac.ObjCRuntime;
using System;
using System.Reflection;
namespace CPF.Mac.Foundation
{
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property)]
public class ExportAttribute : Attribute
{
private string selector;
private ArgumentSemantic semantic;
public string Selector
{
get
{
return selector;
}
set
{
selector = value;
}
}
public ArgumentSemantic ArgumentSemantic
{
get
{
return semantic;
}
set
{
semantic = value;
}
}
public bool IsVariadic
{
get;
set;
}
public ExportAttribute()
{
}
public ExportAttribute(string selector)
{
this.selector = selector;
semantic = ArgumentSemantic.None;
}
public ExportAttribute(string selector, ArgumentSemantic semantic)
{
this.selector = selector;
this.semantic = semantic;
}
public ExportAttribute ToGetter(PropertyInfo prop)
{
if (string.IsNullOrEmpty(Selector))
{
Selector = prop.Name;
}
return new ExportAttribute(selector, semantic);
}
public ExportAttribute ToSetter(PropertyInfo prop)
{
if (string.IsNullOrEmpty(Selector))
{
Selector = prop.Name;
}
return new ExportAttribute($"set{char.ToUpperInvariant(selector[0])}{selector.Substring(1)}:", semantic);
}
}
}