private void CollectEvents(WindowsAccessBridgeModel model) { var type = typeof(WindowsAccessBridgeDefinition); var events = type.GetEvents(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); model.Events.AddRange(events.OrderBy(f => f.Name).Select(x => CollectEvent(x))); }
private void CollectFunctions(WindowsAccessBridgeModel model) { var type = typeof(WindowsAccessBridgeDefinition); var functions = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); model.Functions.AddRange(functions.Where(f => !f.IsSpecialName).OrderBy(f => f.Name).Select(f => CollectFunction(f))); }
private void CollectClasses(WindowsAccessBridgeModel model) { var sampleStruct = typeof(AccessibleContextInfo); var types = typeof(WindowsAccessBridgeDefinition).Assembly.GetExportedTypes() .Where(t => t.Namespace == sampleStruct.Namespace) .Where(t => t.IsClass); model.Classes.AddRange(types.OrderBy(f => f.Name).Select(t => CollectClass(t))); }
private void CollectEnums(WindowsAccessBridgeModel model) { var sampleType = typeof(AccessibleKeyCode); var types = typeof(WindowsAccessBridgeDefinition).Assembly.GetExportedTypes() .Where(t => t.Namespace == sampleType.Namespace) .Where(t => t.IsValueType && t.IsEnum); model.Enums.AddRange(types.OrderBy(f => f.Name).Select(t => CollectEnum(t))); }
/// <summary> /// Returns <code>true</code> if the <see cref="TypeReference"/> <paramref /// name="type"/> is a direct reference to a class. /// </summary> public static bool IsClass(this WindowsAccessBridgeModel model, TypeReference type) { var name = type as NameTypeReference; if (name == null) { return(false); } return(model.IsClassName(name.Name)); }
public WindowsAccessBridgeModel CollectModel() { var model = new WindowsAccessBridgeModel(); _xmlDoc = OpenXmlDocComment(); CollectFunctions(model); CollectEvents(model); CollectEnums(model); CollectStructs(model); CollectClasses(model); return(model); }
/// <summary> /// Returns <code>true</code> if the <see cref="TypeReference"/> <paramref /// name="reference"/> requires a wrapper definition for P/Invoke calls, or /// <code>false</code> if it can be used directly. /// </summary> public static bool TypeReferenceNeedsWrapper(this WindowsAccessBridgeModel model, TypeReference reference) { if (reference is NameTypeReference) { return(model.NameTypeReferenceNeedsWrapper((NameTypeReference)reference)); } else if (reference is ArrayTypeReference) { return(model.TypeReferenceNeedsWrapper(((ArrayTypeReference)reference).ElementType)); } else { throw new InvalidOperationException("Unknown type reference type"); } }
private static bool NameTypeReferenceNeedsWrapper(this WindowsAccessBridgeModel model, NameTypeReference reference) { var name = reference.Name; if (name == typeof(JavaObjectHandle).Name) { return(true); } if (model.Classes.Any(c => c.Name == reference.Name && model.ClassNeedsWrapper(c))) { return(true); } if (model.Structs.Any(c => c.Name == reference.Name && model.StructNeedsWrapper(c))) { return(true); } return(false); }
/// <summary> /// Returns <code>true</code> if the <code>struct</code> <paramref /// name="definition"/> requires a wrapper struct definition for P/Invoke /// calls, or <code>false</code> if it can be used directly. /// </summary> public static bool StructNeedsWrapper(this WindowsAccessBridgeModel model, StructDefinition definition) { return(model.TypeDefinitionNeedsWrapper(definition)); }
/// <summary> /// Returns <code>true</code> if the <code>class</code> named <paramref /// name="name"/> requires a wrapper struct definition for P/Invoke calls, /// or <code>false</code> if it can be used directly. /// </summary> public static bool ClassNameNeedsWrapper(this WindowsAccessBridgeModel model, string name) { var definition = model.Classes.FirstOrDefault(x => x.Name == name); return(definition == null ? false : model.ClassNeedsWrapper(definition)); }
/// <summary> /// Returns <code>true</code> if <paramref name="name"/> is the name of a /// known class definition. /// </summary> public static bool IsClassName(this WindowsAccessBridgeModel model, string name) { return(model.Classes.Any(c => c.Name == name)); }
/// <summary> /// Returns <code>true</code> if <paramref name="name"/> is the name of a /// known struct definition. /// </summary> public static bool IsStructName(this WindowsAccessBridgeModel model, string name) { return(model.Structs.Any(c => c.Name == name)); }
/// <summary> /// Returns <code>true</code> if the <see cref="TypeDefinition"/> <paramref /// name="definition"/> requires a wrapper definition for P/Invoke calls, or /// <code>false</code> if it can be used directly. /// </summary> public static bool TypeDefinitionNeedsWrapper(this WindowsAccessBridgeModel model, TypeDefinition definition) { return(definition.Fields.Any(field => model.TypeReferenceNeedsWrapper(field.Type))); }