protected virtual void Process(HierarchyTypeParameter parent, ApiTypeParameterGenericConstraint constraint) { var hierarchyTypeParameterGenericConstraint = CreateHierarchyElementInternal <HierarchyTypeParameterGenericConstraint> (parent); hierarchyTypeParameterGenericConstraint.Init(constraint); parent.AddMember(hierarchyTypeParameterGenericConstraint); }
// 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); }
protected void AddTypeParameterGenericConstraints(HierarchyTypeParameter parameter, ApiTypeParameter typeParameter) { Helpers.ForEachNotNull(typeParameter.ChildElements, (ApiElement e) => { switch (e) { case ApiTypeParameterGenericConstraint constraint: Process(parameter, constraint); break; default: Logger.Warning($"Unexpected member type for ApiTypeParameter: '{e.GetType ().FullName}'"); break; } }); }