/// <summary> /// Converts to enum item declaration. /// </summary> private static EnumItem ToEnumItem(FieldInfo field, CommentNavigator navigator) { var item = new EnumItem(); item.Name = field.Name; item.Comment = navigator?.GetXmlComment(field); item.Label = field.GetLabelFromAttribute(); return(item); }
/// <summary> /// Generates handler declare section which corresponds to given method. /// </summary> private static HandlerDeclareItem ToDeclare(MethodInfo method, CommentNavigator navigator) { return(new HandlerDeclareItem { Name = method.Name, Type = HandlerType.Job, Label = method.GetLabelFromAttribute(), Comment = method.GetCommentFromAttribute() ?? navigator?.GetXmlComment(method), Hidden = method.IsHidden(), Static = method.IsStatic ? YesNo.Y : (YesNo?)null, Params = method.GetParameters().Select(ToHandlerParam).ToList() }); }
/// <summary> /// Converts given property into corresponding declaration element. /// </summary> private static ElementDecl ToElement(PropertyInfo property, CommentNavigator navigator) { var element = ToTypeMember <ElementDecl>(property.PropertyType); element.Vector = property.PropertyType.IsVector(); element.Name = property.Name; element.Label = property.GetLabelFromAttribute(); element.Comment = property.GetCommentFromAttribute() ?? navigator?.GetXmlComment(property); element.Optional = property.GetCustomAttribute <BsonRequiredAttribute>() == null ? YesNo.Y : (YesNo?)null; element.Hidden = property.IsHidden(); return(element); }
/// <summary> /// Converts enum to EnumDecl /// </summary> public static EnumDecl EnumToDecl(System.Type type, CommentNavigator navigator, ProjectNavigator projNavigator) { if (!type.IsSubclassOf(typeof(Enum))) { throw new ArgumentException($"Cannot create enum declaration from type: {type.FullName}."); } EnumDecl decl = new EnumDecl(); decl.Name = type.Name; decl.Comment = GetCommentFromAttribute(type) ?? navigator?.GetXmlComment(type); decl.Category = projNavigator?.GetTypeLocation(type); decl.Module = new ModuleKey { ModuleName = type.Namespace }; decl.Label = GetLabelFromAttribute(type) ?? type.Name; List <FieldInfo> items = type.GetFields(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Static).ToList(); decl.Items = items.Select(i => ToEnumItem(i, navigator)).ToList(); return(decl); }
/// <summary> /// Converts type inherited from Data to TypeDecl /// </summary> public static TypeDecl TypeToDecl(System.Type type, CommentNavigator navigator, ProjectNavigator projNavigator) { if (!type.IsSubclassOf(typeof(Data))) { throw new ArgumentException($"Cannot create type declaration from type: {type.FullName}."); } TypeDecl decl = new TypeDecl(); decl.Module = new ModuleKey { ModuleName = type.Namespace }; decl.Category = projNavigator?.GetTypeLocation(type); decl.Name = type.Name; decl.Label = GetLabelFromAttribute(type) ?? type.Name; decl.Comment = GetCommentFromAttribute(type) ?? navigator?.GetXmlComment(type); decl.Kind = GetKind(type); decl.IsRecord = type.IsSubclassOf(typeof(Record)); decl.Inherit = IsRoot(type.BaseType) ? null : CreateTypeDeclKey(type.BaseType.Namespace, type.BaseType.Name); decl.Index = GetIndexesFromAttributes(type); // Skip special (property getters, setters, etc) and inherited methods List <MethodInfo> handlers = type.GetMethods(PublicInstanceDeclaredFlags) .Where(IsProperHandler) .ToList(); var declares = new List <HandlerDeclareItem>(); var implements = new List <HandlerImplementItem>(); foreach (MethodInfo method in handlers) { // Abstract methods have only declaration if (method.IsAbstract) { declares.Add(ToDeclare(method, navigator)); } // Overriden methods are marked with override else if (method.GetBaseDefinition() != method) { // TODO: Temp adding declare to avoid signature search in bases. declares.Add(ToDeclare(method, navigator)); implements.Add(ToImplement(method)); } // Case for methods without modifiers else { declares.Add(ToDeclare(method, navigator)); implements.Add(ToImplement(method)); } } // Add method information to declaration if (declares.Any()) { decl.Declare = new HandlerDeclareBlock { Handlers = declares } } ; if (implements.Any()) { decl.Implement = new HandlerImplementBlock { Handlers = implements } } ; List <PropertyInfo> dataProperties = type.GetProperties(PublicInstanceDeclaredFlags) .Where(p => IsAllowedType(p.PropertyType)) .Where(IsPublicGetSet).ToList(); decl.Elements = dataProperties.Select(p => ToElement(p, navigator)).ToList(); decl.Keys = GetKeyProperties(type) .Where(p => IsAllowedType(p.PropertyType)) .Where(IsPublicGetSet) .Select(t => t.Name).ToList(); return(decl); }