Now please modify the propeties with source code mode(in the web page) like below, since you couldn't modify it by properties window when using struct.
"Cannot modify the return value of 'CSharp.MyDPoint.DPoint' because it is not a variable "
That why you can't modify the properties.
(I assume you have read the reference above about difference between struct and class.)
and now have two samples below that sperately uses struct and class:
Using Struct:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Point point = new Point();
point.X = 1;
point.Y = 2;
point.Z = 3;
Console.WriteLine(point.X + ";" + point.Y + ";" + point.Z);
MyClass myClass = new MyClass();
myClass.Point1.X = 4;
myClass.Point1.Y = 5;
myClass.Point1.Z = 6;
Console.WriteLine(myClass.Point1.X + ";" + myClass.Point1.Y + ";" + myClass.Point1.Z);
}
}
class MyClass
{
Point point = new Point();
public Point Point1
{
get
{
return point;
}
set
{
point = value;
}
}
}
struct Point
{
private double _x;
private double _y;
private double _z;
public double Z
{
get { return _z; }
set { _z = value; }
}
public double Y
{
get { return _y; }
set { _y = value; }
}
public double X
{
get { return _x; }
set { _x = value; }
}
}
}
Using class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Point point = new Point();
point.X = 1;
point.Y = 2;
point.Z = 3;
Console.WriteLine(point.X + ";" + point.Y + ";" + point.Z);
MyClass myClass = new MyClass();
myClass.Point1.X = 4;
myClass.Point1.Y = 5;
myClass.Point1.Z = 6;
Console.WriteLine(myClass.Point1.X + ";" + myClass.Point1.Y + ";" + myClass.Point1.Z);
}
}
class MyClass
{
Point point = new Point();
public Point Point1
{
get
{
return point;
}
set
{
point = value;
}
}
}
class Point
{
private double _x;
private double _y;
private double _z;
public double Z
{
get { return _z; }
set { _z = value; }
}
public double Y
{
get { return _y; }
set { _y = value; }
}
public double X
{
get { return _x; }
set { _x = value; }
}
}
}
Run the both samples, you will find the sample using struct occurs one error as when you run the web page.
"Cannot modify the return value of 'CSharp.MyDPoint.DPoint' because it is not a variable "
"Cannot modify the return value of 'ConsoleApplication2.MyClass.Point1' because it is not a variable "
The both samples are better to explain why you couldn't modify the properties. Because when you create the
Because the CSharp.MyDPoint.DPoint just returns the copy of struct, and you were using it as reference(if class).
The explanation for the reason why can't modify the properties is right, but for why the properties can be modified after overriding GetStandardValuesSupported method, it may invovle some inner underground operations of .NET. The research for it is still
processing.
Please mark the replies as answers if they help or unmark if not.
Feedback to us
While reading through this I have to say that it took a little time to get my head around it, and I don't have an answer for you. By overriding the GetStandardValuesSupported and setting it to true, it seems you are basically bypassing one checkpoint the
designer must use. I have sent a question over to our Languages team that understand these inner workings at a much lower level than I do. Hopefully, they will have some insight but this question may fall into the paid support category which requires a more
in-depth level of support.
While reading through this I have to say that it took a little time to get my head around it, and I don't have an answer for you. By overriding the GetStandardValuesSupported and setting it to true, it seems you are basically bypassing one checkpoint the
designer must use. I have sent a question over to our Languages team that understand these inner workings at a much lower level than I do. Hopefully, they will have some insight but this question may fall into the paid support category which requires a more
in-depth level of support.
ToughMan
Participant
1490 Points
635 Posts
Re: Why struct doesn't work properly?
Dec 07, 2012 06:32 AM|LINK
Dear Dai:D
THANKS ANYWAY AND PLZ LEAVE UR EMAIL, I'LL SEND A PROJ OF VS2012 TO U;D
Mamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: Why struct doesn't work properly?
Dec 07, 2012 07:08 AM|LINK
Hi,
Please post your project to the SkyDrive and you will get a shared reference, then please send it to my forum inbox by private message functionality.
Feedback to us
Develop and promote your apps in Windows Store
ToughMan
Participant
1490 Points
635 Posts
Re: Why struct doesn't work properly?
Dec 08, 2012 05:14 AM|LINK
Many thanks!
I'll do that.
ToughMan
Participant
1490 Points
635 Posts
Re: Why struct doesn't work properly?
Dec 08, 2012 05:31 AM|LINK
Hello MSFT,
Let me re-explain the problem again, please see it carefully and clearly, hope this clear you!
1) I have three kinds of files called "Point", "MyPoint" as well as a webpage. The first two files are of cs file (Class file):
[Point File]
Mamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: Why struct doesn't work properly?
Dec 10, 2012 06:25 AM|LINK
Hi,
Again, I really check your reply carefully, and you initial reply provided the code is different now. You might notice it.
Yes, it's ok.
Can't modify the property.
Now try to explain the reason.
Firstly, you need to understand the difference between struct and class, please refer to below:
(Notice: it's important to understand the difference, it make you better to understand the both samples code at last)
http://msdn.microsoft.com/en-us/library/aa664471(v=vs.71).aspx
Now please modify the propeties with source code mode(in the web page) like below, since you couldn't modify it by properties window when using struct.
Run your web page, the error below will occur:
"Cannot modify the return value of 'CSharp.MyDPoint.DPoint' because it is not a variable "
That why you can't modify the properties.
(I assume you have read the reference above about difference between struct and class.)
and now have two samples below that sperately uses struct and class:
Using Struct:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Point point = new Point(); point.X = 1; point.Y = 2; point.Z = 3; Console.WriteLine(point.X + ";" + point.Y + ";" + point.Z); MyClass myClass = new MyClass(); myClass.Point1.X = 4; myClass.Point1.Y = 5; myClass.Point1.Z = 6; Console.WriteLine(myClass.Point1.X + ";" + myClass.Point1.Y + ";" + myClass.Point1.Z); } } class MyClass { Point point = new Point(); public Point Point1 { get { return point; } set { point = value; } } } struct Point { private double _x; private double _y; private double _z; public double Z { get { return _z; } set { _z = value; } } public double Y { get { return _y; } set { _y = value; } } public double X { get { return _x; } set { _x = value; } } } }Using class:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Point point = new Point(); point.X = 1; point.Y = 2; point.Z = 3; Console.WriteLine(point.X + ";" + point.Y + ";" + point.Z); MyClass myClass = new MyClass(); myClass.Point1.X = 4; myClass.Point1.Y = 5; myClass.Point1.Z = 6; Console.WriteLine(myClass.Point1.X + ";" + myClass.Point1.Y + ";" + myClass.Point1.Z); } } class MyClass { Point point = new Point(); public Point Point1 { get { return point; } set { point = value; } } } class Point { private double _x; private double _y; private double _z; public double Z { get { return _z; } set { _z = value; } } public double Y { get { return _y; } set { _y = value; } } public double X { get { return _x; } set { _x = value; } } } }Run the both samples, you will find the sample using struct occurs one error as when you run the web page.
"Cannot modify the return value of 'CSharp.MyDPoint.DPoint' because it is not a variable "
"Cannot modify the return value of 'ConsoleApplication2.MyClass.Point1' because it is not a variable "
The both samples are better to explain why you couldn't modify the properties. Because when you create the
Because the CSharp.MyDPoint.DPoint just returns the copy of struct, and you were using it as reference(if class).
the copy of struct is like below:
myClass.Point1.X = 0; myClass.Point1.Y = 0; myClass.Point1.Z = 0;Because it's just a copy of struct, so when you modify the "X,Y,Z" like below:
<cc1:MyDPoint ID="MyDPoint1" DPoint-X="1" DPoint-Y="3" DPoint-Z="4" runat="server"> </cc1:MyDPoint>It's equal to do something like below:
But if you use the class, it would return one reference, obviously, you can modify it.
Feedback to us
Develop and promote your apps in Windows Store
ToughMan
Participant
1490 Points
635 Posts
Re: Why struct doesn't work properly?
Dec 11, 2012 05:58 AM|LINK
Are u sure?
But if you uncomment the overridable method of:
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
Struct can also work!
Why?????????????????
Mamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: Why struct doesn't work properly?
Dec 14, 2012 07:56 AM|LINK
Hi,
The explanation for the reason why can't modify the properties is right, but for why the properties can be modified after overriding GetStandardValuesSupported method, it may invovle some inner underground operations of .NET. The research for it is still processing.
Feedback to us
Develop and promote your apps in Windows Store
ToughMan
Participant
1490 Points
635 Posts
Re: Why struct doesn't work properly?
Dec 15, 2012 07:28 AM|LINK
Many thanks, waiting for ur reply
cts-mgraham
Contributor
3318 Points
642 Posts
Microsoft
Re: Why struct doesn't work properly?
Dec 15, 2012 12:09 PM|LINK
While reading through this I have to say that it took a little time to get my head around it, and I don't have an answer for you. By overriding the GetStandardValuesSupported and setting it to true, it seems you are basically bypassing one checkpoint the designer must use. I have sent a question over to our Languages team that understand these inner workings at a much lower level than I do. Hopefully, they will have some insight but this question may fall into the paid support category which requires a more in-depth level of support.
You can visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
ToughMan
Participant
1490 Points
635 Posts
Re: Why struct doesn't work properly?
Dec 16, 2012 01:53 AM|LINK
Man!
It seems that you Microsoft ONLY wanna money……I know that u Microsoft will go down……Right?
You cannot solve my problem but ONLY FOR MONEY……Why?