/// <summary> /// Clones a cached CustomAttributeTypedArgument list into a freshly allocated one suitable for direct return through an api. /// </summary> public static ReadOnlyCollection <CustomAttributeTypedArgument> CloneForApiReturn(this IList <CustomAttributeTypedArgument> cats) { int count = cats.Count; CustomAttributeTypedArgument[] clones = new CustomAttributeTypedArgument[count]; for (int i = 0; i < count; i++) { clones[i] = cats[i].CloneForApiReturn(); } return(clones.ToReadOnlyCollection()); }
/// <summary> /// Clones a cached CustomAttributeTypedArgument into a freshly allocated one suitable for direct return through an api. /// </summary> private static CustomAttributeTypedArgument CloneForApiReturn(this CustomAttributeTypedArgument cat) { Type type = cat.ArgumentType; object?value = cat.Value; if (!(value is IList <CustomAttributeTypedArgument> cats)) { return(cat); } int count = cats.Count; CustomAttributeTypedArgument[] cads = new CustomAttributeTypedArgument[count]; for (int i = 0; i < count; i++) { cads[i] = cats[i].CloneForApiReturn(); } return(new CustomAttributeTypedArgument(type, cads.ToReadOnlyCollection())); }