ref

Why cannot return a nested ref return result if the inner method has another ref/out parameter?

为君一笑 提交于 2021-02-19 05:05:48
问题 I thought I understood limitations of ref returns as well as escaping scopes. But now I found a case and I don't get why is it illegal. It seems that ref return cannot be used if the value to return comes from a nested method with any ref/out arguments. public static ref T RefReturn<T>() { ref T result = ref GetResult<T>(normalParam: default); // compiles // ref T result = ref GetResult<T>(out bool outParam); // CS8157 at the return statement // ref T result = ref GetResult<T>(boxedParam: new

C# MVC4 Web API - Resulting JSON should return objects instead of $ref to object

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-18 11:11:50
问题 I have an ASP.NET MVC 4 Web API app using EntityFramework for ORM. In the JSON I return, there are some cases where the same child node is present for multiple parent nodes. In these cases, the first occurrence of the child node is fully visible with all it's members. Any subsequent occurrence shows up as a $ref to the first occurrence. I'd like instead to see the full object everytime it shows up in the JSON returned. For example, instead of seeing: [{ "$id": "1", "userId": 1, "Badge": { "

C# MVC4 Web API - Resulting JSON should return objects instead of $ref to object

[亡魂溺海] 提交于 2021-02-18 11:10:05
问题 I have an ASP.NET MVC 4 Web API app using EntityFramework for ORM. In the JSON I return, there are some cases where the same child node is present for multiple parent nodes. In these cases, the first occurrence of the child node is fully visible with all it's members. Any subsequent occurrence shows up as a $ref to the first occurrence. I'd like instead to see the full object everytime it shows up in the JSON returned. For example, instead of seeing: [{ "$id": "1", "userId": 1, "Badge": { "

Using document.querySelector in React? Should I use refs instead? How?

谁说胖子不能爱 提交于 2021-02-18 05:15:19
问题 I am building a carousel right now, in React. To scroll to the individual slides I am using document.querySelector like so : useEffect(() => { document.querySelector(`#slide-${activeSlide}`).scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' }); }, [activeSlide]); Is this bad practice? After all, I am accessing the DOM directly here? What would be the React way of doing this? edit: full return method return ( <> <button onClick={() => setActiveSlide(moveLeft)}>PREV<

Using document.querySelector in React? Should I use refs instead? How?

余生长醉 提交于 2021-02-18 05:15:18
问题 I am building a carousel right now, in React. To scroll to the individual slides I am using document.querySelector like so : useEffect(() => { document.querySelector(`#slide-${activeSlide}`).scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' }); }, [activeSlide]); Is this bad practice? After all, I am accessing the DOM directly here? What would be the React way of doing this? edit: full return method return ( <> <button onClick={() => setActiveSlide(moveLeft)}>PREV<

Vue 3 composition API get value from object ref

怎甘沉沦 提交于 2021-02-11 12:49:01
问题 I have a ref : const editItem = ref<object | null>(null) Here's an example value for it: { id: 1, title: 'Harry Potter', author: 'J.K. Rowling', created: '30-08-2000', } If I run console.log(editItem.value) , I see this object: But when I try to read the value's author with console.log(editItem.value.author) , then I see this error: Object is possibly 'null'. 回答1: Since the type of the ref is object | null , it could be null when you access it, leading to a runtime exception. The error

Using 'ref' as array in React

落爺英雄遲暮 提交于 2021-02-09 08:01:28
问题 I have some issues when im trying to reference inputs as arrays in React with Redux. The code below maps one Panel per article in the array. var articles = this.props.item.array.articles.map((article, index) => { return <Panel key={index} header={'Article ' + index}> <Input type='select' ref='id' label='Article' defaultValue={article.id} > {articles} </Input> </Panel> }) I'm trying to construct the refs so that they're in an array format, which does not seem to be possible at the moment.

Can I foreach over an array of structs without copying the elements in C# 8?

混江龙づ霸主 提交于 2021-02-08 14:49:22
问题 With the new readonly instance member features in C# 8, I try to minify unnecessary copying of struct instances in my code. I do have some foreach iterations over arrays of structs, and according to this answer, it means that every element is copied when iterating over the array. I thought I can simply modify my code now to prevent the copying, like so: // Example struct, real structs may be even bigger than 32 bytes. struct Color { public int R; public int G; public int B; public int A; }

Extension method and local 'this' variable

你。 提交于 2021-02-08 13:34:09
问题 To my knowledge this in a extension method is passed as a ref variable. I can verify this by doing public static void Method<T>(this List<T> list) { list.Add(default(T)); } List<int> ints = new List<int>(new int[] { 1, 2, 3, 4, 5 }); ints.Method(); My List<int> ints is now 1, 2, 3, 4, 5, 0 . However when I do public static void Method<T>(this List<T> list, Func<T, bool> predicate) { list = list.Where(predicate).ToList(); } List<int> ints = new List<int>(new int[] { 1, 2, 3, 4, 5 }); ints

Extension method and local 'this' variable

故事扮演 提交于 2021-02-08 13:32:57
问题 To my knowledge this in a extension method is passed as a ref variable. I can verify this by doing public static void Method<T>(this List<T> list) { list.Add(default(T)); } List<int> ints = new List<int>(new int[] { 1, 2, 3, 4, 5 }); ints.Method(); My List<int> ints is now 1, 2, 3, 4, 5, 0 . However when I do public static void Method<T>(this List<T> list, Func<T, bool> predicate) { list = list.Where(predicate).ToList(); } List<int> ints = new List<int>(new int[] { 1, 2, 3, 4, 5 }); ints