Beispiel #1
0
        public virtual bool IsValid <TMeta>(ILogger <IValidatable> logger, TMeta info) where TMeta : IMetaInfo
        {
            var usage   = GetType().GetAttribute <AttributeUsageAttribute>();
            var validOn = usage.ValidOn;

            var message = $"This attribute is not valid on type {info.GetType().Name} called {info.GetPath()}.";

            if (!(validOn.HasFlag(AttributeTargets.Class) || validOn.HasFlag(AttributeTargets.Struct) || validOn.HasFlag(AttributeTargets.Enum)) && info is ITypeInfo)
            {
                throw new Exception(message);
            }

            if (!validOn.HasFlag(AttributeTargets.Property) && info is IPropertyInfo)
            {
                throw new Exception(message);
            }

            if (!validOn.HasFlag(AttributeTargets.Method) && info is IFunctionInfo)
            {
                throw new Exception(message);
            }

            if (!validOn.HasFlag(AttributeTargets.Delegate) && info is IEventInfo)
            {
                throw new Exception(message);
            }

            if (!validOn.HasFlag(AttributeTargets.Parameter) && info is IParameterInfo)
            {
                throw new Exception(message);
            }

            ITypeInfo outer = null;

            if (info is ITypeInfo typeInfo)
            {
                outer = typeInfo;
            }
            else if (info is IMemberInfo memberInfo)
            {
                outer = memberInfo.DeclaringType;
            }

            if (outer != null)
            {
                if (!outer.HasAttribute <ExportAttribute>())
                {
                    throw new Exception($"Type {outer.GetPath()} should have the [Export] attribute.");
                }
            }

            return(true);
        }
Beispiel #2
0
        public override string TransformType(ITypeInfo type)
        {
            var result = base.TransformType(type);

            var nativeType = type.Native;

            if (nativeType == typeof(string))
            {
                result = "FString";
            }
            else if (nativeType == typeof(Vector3 <float>) || nativeType == typeof(Vector3 <double>))
            {
                result = "FVector";
            }
            else if (nativeType == typeof(Vector2 <float>) || nativeType == typeof(Vector2 <double>))
            {
                result = "FVector2D";
            }
            else if (nativeType == typeof(Vector4 <float>) || nativeType == typeof(Vector4 <double>))
            {
                result = "FVector4";
            }
            else if (nativeType == typeof(Quaternion <float>) || nativeType == typeof(Quaternion <double>))
            {
                result = "FQuat";
            }
            else if (nativeType == typeof(Rotation <float>) || nativeType == typeof(Rotation <double>))
            {
                result = "FRotator";
            }
            else if (nativeType == typeof(Box <float>) || nativeType == typeof(Box <double>))
            {
                result = "FBox";
            }
            else if (nativeType == typeof(Rect <float>) || nativeType == typeof(Rect <double>))
            {
                result = "FBox2D";
            }
            else
            {
                result = NameTransformer.TransformName(type, type.Name, NameContext.Type);
            }
            result = result.Trim();

            if (string.IsNullOrEmpty(result))
            {
                throw new NotSupportedException($"Type {type.GetPath()} not resolved in {nameof(UnrealTypeTransformer)}.");
            }

            return(result);
        }
Beispiel #3
0
        private static void DeconstructPath(ILogger <IValidatable> logger, ITypeInfo type, string path, ref List <IMemberInfo> result)
        {
            if (path.Length == 0)
            {
                return;
            }

            var actualProperties = type.Properties;
            var propertyName     = path.Split('.')[0];

            var actualProperty = actualProperties.FirstOrDefault(o => o.Name == propertyName);

            if (actualProperty == null)
            {
                if (logger != null)
                {
                    logger.LogError(
                        $"Tried to deconstruct with invalid property name ({propertyName}) on type {type.GetPath()}.");
                }
                else
                {
                    throw new Exception(
                              $"Tried to deconstruct with invalid property name ({propertyName}) on type {type.GetPath()}.");
                }
            }

            // TODO: Needs metadataprovider
            result.Add(new ProxyMemberInfo <ITypeInfo>(null, actualProperty.Type, propertyName));

            if (!path.Contains('.'))
            {
                return;
            }

            path = path.Substring(path.IndexOf('.') + 1);
            DeconstructPath(logger, actualProperty.Type, path, ref result);
        }