Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#@ template debug="true" hostspecific="false" language="C#" #>
- <#@ assembly name="System.Core" #>
- <#@ assembly name="$(SolutionDir)test\bin\Debug\test.dll" #>
- <#@ import namespace="System.Linq" #>
- <#@ import namespace="System.Text" #>
- <#@ import namespace="System.Collections.Generic" #>
- <#@ import namespace="test" #>
- <#@ output extension=".cs" #>
- <#
- Dictionary<string, TypeInfo> types = new Dictionary<string, TypeInfo>()
- {
- { "Decimal", new TypeInfo() { Type = typeof(decimal), TypeName = "Decimal", Name = "Decimal", Signed = true, Decimal = true, MateName = null, BitCount = 128,
- ImplicitCasts = new List<string>(),
- ExplicitCasts = new List<string>() { "SByte", "Byte", "Short", "UShort", "Int", "UInt", "Long", "ULong", "Float", "Double", "Decimal" } } },
- { "Double", new TypeInfo() { Type = typeof(double), TypeName = "Double", Name = "Double", Signed = true, Decimal = true, MateName = null, BitCount = 64,
- ImplicitCasts = new List<string>() { },
- ExplicitCasts = new List<string>() { "SByte", "Byte", "Short", "UShort", "Int", "UInt", "Long", "ULong", "Float", "Double", "Decimal" } } },
- { "Float", new TypeInfo() { Type = typeof(Single), TypeName = "Single", Name = "Float", Signed = true, Decimal = true, MateName = null, BitCount = 32,
- ImplicitCasts = new List<string>() { "Float", "Double" },
- ExplicitCasts = new List<string>() { "SByte", "Byte", "Short", "UShort", "Int", "UInt", "Long", "ULong", "Decimal" } } },
- { "Byte", new TypeInfo() { Type = typeof(byte), TypeName = "Byte", Name = "Byte", Signed = false, Decimal = false, MateName = "SByte", BitCount = 8,
- ImplicitCasts = new List<string>() { "Byte", "Short", "UShort", "Int", "UInt", "Long", "ULong", "Float", "Double", "Decimal" },
- ExplicitCasts = new List<string>() { "SByte" } } },
- { "SByte", new TypeInfo() { Type = typeof(sbyte), TypeName = "SByte", Name = "SByte", Signed = true, Decimal = false, MateName = "Byte", BitCount = 8,
- ImplicitCasts = new List<string>() { "SByte", "Short", "Int", "Long", "Float", "Double", "Decimal" },
- ExplicitCasts = new List<string>() { "Byte", "UShort", "UInt", "ULong" } } },
- { "Short", new TypeInfo() { Type = typeof(Int16), TypeName = "Int16", Name = "Short", Signed = true, Decimal = false, MateName = "UShort", BitCount = 16,
- ImplicitCasts = new List<string>() { "Short", "Int", "Long", "Float", "Double", "Decimal" },
- ExplicitCasts = new List<string>() { "SByte", "Byte", "UShort", "UInt", "ULong" } } },
- { "UShort", new TypeInfo() { Type = typeof(UInt16), TypeName = "UInt16", Name = "UShort", Signed = false, Decimal = false, MateName = "Short", BitCount = 16,
- ImplicitCasts = new List<string>() { "UShort", "Int", "UInt", "Long", "ULong", "Float", "Double", "Decimal" },
- ExplicitCasts = new List<string>() { "SByte", "Byte", "Short" } } },
- { "Int", new TypeInfo() { Type = typeof(Int32), TypeName = "Int32", Name = "Int", Signed = true, Decimal = false, MateName = "UInt", BitCount = 32,
- ImplicitCasts = new List<string>() { "Int", "Long", "Float", "Double", "Decimal" },
- ExplicitCasts = new List<string>() { "SByte", "Byte", "Short", "UShort", "UInt", "ULong" } } },
- { "UInt", new TypeInfo() { Type = typeof(UInt32), TypeName = "UInt32", Name = "UInt", Signed = false, Decimal = false, MateName = "Int", BitCount = 32,
- ImplicitCasts = new List<string>() { "UInt", "Long", "ULong", "Float", "Double", "Decimal" },
- ExplicitCasts = new List<string>() { "SByte", "Byte", "Short", "UShort", "Int" } } },
- { "Long", new TypeInfo() { Type = typeof(Int64), TypeName = "Int64", Name = "Long", Signed = true, Decimal = false, MateName = "ULong", BitCount = 64,
- ImplicitCasts = new List<string>() { "Long", "Float", "Double", "Decimal" },
- ExplicitCasts = new List<string>() { "SByte", "Byte", "Short", "UShort", "Int", "UInt", "ULong" } } },
- { "ULong", new TypeInfo() { Type = typeof(UInt64), TypeName = "UInt64", Name = "ULong", Signed = false, Decimal = false, MateName = "Long", BitCount = 64,
- ImplicitCasts = new List<string>() { "ULong", "Float", "Double", "Decimal" },
- ExplicitCasts = new List<string>() { "SByte", "Byte", "Short", "UShort", "Int", "UInt", "Long" } } }
- };
- #>
- using System;
- //using XGEFCore;
- using test;
- namespace Stats
- {
- <# foreach(var pair in types) { #>
- <# string T = pair.Value.Type.Name; #>
- <# string Class = pair.Key + "Stat"; #>
- public class <#= Class #> : NumericStat<<#= T #>>
- {
- public override <#= T #> MaxValue { get { return Math.Min(<#= T #>.MaxValue, MaxLimit); } }
- public override <#= T #> MinValue { get { return Math.Max(<#= T #>.MinValue, MinLimit); } }
- public override int CompareTo(object obj)
- {
- if (obj == null)
- return 1;
- //if(obj is <#= T #> t)
- if(obj is <#= T #>)
- {
- return Value.CompareTo(obj);
- }
- <# foreach(string str in types.Keys) {
- string name = types[str].Name + "Stat";#>
- if(obj is <#= name #>)
- {
- return Value.CompareTo(((<#= name #>)obj).Value);
- }
- <# } #>
- return Value.CompareTo(obj);
- }
- #region IConvertible
- public override TypeCode GetTypeCode()
- {
- return TypeCode.<#= pair.Value.TypeName #>;
- }
- public override bool ToBoolean(IFormatProvider provider)
- {
- if(Value == 0)
- return false;
- return true;
- }
- public override char ToChar(IFormatProvider provider)
- {
- return Convert.ToChar(Value);
- }
- public override sbyte ToSByte(IFormatProvider provider)
- {
- return Convert.ToSByte(Value);
- }
- public override byte ToByte(IFormatProvider provider)
- {
- return Convert.ToByte(Value);
- }
- public override short ToInt16(IFormatProvider provider)
- {
- return Convert.ToInt16(Value);
- }
- public override ushort ToUInt16(IFormatProvider provider)
- {
- return Convert.ToUInt16(Value);
- }
- public override int ToInt32(IFormatProvider provider)
- {
- return Convert.ToInt32(Value);
- }
- public override uint ToUInt32(IFormatProvider provider)
- {
- return Convert.ToUInt32(Value);
- }
- public override long ToInt64(IFormatProvider provider)
- {
- return Convert.ToInt64(Value);
- }
- public override ulong ToUInt64(IFormatProvider provider)
- {
- return Convert.ToUInt64(Value);
- }
- public override float ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(Value);
- }
- public override double ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(Value);
- }
- public override decimal ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(Value);
- }
- public override DateTime ToDateTime(IFormatProvider provider)
- {
- return Convert.ToDateTime(Value);
- }
- public override string ToString(IFormatProvider provider)
- {
- return Convert.ToString(Value);
- }
- public override object ToType(Type conversionType, IFormatProvider provider)
- {
- return Convert.ChangeType(Value,conversionType);
- }
- #endregion
- #region Type Casting
- <# foreach(var typePair in types) {
- string imp = typePair.Value.Type.Name;
- string castingType = "explicit";
- if(typePair.Value.Decimal == pair.Value.Decimal)
- {
- if(typePair.Value.Signed == pair.Value.Signed && pair.Value.BitCount <= typePair.Value.BitCount)
- {
- castingType = "implicit";
- }
- }
- else if(pair.Value.Decimal)
- castingType = "explicit";
- else
- castingType = "implicit";#>
- public static <#= castingType #> operator <#= imp #>(<#= Class #> stat)
- {
- return (<#= imp #>)stat.Value;
- }
- <# string castingType2 = "explicit";
- if(typePair.Value.Decimal == pair.Value.Decimal)
- {
- if(typePair.Value.Signed == pair.Value.Signed && pair.Value.BitCount >= typePair.Value.BitCount)
- {
- castingType2 = "implicit";
- }
- }
- else if(pair.Value.Decimal)
- castingType2 = "implicit";
- else
- castingType2 = "explicit";#>
- public static <#= castingType2 #> operator <#= Class #>(<#= imp #> num)
- {
- <#= Class #> stat = new <#= Class #>();
- stat.Set((<#= T #>)num);
- return stat;
- }
- <# } #>
- #endregion
- public <#= Class #> Copy()
- {
- return new <#= Class #>(Name, Value, MinLimit, MaxLimit, Description, Notes);
- }
- public <#= Class #>() : this("UnnamedStat", 0, 0, 0, null, null) { }
- public <#= Class #>(string name) : this(name, 0, 0, 0, null, null) { }
- public <#= Class #>(string name, <#= T #> value) : this(name, value, 0, 0, null, null) { }
- public <#= Class #>(string name, <#= T #> value, <#= T #> min, <#= T #> max) : this(name, value, min, max, null, null) { }
- public <#= Class #>(string name, <#= T #> value, <#= T #> min, <#= T #> max, string desc, string notes) : base(name, value, min, max, desc, notes) { }
- }
- <# } #>
- }
- <#+
- public struct TypeInfo
- {
- public Type Type { get; set; }
- public string Name { get; set; }
- public string TypeName { get; set; }
- public bool Signed { get; set; }
- public bool Decimal { get; set; }
- public string MateName { get; set; }
- public int BitCount { get; set; }
- public List<string> ImplicitCasts { get; set; }
- public List<string> ExplicitCasts { get; set; }
- }
- #>
Advertisement
Add Comment
Please, Sign In to add comment