"Greg" <im*****@hotmail.co.ukwrote in message
news:11**********************@o58g2000hsb.googlegr oups.com...
>
Ben Voigt wrote:
>There's
using signaltype = double;
But that just creates a new alias so: (1) the name isn't available in
other
files, and (2) it's the same type, as far as typeof and function
overloading
are concerned.
Alias is perfect because that way I can distinguish between the defined
type and when a double is used for something else. Could it be put in
a namespace ?
What I was trying to make clear was that you can't distinguish. It's
another name for the same thing. Only the source code will have the
distinction. You can put it in a namespace, but only at the very top (wierd
rule) and the only effect is that it goes away at the closing brace of the
namespace instead of the end of the file. There's no way to export the
alias to other files either.
>
>So I've made a compiler that uses Reflection.Emit to create new value
types
that automatically cast to/from ordinary types and allow methods to be
added
aspect-style (such as ToString, TryParse).
OK, it is good that someone into compilers has common sense, how does
I wouldn't say I'm into compilers. Just had a bunch of types defined in a
non-.NET language (ASN.1 subset actually) and wanted to use them. It's a
two-step process, ASN.1 parsing in perl which writes out an xml file, and
the Reflection/Emit part which an assembly as described by the xml file.
that work.
Is this variation / extension available online ?
No, not presently. The source for it is owned by my employer or possibly
the company we're under contract to. I may eventually try to make a freely
available web service where you can submit your xml and receive the compiled
dll, but I doubt the source will be released. It's rather specialized at
present anyway, a lot of changes would be needed before it would become
generally useful.
Here's an example typedef, decompiled by .NET Reflector
ASN.1:
--
-- 32 bit signed integer
--
INT-I32 ::= INTEGER (-2147483648..2147483647)
xml:
<typedef>
<name>INT-I32</name>
<type>
<base>INTEGER</base>
<range>
<min>-2147483648</min>
<max>2147483647</max>
</range>
</type>
<comment>32 bit signed integer</comment>
</typedef>
..NET Reflector's C# view:
[StructLayout(LayoutKind.Sequential), ValueType("INT-I32", Comment="32 bit
signed integer", ConstantType=typeof(int)),
DebuggerDisplay("{DebugDisplay}")]
public struct IntI32 : IDebugDisplay, IComparable, IFormattable,
IConvertible, IComparable<int>, IComparable<IntI32>, IEquatable<int>,
IEquatable<IntI32>, ICloneable, IEncodable, IMderEncodable
{
public const int MinValue = -2147483648;
public const int MaxValue = 0x7fffffff;
private readonly int internalValue;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public override string DebugDisplay { get; }
public IntI32([In] int value);
public static implicit operator IntI32([In] int value);
public IntI32([In] IntI32 original);
public static implicit operator int([In] IntI32 castFrom);
public sealed override int CompareTo(object obj);
public sealed override string ToString(string format, IFormatProvider
formatProvider);
public sealed override TypeCode GetTypeCode();
bool IConvertible.ToBoolean(IFormatProvider provider);
char IConvertible.ToChar(IFormatProvider provider);
sbyte IConvertible.ToSByte(IFormatProvider provider);
byte IConvertible.ToByte(IFormatProvider provider);
short IConvertible.ToInt16(IFormatProvider provider);
ushort IConvertible.ToUInt16(IFormatProvider provider);
int IConvertible.ToInt32(IFormatProvider provider);
uint IConvertible.ToUInt32(IFormatProvider provider);
long IConvertible.ToInt64(IFormatProvider provider);
ulong IConvertible.ToUInt64(IFormatProvider provider);
float IConvertible.ToSingle(IFormatProvider provider);
double IConvertible.ToDouble(IFormatProvider provider);
decimal IConvertible.ToDecimal(IFormatProvider provider);
DateTime IConvertible.ToDateTime(IFormatProvider provider);
public sealed override string ToString(IFormatProvider provider);
object IConvertible.ToType(Type conversionType, IFormatProvider
provider);
public sealed override int CompareTo(int other);
public override int CompareTo(IntI32 other);
public sealed override bool Equals(int other);
public override bool Equals(IntI32 other);
public override object Clone();
public override string ToString();
public override void Into(IEncoder buffer);
public override void Into(MderEncodingBuffer buffer);
public string ToString(string format);
public override bool Equals(object obj);
public override int GetHashCode();
public override string LTM.IDebugDisplay.DebugDisplay { get; }
}