-
Notifications
You must be signed in to change notification settings - Fork 30
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
Potentially change structure of Razer.Devices #180
Comments
A way to implement this that would require less drastic changes in the current usage of GUIDs could be to add the names as attributes on the Guid fields like this: public static class Devices
{
[DeviceName("Some Device")]
public static readonly Guid SomeDevice = new Guid(/* ... */);
} Thoughts? |
So, here's how you could get the DeviceName from the attribute, unless I'm missing something... Set the name [PublicAPI]
[DeviceName("BlackWidow")]
public static readonly Guid Blackwidow = new Guid(
0x2ea1bb63,
0xca28,
0x428d,
0x9f,
0x06,
0x19,
0x6b,
0x88,
0x33,
0x0b,
0xbb); Create the attribute internal class DeviceNameAttribute : Attribute
{
private string DeviceName;
public DeviceNameAttribute(string name)
{
this.DeviceName = name;
}
public string Name
{
get
{
return DeviceName;
}
}
} Retrieve the name from the Guid public static string GetName(Guid id)
{
var fields = typeof(Devices).GetFields();
foreach (var field in fields)
{
if ((Guid)field.GetValue(null) == id)
{
var attr = (DeviceNameAttribute)field.GetCustomAttributes(typeof(DeviceNameAttribute), false)[0];
return attr.Name;
}
}
return null;
} |
Custom attribute is useful if we want to give the full name i.e "BlackWidow Tournament Edition", but if we literally just want to find out the field name, we can do this without using a new attribute: public static string GetName(Guid id)
{
var fields = typeof(Devices).GetFields();
foreach (var field in fields)
{
if ((Guid)field.GetValue(null) == id)
{
return field.Name;
}
}
return null;
} |
Moving this to v6.1. I'm thinking adding two methods: |
This was implemented early, in bd61119. |
I've been thinking about this for a while now, but if you have a GUID of a device, it's quite difficult to get a string friendly version of the field name that matches.
This would be particularly useful for #145
This is literally just a rough thinking, and I know it won't be the right solution, but I've remedied this with:
I also know that this would be a major change, but I just wanted to see what you guys thought about this?
The text was updated successfully, but these errors were encountered: