Example #1
0
        public static string ToFlagString(this StrictNullFlags strictNullFlags)
        {
            var result = "";

            if (strictNullFlags.HasFlag(StrictNullFlags.Null))
            {
                result += "null ";
            }
            if (strictNullFlags.HasFlag(StrictNullFlags.Undefined))
            {
                result += "undefined ";
            }

            return(result.TrimEnd().Replace(" ", "|"));
        }
Example #2
0
        private string GetStrictNullChecksTypeSuffix(MemberInfo memberInfo, StrictNullFlags csNullableTranslation)
        {
            Type memberType = memberInfo is PropertyInfo info
                ? info.PropertyType
                : ((FieldInfo)memberInfo).FieldType;

            StrictNullFlags flags = Nullable.GetUnderlyingType(memberType) != null ? csNullableTranslation : StrictNullFlags.Regular;

            if (_metadataReader.GetAttribute <TsNullAttribute>(memberInfo) != null)
            {
                flags |= StrictNullFlags.Null;
            }
            if (_metadataReader.GetAttribute <TsUndefinedAttribute>(memberInfo) != null)
            {
                flags |= StrictNullFlags.Undefined;
            }

            if (_metadataReader.GetAttribute <TsNotNullAttribute>(memberInfo) != null)
            {
                flags &= ~StrictNullFlags.Null;
            }
            if (_metadataReader.GetAttribute <TsNotUndefinedAttribute>(memberInfo) != null)
            {
                flags &= ~StrictNullFlags.Undefined;
            }

            var result = "";

            if (flags.HasFlag(StrictNullFlags.Null))
            {
                result += " | null";
            }
            if (flags.HasFlag(StrictNullFlags.Undefined))
            {
                result += " | undefined";
            }

            return(result);
        }