mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
Nullables
This commit is contained in:
@ -72,7 +72,6 @@ public class ConstantTemplate : MemberTemplate
|
||||
public static ConstantTemplate MakeConstantTemplate(Type type, FieldInfo ci, byte index = 0, string customName = null, TypeTemplate typeTemplate = null)
|
||||
{
|
||||
var annotationAttr = ci.GetCustomAttribute<AnnotationAttribute>(true);
|
||||
var nullableAttr = ci.GetCustomAttribute<NullableAttribute>(true);
|
||||
|
||||
var valueType = RepresentationType.FromType(ci.FieldType);
|
||||
|
||||
|
@ -82,29 +82,32 @@ public class EventTemplate : MemberTemplate
|
||||
|
||||
var annotationAttr = ei.GetCustomAttribute<AnnotationAttribute>(true);
|
||||
var listenableAttr = ei.GetCustomAttribute<ListenableAttribute>(true);
|
||||
var nullableAttr = ei.GetCustomAttribute<NullableAttribute>(true);
|
||||
var nullableContextAttr = ei.GetCustomAttribute<NullableContextAttribute>(true);
|
||||
|
||||
var flags = nullableAttr?.Flags?.ToList() ?? new List<byte>();
|
||||
evtType.Nullable = new NullabilityInfoContext().Create(ei).ReadState is NullabilityState.Nullable;
|
||||
|
||||
// skip the eventHandler class
|
||||
if (flags.Count > 1)
|
||||
flags = flags.Skip(1).ToList();
|
||||
//var nullableAttr = ei.GetCustomAttribute<NullableAttribute>(true);
|
||||
//var nullableContextAttr = ei.GetCustomAttribute<NullableContextAttribute>(true);
|
||||
|
||||
if (nullableContextAttr?.Flag == 2)
|
||||
{
|
||||
if (flags.Count == 1)
|
||||
evtType.SetNotNull(flags.FirstOrDefault());
|
||||
else
|
||||
evtType.SetNotNull(flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flags.Count == 1)
|
||||
evtType.SetNull(flags.FirstOrDefault());
|
||||
else
|
||||
evtType.SetNull(flags);
|
||||
}
|
||||
//var flags = nullableAttr?.Flags?.ToList() ?? new List<byte>();
|
||||
|
||||
//// skip the eventHandler class
|
||||
//if (flags.Count > 1)
|
||||
// flags = flags.Skip(1).ToList();
|
||||
|
||||
//if (nullableContextAttr?.Flag == 2)
|
||||
//{
|
||||
// if (flags.Count == 1)
|
||||
// evtType.SetNotNull(flags.FirstOrDefault());
|
||||
// else
|
||||
// evtType.SetNotNull(flags);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (flags.Count == 1)
|
||||
// evtType.SetNull(flags.FirstOrDefault());
|
||||
// else
|
||||
// evtType.SetNull(flags);
|
||||
//}
|
||||
|
||||
var et = new EventTemplate(typeTemplate, index, customName ?? ei.Name, ei.DeclaringType != type, evtType);
|
||||
et.EventInfo = ei;
|
||||
|
@ -90,36 +90,42 @@ public class FunctionTemplate : MemberTemplate
|
||||
throw new Exception($"Unsupported type `{mi.ReturnType}` in method `{type.Name}.{mi.Name}` return");
|
||||
|
||||
var annotationAttr = mi.GetCustomAttribute<AnnotationAttribute>(true);
|
||||
var nullableAttr = mi.GetCustomAttribute<NullableAttribute>(true);
|
||||
var nullableContextAttr = mi.GetCustomAttribute<NullableContextAttribute>(true);
|
||||
|
||||
var flags = nullableAttr?.Flags?.ToList() ?? new List<byte>();
|
||||
var nullabilityInfoContext = new NullabilityInfoContext();
|
||||
|
||||
var rtNullableAttr = mi.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(NullableAttribute), true).FirstOrDefault() as NullableAttribute;
|
||||
var rtNullableContextAttr = mi.ReturnTypeCustomAttributes
|
||||
.GetCustomAttributes(typeof(NullableContextAttribute), true)
|
||||
.FirstOrDefault() as NullableContextAttribute
|
||||
?? nullableContextAttr;
|
||||
rtType.Nullable = nullabilityInfoContext.Create(mi.ReturnParameter).WriteState is NullabilityState.Nullable;
|
||||
|
||||
var rtFlags = rtNullableAttr?.Flags?.ToList() ?? new List<byte>();
|
||||
|
||||
if (rtFlags.Count > 0 && genericRtType == typeof(AsyncReply<>))
|
||||
rtFlags.RemoveAt(0);
|
||||
//var nullableAttr = mi.GetCustomAttribute<NullableAttribute>(true);
|
||||
//var nullableContextAttr = mi.GetCustomAttribute<NullableContextAttribute>(true);
|
||||
|
||||
if (rtNullableContextAttr?.Flag == 2)
|
||||
{
|
||||
if (rtFlags.Count == 1)
|
||||
rtType.SetNotNull(rtFlags.FirstOrDefault());
|
||||
else
|
||||
rtType.SetNotNull(rtFlags);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rtFlags.Count == 1)
|
||||
rtType.SetNull(rtFlags.FirstOrDefault());
|
||||
else
|
||||
rtType.SetNull(rtFlags);
|
||||
}
|
||||
//var flags = nullableAttr?.Flags?.ToList() ?? new List<byte>();
|
||||
|
||||
//var rtNullableAttr = mi.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(NullableAttribute), true).FirstOrDefault() as NullableAttribute;
|
||||
//var rtNullableContextAttr = mi.ReturnTypeCustomAttributes
|
||||
// .GetCustomAttributes(typeof(NullableContextAttribute), true)
|
||||
// .FirstOrDefault() as NullableContextAttribute
|
||||
// ?? nullableContextAttr;
|
||||
|
||||
//var rtFlags = rtNullableAttr?.Flags?.ToList() ?? new List<byte>();
|
||||
|
||||
//if (rtFlags.Count > 0 && genericRtType == typeof(AsyncReply<>))
|
||||
// rtFlags.RemoveAt(0);
|
||||
|
||||
//if (rtNullableContextAttr?.Flag == 2)
|
||||
//{
|
||||
// if (rtFlags.Count == 1)
|
||||
// rtType.SetNotNull(rtFlags.FirstOrDefault());
|
||||
// else
|
||||
// rtType.SetNotNull(rtFlags);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (rtFlags.Count == 1)
|
||||
// rtType.SetNull(rtFlags.FirstOrDefault());
|
||||
// else
|
||||
// rtType.SetNull(rtFlags);
|
||||
//}
|
||||
|
||||
var args = mi.GetParameters();
|
||||
|
||||
@ -136,27 +142,28 @@ public class FunctionTemplate : MemberTemplate
|
||||
if (argType == null)
|
||||
throw new Exception($"Unsupported type `{x.ParameterType}` in method `{type.Name}.{mi.Name}` parameter `{x.Name}`");
|
||||
|
||||
argType.Nullable = nullabilityInfoContext.Create(x).WriteState is NullabilityState.Nullable;
|
||||
|
||||
var argNullableAttr = x.GetCustomAttribute<NullableAttribute>(true);
|
||||
var argNullableContextAttr = x.GetCustomAttribute<NullableContextAttribute>(true) ?? nullableContextAttr;
|
||||
//var argNullableAttr = x.GetCustomAttribute<NullableAttribute>(true);
|
||||
//var argNullableContextAttr = x.GetCustomAttribute<NullableContextAttribute>(true) ?? nullableContextAttr;
|
||||
|
||||
var argFlags = argNullableAttr?.Flags?.ToList() ?? new List<byte>();
|
||||
//var argFlags = argNullableAttr?.Flags?.ToList() ?? new List<byte>();
|
||||
|
||||
|
||||
if (argNullableContextAttr?.Flag == 2)
|
||||
{
|
||||
if (argFlags.Count == 1)
|
||||
argType.SetNotNull(argFlags.FirstOrDefault());
|
||||
else
|
||||
argType.SetNotNull(argFlags);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rtFlags.Count == 1)
|
||||
argType.SetNull(argFlags.FirstOrDefault());
|
||||
else
|
||||
argType.SetNull(argFlags);
|
||||
}
|
||||
//if (argNullableContextAttr?.Flag == 2)
|
||||
//{
|
||||
// if (argFlags.Count == 1)
|
||||
// argType.SetNotNull(argFlags.FirstOrDefault());
|
||||
// else
|
||||
// argType.SetNotNull(argFlags);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (rtFlags.Count == 1)
|
||||
// argType.SetNull(argFlags.FirstOrDefault());
|
||||
// else
|
||||
// argType.SetNull(argFlags);
|
||||
//}
|
||||
|
||||
return new ArgumentTemplate()
|
||||
{
|
||||
|
@ -139,6 +139,9 @@ public class PropertyTemplate : MemberTemplate
|
||||
RepresentationType valueType, string readAnnotation = null, string writeAnnotation = null, bool recordable = false)
|
||||
: base(template, index, name, inherited)
|
||||
{
|
||||
if (name == "RecordNullable")
|
||||
Console.Beep();
|
||||
|
||||
this.Recordable = recordable;
|
||||
//this.Storage = storage;
|
||||
if (readAnnotation != null)
|
||||
@ -163,28 +166,32 @@ public class PropertyTemplate : MemberTemplate
|
||||
var annotationAttr = pi.GetCustomAttribute<AnnotationAttribute>(true);
|
||||
var storageAttr = pi.GetCustomAttribute<StorageAttribute>(true);
|
||||
|
||||
var nullableContextAttr = pi.GetCustomAttribute<NullableContextAttribute>(true);
|
||||
var nullableAttr = pi.GetCustomAttribute<NullableAttribute>(true);
|
||||
var nullabilityContext = new NullabilityInfoContext();
|
||||
propType.Nullable = nullabilityContext.Create(pi).ReadState is NullabilityState.Nullable;
|
||||
|
||||
var flags = nullableAttr?.Flags?.ToList() ?? new List<byte>();
|
||||
|
||||
if (flags.Count > 0 && genericPropType == typeof(DistributedPropertyContext<>))
|
||||
flags.RemoveAt(0);
|
||||
// var nullableContextAttr = pi.GetCustomAttribute<NullableContextAttribute>(true);
|
||||
// var nullableAttr = pi.GetCustomAttribute<NullableAttribute>(true);
|
||||
|
||||
if (nullableContextAttr?.Flag == 2)
|
||||
{
|
||||
if (flags.Count == 1)
|
||||
propType.SetNotNull(flags.FirstOrDefault());
|
||||
else
|
||||
propType.SetNotNull(flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flags.Count == 1)
|
||||
propType.SetNull(flags.FirstOrDefault());
|
||||
else
|
||||
propType.SetNull(flags);
|
||||
}
|
||||
// var flags = nullableAttr?.Flags?.ToList() ?? new List<byte>();
|
||||
|
||||
// if (flags.Count > 0 && genericPropType == typeof(DistributedPropertyContext<>))
|
||||
// flags.RemoveAt(0);
|
||||
|
||||
// if (nullableContextAttr?.Flag == 2)
|
||||
// {
|
||||
// if (flags.Count == 1)
|
||||
// propType.SetNotNull(flags.FirstOrDefault());
|
||||
// else
|
||||
// propType.SetNotNull(flags);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (flags.Count == 1)
|
||||
// propType.SetNull(flags.FirstOrDefault());
|
||||
// else
|
||||
// propType.SetNull(flags);
|
||||
// }
|
||||
|
||||
var pt = new PropertyTemplate(typeTemplate, index, customName ?? pi.Name, pi.DeclaringType != type, propType);
|
||||
|
||||
|
@ -376,7 +376,6 @@ public class TypeTemplate
|
||||
public static ConstantTemplate MakeConstantTemplate(Type type, FieldInfo ci, ExportAttribute exportAttr, byte index = 0, TypeTemplate typeTemplate = null)
|
||||
{
|
||||
var annotationAttr = ci.GetCustomAttribute<AnnotationAttribute>(true);
|
||||
var nullableAttr = ci.GetCustomAttribute<NullableAttribute>(true);
|
||||
|
||||
var valueType = RepresentationType.FromType(ci.FieldType);
|
||||
|
||||
|
Reference in New Issue
Block a user