Jump to content

C# - Inconsistent Accessibility


hda
 Share

Recommended Posts

pois bem, normalmente o google é meu amigo quando tenho problemas a programar mas desta vez não consegui perceber o que ele me quer dizer

estou a gravar um vector para ficheiro, o estúpido é que já fiz isto com outros dois vectores e só este não funciona, não sei porquê.

imageListSerialize.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.
Binary;

namespace GestaoImagens
{
	[Serializable()]
	public class ImageToSerialize : ISerializable
	{
		private List<image> imageList;

		public List<image> Images
		{
			get { return this.imageList; }
			set { this.imageList = value; }
		}

		public ImageToSerialize()
		{
		}

		public ImageToSerialize(SerializationInfo info, StreamingContext ctxt)
		{
			this.imageList = (List<image>)info.GetValue("images", typeof(List<image>));
		}

		public void GetImageData(SerializationInfo info, StreamingContext ctxt)
		{
			info.AddValue("image", this.imageList);
		}

		public static void Save(List<image> imageList, string filename)
		{
			ImageToSerialize imageToSerialize = new ImageToSerialize();
			imageToSerialize.imageList = imageList;

			Serializer serializer = new Serializer();
			serializer.imageListSerialize(filename, imageToSerialize);
		}

		public static List<image> LoadImages(string filename)
		{
			Serializer serializer = new Serializer();
			ImageToSerialize imageToSerialize = serializer.DeSerializeObjectIM(filename);
			if (imageToSerialize == null) return new List<image>();
			else return imageToSerialize.imageList;
		}
	}
}

Serializer.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GestaoImagens
{
	using System.IO;
	using System.Runtime.Serialization;
	using System.Runtime.Serialization.Formatters.
Binary;

	public class Serializer
	{
		public Serializer()
		{
		}

		public void SerializeObject(string filename,
					   ObjectToSerialize objectToSerialize)
		{
			Stream stream = File.Open(filename, FileMode.Create);
			BinaryFormatter bFormatter = new BinaryFormatter();
			bFormatter.Serialize(stream, objectToSerialize);
			stream.Close();
		}

		public ObjectToSerialize DeSerializeObject(string filename)
		{
			ObjectToSerialize objectToSerialize;
			try
			{
				Stream stream = File.Open(filename, FileMode.Open);
				 BinaryFormatter bFormatter = new BinaryFormatter();
				objectToSerialize = (ObjectToSerialize)bFormatter.Deserialize(stream);
				stream.Close();
				return objectToSerialize;
			}
			catch(FileNotFoundException fe) {
			   Stream stream = File.Open(filename, FileMode.Create);
				stream.Close();
				return null;
			}		   
		}

		public void operatorListSerialize(string filename,
			   operatorListSerialize operatorListSerialize)
		{
			Stream stream = File.Open(filename, FileMode.Create);
			BinaryFormatter bFormatter = new BinaryFormatter();
			bFormatter.Serialize(stream, operatorListSerialize);
			stream.Close();
		}

		public operatorListSerialize DeSerializeObjectOP(string filename)
		{
			operatorListSerialize operatorListSerialize;
			try
			{
				Stream stream = File.Open(filename, FileMode.Open);
				BinaryFormatter bFormatter = new BinaryFormatter();
				operatorListSerialize = (operatorListSerialize)bFormatter.Deserialize(stream);
				stream.Close();
				return operatorListSerialize;
			}
			catch (FileNotFoundException fe)
			{
				Stream stream = File.Open(filename, FileMode.Create);
				stream.Close();
				return null;
			}
		}


		public void imageListSerialize(string filename, ImageToSerialize imageListSerialize)
		{
			Stream stream = File.Open(filename, FileMode.Create);
			BinaryFormatter bFormatter = new BinaryFormatter();
			bFormatter.Serialize(stream, imageListSerialize);
			stream.Close();
		}

		public ImageToSerialize DeSerializeObjectIM(string filename)
		{
			imageListSerialize imageListSerialize;
			try
			{
				Stream stream = File.Open(filename, FileMode.Open);
				BinaryFormatter bFormatter = new BinaryFormatter();
				imageListSerialize = (imageListSerialize)bFormatter.Deserialize(stream);
				stream.Close();
				return imageListSerialize;
			}
			catch (FileNotFoundException fe)
			{
				Stream stream = File.Open(filename, FileMode.Create);
				stream.Close();
				return null;
			}
		}
	}
}

os erros que o vs dá são:

Error	1	Inconsistent accessibility: property type 'System.Collections.Generic.List<GestaoImagens.image>' is less accessible than property 'GestaoImagens.ImageToSerialize.Image
s'	C:\Users\Hugo\Documents\Visual Studio 2008\Projects\GestaoImagens\GestaoImagens\imageListSerialize.cs	15	28	GestaoImagens

Error	2	Inconsistent accessibility: parameter type 'System.Collections.Generic.List<GestaoImagens.image>' is less accessible than method 'GestaoImagens.ImageToSerialize.Save(System.Collections.Generic.List<GestaoImagens.image>, string)'	C:\Users\Hugo\Documents\Visual Studio 2008\Projects\GestaoImagens\GestaoImagens\imageListSerialize.cs	35	28	GestaoImagens

Error	3	Inconsistent accessibility: return type 'System.Collections.Generic.List<GestaoImagens.image>' is less accessible than method 'GestaoImagens.ImageToSerialize.LoadI
mages(string)'	C:\Users\Hugo\Documents\Visual Studio 2008\Projects\GestaoImagens\GestaoImagens\imageListSerialize.cs	44	35	GestaoImagens

Obrigado desde já ;)

edit:

de notar que pelo que li tenho que _supostamente_ equalizar as permissões entre os parâmetros/métodos/tipos/propriedades. só que a única coisa que tenho private aí já tentei por public, mesmo sem fazer sentido, e bolha

Edited by hda
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.