mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-25 22:59:28 -05:00
* Don't try to wrap a setter if there is no setter to wrap, same for getters * Add some properties to test data that will definitely cause tests to fail
83 lines
1.2 KiB
C#
83 lines
1.2 KiB
C#
using Sandbox;
|
|
using System;
|
|
|
|
[AttributeUsage( AttributeTargets.Property )]
|
|
[CodeGenerator( CodeGeneratorFlags.WrapPropertyGet | CodeGeneratorFlags.Instance, "OnWrapGet" )]
|
|
[CodeGenerator( CodeGeneratorFlags.WrapPropertyGet | CodeGeneratorFlags.Static, "WrapGet.OnWrapGetStatic" )]
|
|
public class WrapGet : Attribute
|
|
{
|
|
public static T OnWrapGetStatic<T>( WrappedPropertyGet<T> p )
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public class MyTestClass
|
|
{
|
|
|
|
}
|
|
|
|
public partial class TestWrapGet
|
|
{
|
|
[WrapGet]
|
|
public static bool StaticProperty { get; set; }
|
|
|
|
[WrapGet]
|
|
public bool InstanceProperty { get; set; } = true;
|
|
|
|
[WrapGet]
|
|
public bool Test
|
|
{
|
|
get
|
|
{
|
|
return true;
|
|
}
|
|
set
|
|
{
|
|
InstanceProperty = true;
|
|
}
|
|
}
|
|
|
|
private bool _hasNoGetterToWrap;
|
|
|
|
[WrapGet]
|
|
public bool HasNoGetterToWrap
|
|
{
|
|
set
|
|
{
|
|
_hasNoGetterToWrap = true;
|
|
}
|
|
}
|
|
|
|
[WrapGet]
|
|
public MyTestClass InstanceProperty2 { get; }
|
|
|
|
internal T OnWrapGet<T>( WrappedPropertyGet<T> p )
|
|
{
|
|
return p.Value;
|
|
}
|
|
|
|
[WrapGet]
|
|
public bool FieldKeywordProperty
|
|
{
|
|
set
|
|
{
|
|
field = value;
|
|
}
|
|
get
|
|
{
|
|
return field;
|
|
}
|
|
}
|
|
|
|
[WrapGet]
|
|
public bool FieldKeywordPropertyAuto
|
|
{
|
|
set
|
|
{
|
|
field = value;
|
|
}
|
|
get;
|
|
}
|
|
}
|