Jump to content
The simFlight Network Forums

swemaniac

Members
  • Posts

    10
  • Joined

  • Last visited

Profile Information

  • Gender
    Male
  • Location
    Sweden

swemaniac's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Hey thanks Paul, I really appreciate it!
  2. Sorry, yes. The scenario I'm referring to is basically this: // creating the offset var offset = new Offset(123, 4); // or var offset = new Offset<int>(123); // somewhere else, getting the value back of a type that's determined at runtime internal object GetInternalOffsetValue(int address, Type type) return offset.GetValue(type); Does it make sense to you to add that method? The GetValue<T> is still very useful to me, it's just I need the non-generic method as well to make this work.
  3. Paul, I'm missing the thing that was going to help me access offset values at runtime without knowing the underlying type. I.e. I know the type I need to access, but i can't use `T` at runtime. I need to be able to get an `object` (as explained above in my examples) so that I can convert it to a type. E.g. `Convert.ChangeType(offset.GetValue(), type)` (where type is for instance, typeof(int)). Could you perhaps include a non-generic version of the `GetValue` method that returns the value T as an `object`?
  4. Thank you for your work Paul, I'll try it out tonight! Looks great.
  5. Yes sure, please go for it :) Thanks again.
  6. Thanks Paul! I like the idea of a more "raw" offset object that's untyped. How about "Offset(address, length)" with "T Get<T>" and "object Get(Type)" or something to accommodate both generics and non-generics users? I think it's pretty common to see overloads for "Type" methods wherever there's a generic method/class. You could still have the helper methods GetInt32() etc, but I prefer giving a type (again, easier in runtime). Then we could do: var offset = new Offset(0x345, 10); byte[] raw = offset.Value; string val = offset.Get<string>(); string val2 = (string)offset.Get(typeof(string));
  7. Ok sure. I've created a local/private nuget package that I can consume in the meantime, but it'd be nice to have an official package whenever you have the time for it.
  8. Hi, Thank you I appreciate your input and you got a valid point, and I can explain why making IOffset public would make life easier for me if it interests you: Consider a simple dictionary of offset addresses and offsets. Right now it has to be declared as such: readonly IDictionary<int, object> Offsets = new Dictionary<int, object>(); (As there are no common public denominator). Could be done with dynamic as well. Then consider the method needed to retrieve an Offset<T> value from that dictionary. The easy implementation is if T is known (compile time): T GetOffsetValue<T>(int address) { object offset; if (Offsets.TryGetValue(address, out offset)) { if (offset is Offset<T>) return ((Offset<T>)offset).Value; else throw new InvalidOperationException(string.Format("Value of requested offset {0} does not match the expected type {1}", address, typeof(T))); } Offsets.Add(address, new Offset<T>(address)); return default(T); } But if you don't know T (as in getting an Offset from a Type), the code becomes a little messier (note that the generic type creation isn't strictly needed to see if the value is of the correct type, but it enforces the dictionary type to be Offset<>): object GetInternalOffsetValue(int address, Type type) { object tempOffset; var offsetBaseType = typeof(Offset<>); var offsetType = offsetBaseType.MakeGenericType(type); if (Offsets.TryGetValue(address, out tempOffset)) { if (offsetType.IsInstanceOfType(tempOffset)) return tempOffset.GetType().GetProperty("Value").GetGetMethod().Invoke(tempOffset, null); else throw new InvalidOperationException(string.Format("Value of requested offset {0} does not match the expected type {1}", address, type)); } var newOffset = Activator.CreateInstance(offsetType); Offsets.Add(address, newOffset); if (type.IsValueType) return Activator.CreateInstance(type); return null; } I am especially unfond of the magic string needed to get the value :) If IOffset was public, the dictionary can be strongly typed, and the second method can be trivialized by comparing the data type directly instead of having to create a generic type on the fly, and the offset value can be accessed directly via IOffset.Value rather than relying on a reflected magic string "Value".
  9. Hi Paul, Is there a chance you can expose the FSUIPC.IOffset interface or perhaps enclose all offsets in another (marker) interface? The reason I'm asking is right now it's impossible to abstract an instance of Offset<T> (say you want to push offsets into a list or a dictionary for caching purposes, or instantiate offsets at runtime). Right now I'm casting object:s and doing some serious generic type juggling (good fun but not really pretty). Cheers /Johan
  10. First off hats off to a great job. Is there a chance you could put the assembly in a nuget package to make it more managable? Cheers
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.