I have a struct called Base64String
which basically does implicit conversion between a string
and a byte[]
It's working quite well in the library, but here's the oddity...
When I have a webservice, that returns the value as Base64String
[WebMethod]
public Base64String GetBase64String(string input)
{
return input;
}
This method was merely a test though, as Base64String
is the type of a property on the real object being returned.
And then Add a Reference to the webservice in another project, it has a return type of DataSet
??? Why is it doing that? Of all the types it could pick, why DataSet, it's not even remotely close to what I want.
And for reference the Base64String struct:
using System.Linq;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System;
using System.Text;
[XmlRoot("string")]
public struct Base64String : IEqualityComparer<Base64String>, IXmlSerializable
{
private byte[] bytes;
private Base64String(byte[] value)
{
bytes = value;
}
private Base64String(string value)
{
bytes = Convert.FromBase64String(value);
}
public static Base64String FromText(string text)
{
return new Base64String(Encoding.UTF8.GetBytes(text));
}
public static implicit operator string(Base64String value)
{
return value.bytes == null ? string.Empty : Convert.ToBase64String(value.bytes);
}
public static implicit operator byte[](Base64String value)
{
return value.bytes;
}
public static implicit operator Base64String(string value)
{
return new Base64String(value);
}
public static implicit operator Base64String(byte[] value)
{
return new Base64String(value);
}
public static bool operator ==(Base64String left, Base64String right)
{
// Both null, thus equal
if ((object)left == null && (object)right == null)
return true;
// Only one is null, thus not equal
if ((object)left == null || (object)right == null)
return false;
// Neither null, compare
return left.bytes.SequenceEqual(right.bytes);
}
public static bool operator !=(Base64String left, Base64String right)
{
return !(left == right);
}
public override bool Equals(object obj)
{
return this == (Base64String)obj;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public bool Equals(Base64String x, Base64String y)
{
return (x == y);
}
public int GetHashCode(Base64String obj)
{
return base.GetHashCode();
}
public override string ToString()
{
return this;
}
public XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
this = reader.ReadString();
}
public void WriteXml(XmlWriter writer)
{
writer.WriteString(this);
}
}