Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net Protobuf网络梯度刷_.net_Wpf_Serialization_Protobuf Net - Fatal编程技术网

.net Protobuf网络梯度刷

.net Protobuf网络梯度刷,.net,wpf,serialization,protobuf-net,.net,Wpf,Serialization,Protobuf Net,我正在尝试序列化/反序列化渐变笔刷属性 RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(101, typeof(System.Windows.Media.SolidColorBrush)); RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(102, typeof(Sy

我正在尝试序列化/反序列化渐变笔刷属性

RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(101, typeof(System.Windows.Media.SolidColorBrush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(102, typeof(System.Windows.Media.ImageBrush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(103, typeof(System.Windows.Media.LinearGradientBrush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(104, typeof(System.Windows.Media.RadialGradientBrush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(105, typeof(System.Windows.Media.GradientBrush));
RuntimeTypeModel.Default.Add(typeof(SolidColorBrush), false).Add("Color");
RuntimeTypeModel.Default.Add(typeof(Color), false).Add("A", "R", "G", "B"); 

LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();
myLinearGradientBrush.StartPoint = new Point(0, 0);
myLinearGradientBrush.EndPoint = new Point(1, 1);
myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.0));
myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.Red, 0.25));
myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.Blue, 0.75));
myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.LimeGreen,1.0));
brush = myLinearGradientBrush;

using (var file1 = File.Create(@"C:\Users\vitor\Desktop\test.bin"))
{
     Serializer.Serialize(file1, brush);
}

GradientBrush newBrush;
using (var file1 = File.OpenRead(@"C:\Users\vitor\Desktop\test.bin"))
{
    newBrush = Serializer.Deserialize<GradientBrush>(file1);
}
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush),true).AddSubType(101,typeof(System.Windows.Media.solidcolorbush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush),true).AddSubType(102,typeof(System.Windows.Media.ImageBrush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush),true);
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush),true).AddSubType(104,typeof(System.Windows.Media.RadialGradientBrush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush),true).AddSubType(105,typeof(System.Windows.Media.GradientBrush));
RuntimeTypeModel.Default.Add(typeof(SolidColorBrush),false).Add(“Color”);
RuntimeTypeModel.Default.Add(typeof(Color),false);
LinearGradientBrush myLinearGradientBrush=新的LinearGradientBrush();
myLinearGradientBrush.StartPoint=新点(0,0);
myLinearGradientBrush.EndPoint=新点(1,1);
myLinearGradientBrush.GradientStops.Add(新的GradientStop(Colors.Yellow,0.0));
myLinearGradientBrush.GradientStops.Add(新的GradientStop(Colors.Red,0.25));
myLinearGradientBrush.GradientStops.Add(新的GradientStop(Colors.Blue,0.75));
myLinearGradientBrush.GradientStops.Add(新的GradientStop(Colors.LimeGreen,1.0));
brush=myLinearGradientBrush;
使用(var file1=File.Create(@“C:\Users\vitor\Desktop\test.bin”))
{
Serializer.Serialize(文件1,画笔);
}
梯度灌木丛;
使用(var file1=File.OpenRead(@“C:\Users\vitor\Desktop\test.bin”))
{
newBrush=序列化程序。反序列化(file1);
}

但是当我反序列化newBrush.GradientStops时,它是空的。如何序列化/反序列化GradientBrush?

并非每种类型都适合任何序列化程序。通常,如果您遇到问题,最简单和最可靠的修复方法是编写DTO层,这意味着:一个简单定义您的系统的对象模型,与GradientBrush之类的任何笨拙的实现细节无关(但具有构建正确对象所需的数据),我已经使用DTO层完成了这项工作。非常感谢。