-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from rafaelsc/rafaelsc/genericAttribute
Add Support to C#11 Generic Attributes
- Loading branch information
Showing
10 changed files
with
659 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
sandbox/Generated/UnitGenerator/UnitGenerator.SourceGenerator/FileGenerate.Aa.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// <auto-generated> | ||
// THIS (.cs) FILE IS GENERATED BY UnitGenerator. DO NOT CHANGE IT. | ||
// </auto-generated> | ||
#pragma warning disable CS8669 | ||
using System; | ||
using System.Globalization; | ||
#if NET7_0_OR_GREATER | ||
using System.Numerics; | ||
#endif | ||
namespace FileGenerate | ||
{ | ||
[System.ComponentModel.TypeConverter(typeof(AaTypeConverter))] | ||
readonly partial struct Aa | ||
: IEquatable<Aa> | ||
#if NET7_0_OR_GREATER | ||
, IEqualityOperators<Aa, Aa, bool> | ||
#endif | ||
{ | ||
readonly int value; | ||
|
||
public int AsPrimitive() => value; | ||
|
||
public Aa(int value) | ||
{ | ||
this.value = value; | ||
} | ||
|
||
public static explicit operator int(Aa value) | ||
{ | ||
return value.value; | ||
} | ||
|
||
public static explicit operator Aa(int value) | ||
{ | ||
return new Aa(value); | ||
} | ||
|
||
public bool Equals(Aa other) | ||
{ | ||
return value.Equals(other.value); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (obj == null) return false; | ||
var t = obj.GetType(); | ||
if (t == typeof(Aa)) | ||
{ | ||
return Equals((Aa)obj); | ||
} | ||
if (t == typeof(int)) | ||
{ | ||
return value.Equals((int)obj); | ||
} | ||
|
||
return value.Equals(obj); | ||
} | ||
|
||
public static bool operator ==(Aa x, Aa y) | ||
{ | ||
return x.value.Equals(y.value); | ||
} | ||
|
||
public static bool operator !=(Aa x, Aa y) | ||
{ | ||
return !x.value.Equals(y.value); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return value.GetHashCode(); | ||
} | ||
|
||
public override string ToString() => value.ToString(); | ||
|
||
// Default | ||
|
||
private class AaTypeConverter : System.ComponentModel.TypeConverter | ||
{ | ||
private static readonly Type WrapperType = typeof(Aa); | ||
private static readonly Type ValueType = typeof(int); | ||
|
||
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, Type sourceType) | ||
{ | ||
if (sourceType == WrapperType || sourceType == ValueType) | ||
{ | ||
return true; | ||
} | ||
|
||
return base.CanConvertFrom(context, sourceType); | ||
} | ||
|
||
public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, Type destinationType) | ||
{ | ||
if (destinationType == WrapperType || destinationType == ValueType) | ||
{ | ||
return true; | ||
} | ||
|
||
return base.CanConvertTo(context, destinationType); | ||
} | ||
|
||
public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) | ||
{ | ||
if (value != null) | ||
{ | ||
var t = value.GetType(); | ||
if (t == typeof(Aa)) | ||
{ | ||
return (Aa)value; | ||
} | ||
if (t == typeof(int)) | ||
{ | ||
return new Aa((int)value); | ||
} | ||
} | ||
|
||
return base.ConvertFrom(context, culture, value); | ||
} | ||
|
||
public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) | ||
{ | ||
if (value is Aa wrappedValue) | ||
{ | ||
if (destinationType == WrapperType) | ||
{ | ||
return wrappedValue; | ||
} | ||
|
||
if (destinationType == ValueType) | ||
{ | ||
return wrappedValue.AsPrimitive(); | ||
} | ||
} | ||
|
||
return base.ConvertTo(context, culture, value, destinationType); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
sandbox/Generated/UnitGenerator/UnitGenerator.SourceGenerator/FileGenerate.Bb.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// <auto-generated> | ||
// THIS (.cs) FILE IS GENERATED BY UnitGenerator. DO NOT CHANGE IT. | ||
// </auto-generated> | ||
#pragma warning disable CS8669 | ||
using System; | ||
using System.Globalization; | ||
#if NET7_0_OR_GREATER | ||
using System.Numerics; | ||
#endif | ||
namespace FileGenerate | ||
{ | ||
[System.ComponentModel.TypeConverter(typeof(BbTypeConverter))] | ||
readonly partial struct Bb | ||
: IEquatable<Bb> | ||
#if NET7_0_OR_GREATER | ||
, IEqualityOperators<Bb, Bb, bool> | ||
#endif | ||
{ | ||
readonly string value; | ||
|
||
public string AsPrimitive() => value; | ||
|
||
public Bb(string value) | ||
{ | ||
this.value = value; | ||
} | ||
|
||
public static explicit operator string(Bb value) | ||
{ | ||
return value.value; | ||
} | ||
|
||
public static explicit operator Bb(string value) | ||
{ | ||
return new Bb(value); | ||
} | ||
|
||
public bool Equals(Bb other) | ||
{ | ||
return value.Equals(other.value); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (obj == null) return false; | ||
var t = obj.GetType(); | ||
if (t == typeof(Bb)) | ||
{ | ||
return Equals((Bb)obj); | ||
} | ||
if (t == typeof(string)) | ||
{ | ||
return value.Equals((string)obj); | ||
} | ||
|
||
return value.Equals(obj); | ||
} | ||
|
||
public static bool operator ==(Bb x, Bb y) | ||
{ | ||
return x.value.Equals(y.value); | ||
} | ||
|
||
public static bool operator !=(Bb x, Bb y) | ||
{ | ||
return !x.value.Equals(y.value); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return value.GetHashCode(); | ||
} | ||
|
||
public override string ToString() => value == null ? "null" : value.ToString(); | ||
|
||
// Default | ||
|
||
private class BbTypeConverter : System.ComponentModel.TypeConverter | ||
{ | ||
private static readonly Type WrapperType = typeof(Bb); | ||
private static readonly Type ValueType = typeof(string); | ||
|
||
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, Type sourceType) | ||
{ | ||
if (sourceType == WrapperType || sourceType == ValueType) | ||
{ | ||
return true; | ||
} | ||
|
||
return base.CanConvertFrom(context, sourceType); | ||
} | ||
|
||
public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, Type destinationType) | ||
{ | ||
if (destinationType == WrapperType || destinationType == ValueType) | ||
{ | ||
return true; | ||
} | ||
|
||
return base.CanConvertTo(context, destinationType); | ||
} | ||
|
||
public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) | ||
{ | ||
if (value != null) | ||
{ | ||
var t = value.GetType(); | ||
if (t == typeof(Bb)) | ||
{ | ||
return (Bb)value; | ||
} | ||
if (t == typeof(string)) | ||
{ | ||
return new Bb((string)value); | ||
} | ||
} | ||
|
||
return base.ConvertFrom(context, culture, value); | ||
} | ||
|
||
public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) | ||
{ | ||
if (value is Bb wrappedValue) | ||
{ | ||
if (destinationType == WrapperType) | ||
{ | ||
return wrappedValue; | ||
} | ||
|
||
if (destinationType == ValueType) | ||
{ | ||
return wrappedValue.AsPrimitive(); | ||
} | ||
} | ||
|
||
return base.ConvertTo(context, culture, value, destinationType); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.