Main
поймать нельзя.Exception
и указывая параметры исключений /// <summary>
/// Localized exception
/// </summary>
/// <param name="stringId">i18n string Id</param>
/// <param name="args">String arguments for format</param>
public class I18nException(string stringId, object[] args)
: Exception(
string.Format(
I18n($"{ExceptionId} {stringId}"),
args))
{
public readonly object[] Args = args;
public readonly string StringId = stringId;
private const string ExceptionId = "Exception";
}
public class ElementNotFoundException(Type type, string name)
: I18nException(
"Element not found",
[type.FullName, name]
)
{
public readonly string ElementName = name;
public readonly Type ElementType = type;
}
(тыц). перевод игры лежит в отдельном файле(например json и хранит в себе каждую строчку текста, которая применяется в игре), и потом в коде запрашивать нужную строку из файла и брать от туда значение текста для последующего применения на сцене
или есть способы попроще
public static class Native
{
[DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hwnd, ref RECT rectangle);
[DllImport("user32.dll")]
private static extern bool GetClientRect(IntPtr hwnd, ref RECT rectangle);
public RECT GetWindowPos(IntPtr hwnd)
{
var r = new RECT();
GetWindowRect(hwnd, ref r);
return r;
}
public RECT GetClientPos(IntPtr hwnd)
{
var r = new RECT();
GetClientRect(hwnd, ref r);
return r;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct RECT(int left, int top, int right, int bottom)
{
public int Left = left;
public int Top = top;
public int Right = right;
public int Bottom = bottom;
public readonly int Width => Right - Left;
public readonly int Height => Bottom - Top;
}
}
RenderSize
и ActualWidth/ActualHeight
будут после вычисления положения самого элемента. Скорее всего вы слишком рано пытаетесь получить к ним доступ. Запустите ваше приложение и в отладчике посмотрите в дереве окон значения.public class MyControl : Control
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
// Размеры и позиция элемента вычислены и он готов к работе
}
}
using System.Reflection;
namespace ConsoleAppTest
{
public static class Program
{
private static void Main(string[] args)
{
Test obj = new() { Prop1 = "Prop1 Value" };
// Получаем тип объекта
Type objType = typeof(Test);
// Получаем список интерфейсов
Type[] interfaces = objType.GetInterfaces();
foreach (Type iface in interfaces)
{
// Получаем список свойств интерфейса
PropertyInfo[] ifaceProperties = iface.GetProperties();
foreach (PropertyInfo prop in ifaceProperties)
{
// Ищем нужный аттрибут в свойстве
Attribute? attribute = prop.GetCustomAttribute<TestAttribute>();
if (attribute != null)
{
// Получаем значение свойства
object? propValue = prop.GetValue(obj); // -> Prop1 Value
}
}
}
}
}
[AttributeUsage(AttributeTargets.Property)]
public sealed class TestAttribute : Attribute
{ }
internal sealed class Test : ITest
{
public string Prop1 { get; set; } = string.Empty;
}
internal interface ITest
{
[Test]
public string Prop1 { get; set; }
}
}
public class Foo
{
public virtual void Update()
{
Console.WriteLine("Foo->Update()");
}
}
public class Bar : Foo
{
public override void Update()
{
base.Update();
Console.WriteLine("Bar->Update()");
}
}