示例#1
0
        // A bit clumsy but better than full-blown reflection use or an open set of Create* methods for each
        // type we support now or in the future
        protected virtual T CreateHierarchyElement <T> (HierarchyBase parent) where T : HierarchyElement
        {
            Type          type = typeof(T);
            HierarchyBase ret  = null;

            if (type == typeof(HierarchyNamespace))
            {
                ret = new HierarchyNamespace(Context, parent as Hierarchy);
            }
            else if (type == typeof(HierarchyClass))
            {
                ret = new HierarchyClass(Context, parent as HierarchyNamespace);
            }
            else if (type == typeof(HierarchyImplements))
            {
                ret = new HierarchyImplements(Context, parent as HierarchyObject);
            }
            else if (type == typeof(HierarchyMethod))
            {
                ret = new HierarchyMethod(Context, parent as HierarchyObject);
            }
            else if (type == typeof(HierarchyConstructor))
            {
                ret = new HierarchyConstructor(Context, parent as HierarchyObject);
            }
            else if (type == typeof(HierarchyException))
            {
                ret = new HierarchyException(Context, parent as HierarchyMethod);
            }
            else if (type == typeof(HierarchyTypeParameter))
            {
                ret = new HierarchyTypeParameter(Context, parent as HierarchyElement);
            }
            else if (type == typeof(HierarchyTypeParameterGenericConstraint))
            {
                ret = new HierarchyTypeParameterGenericConstraint(Context, parent as HierarchyTypeParameter);
            }
            else if (type == typeof(HierarchyMethodParameter))
            {
                ret = new HierarchyMethodParameter(Context, parent as HierarchyMethod);
            }
            else if (type == typeof(HierarchyField))
            {
                ret = new HierarchyField(Context, parent as HierarchyObject);
            }
            else if (type == typeof(HierarchyInterface))
            {
                ret = new HierarchyInterface(Context, parent as HierarchyNamespace);
            }
            else if (type == typeof(HierarchyEnum))
            {
                ret = new HierarchyEnum(Context, parent as Hierarchy);
            }
            else
            {
                throw new InvalidOperationException($"Unsupported hierarchy element type {type}");
            }

            return(ret as T);
        }
示例#2
0
        // Walks up the parent chain and calculates the namespace based on the parent types instead of just
        // reading the full managed name which can lead to invalid results
        public virtual string GetNamespace()
        {
            if (Parent == null)
            {
                return(null);
            }

            HierarchyElement parent         = ParentElement;
            HierarchyBase    previousParent = parent;
            var segments = new List <string> ();

            while (parent != null)
            {
                var ns = parent as HierarchyNamespace;
                if (ns != null)
                {
                    if (!(previousParent is HierarchyNamespace))
                    {
                        throw new InvalidOperationException("Parent namespaces must not be interlaced with other types");
                    }
                    segments.Add(ns.GetManagedName());
                }
                previousParent = parent;
                parent         = parent.ParentElement;
            }

            if (segments.Count == 0)
            {
                throw new InvalidOperationException($"A type must be a child of at least one namespace");
            }

            return(String.Join(".", segments));
        }
示例#3
0
 public HierarchyExternalTypeReference(GeneratorContext context, HierarchyBase parent, string typeName, bool isManaged = false) : base(context, parent)
 {
     if (String.IsNullOrEmpty(nameof(typeName)))
     {
         throw new ArgumentException("must not be null or empty", nameof(typeName));
     }
     Name      = typeName;
     IsManaged = isManaged;
 }
示例#4
0
        static string TypeToPrefix(HierarchyBase element)
        {
            if (element == null)
            {
                return("[null]");
            }

            return(TypeToPrefix(element.GetType()));
        }
示例#5
0
        protected T CreateHierarchyElementInternal <T> (HierarchyBase parent) where T : HierarchyElement
        {
            T ret = CreateHierarchyElement <T> (parent);

            if (ret == null)
            {
                throw new InvalidOperationException($"Hierarchy element of type {typeof (T)} not created");
            }
            return(ret);
        }
示例#6
0
        protected virtual string BuildFullName(string firstSegment, Func <HierarchyElement, string> getSegment)
        {
            if (String.IsNullOrEmpty(firstSegment))
            {
                throw new ArgumentException("must not be null or empty", nameof(firstSegment));
            }
            if (getSegment == null)
            {
                throw new ArgumentNullException(nameof(getSegment));
            }

            var segments = new List <string> {
            };

            if (SplitName(firstSegment, out List <string> split))
            {
                segments.AddRange(split);
            }
            else
            {
                segments.Add(firstSegment);
            }

            HierarchyBase parent = Parent;

            while (parent != null)
            {
                var element = parent as HierarchyElement;
                if (element == null)
                {
                    break;
                }

                string segment = getSegment(element);
                if (String.IsNullOrEmpty(segment))
                {
                    throw new InvalidOperationException("Element name segment must not be null or empty");
                }
                if (SplitName(segment, out split))
                {
                    segments.AddRange(split);
                }
                else
                {
                    segments.Add(segment);
                }
                parent = element.Parent;
            }

            // string dbg = String.Join (" → ", segments);
            // Logger.Debug ($"Full name segments for {Name} ({GetType ().FullName}): {dbg}");
            return(MakeFullName(segments));
        }
示例#7
0
 protected HierarchyObject(GeneratorContext context, HierarchyBase parent) : base(context, parent)
 {
 }
示例#8
0
 public HierarchyEnum(GeneratorContext context, HierarchyBase parent) : base(context, parent)
 {
     DoNotAddBaseTypes = true;
 }
示例#9
0
 protected HierarchyElement(GeneratorContext context, HierarchyBase parent) : base(context)
 {
     Parent     = parent ?? throw new ArgumentNullException(nameof(parent));
     IsBoundAPI = false;
 }
示例#10
0
 public HierarchyException(GeneratorContext context, HierarchyBase parent) : base(context, parent)
 {
 }
示例#11
0
 public HierarchyTypeParameterGenericConstraint(GeneratorContext context, HierarchyBase parent) : base(context, parent)
 {
 }
示例#12
0
        string TypeToName(HierarchyBase element)
        {
            if (element == null)
            {
                return("[null]");
            }

            Type type = element.GetType();

            if (type == typeof(HierarchyNamespace))
            {
                return("Namespace");
            }
            else if (type == typeof(HierarchyClass))
            {
                return("Class");
            }
            else if (type == typeof(HierarchyInterfaceInvoker))
            {
                return("Class (invoker)");
            }
            else if (type == typeof(HierarchyTypeMember))
            {
                return("Type Member");
            }
            else if (type == typeof(HierarchyImplements))
            {
                return("Implements");
            }
            else if (type == typeof(HierarchyMethod))
            {
                return("Method");
            }
            else if (type == typeof(HierarchyConstructor))
            {
                return("Constructor");
            }
            else if (type == typeof(HierarchyException))
            {
                return("Exception");
            }
            else if (type == typeof(HierarchyTypeParameter))
            {
                return("Type Parameter");
            }
            else if (type == typeof(HierarchyTypeParameterGenericConstraint))
            {
                return("Type Parameter Generic Constraint");
            }
            else if (type == typeof(HierarchyMethodParameter))
            {
                return("Method Parameter");
            }
            else if (type == typeof(HierarchyField))
            {
                return("Field");
            }
            else if (type == typeof(HierarchyInterface))
            {
                return("Interface");
            }
            else if (type == typeof(HierarchyEnum))
            {
                return("Enum");
            }
            else
            {
                return(element.GetType().ToString());
            }
        }
示例#13
0
 public HierarchyImplements(GeneratorContext context, HierarchyBase parent) : base(context, parent)
 {
 }
示例#14
0
 public HierarchyMethodParameter(GeneratorContext context, HierarchyBase parent) : base(context, parent)
 {
 }