예제 #1
0
        private static ConversionType DetermineConversionType(ConversionQuery query)
        {
            var source      = query.source;
            var destination = query.destination;

            if (source == null)
            {
                if (destination.IsNullable())
                {
                    return(ConversionType.Identity);
                }
                else
                {
                    return(ConversionType.Impossible);
                }
            }

            Ensure.That(nameof(destination)).IsNotNull(destination);

            if (RespectsIdentity(source, destination))
            {
                return(ConversionType.Identity);
            }
            else if (IsUpcast(source, destination))
            {
                return(ConversionType.Upcast);
            }
            else if (IsDowncast(source, destination))
            {
                return(ConversionType.Downcast);
            }
            // Disabling *.ToString conversion, because it's more often than otherwise very confusing

            /*else if (ExpectsString(source, destination))
             * {
             *  return ConversionType.ToString;
             * }*/
            else if (HasImplicitNumericConversion(source, destination))
            {
                return(ConversionType.NumericImplicit);
            }
            else if (HasExplicitNumericConversion(source, destination))
            {
                return(ConversionType.NumericExplicit);
            }
            else if (HasUnityHierarchyConversion(source, destination))
            {
                return(ConversionType.UnityHierarchy);
            }
            else if (HasEnumerableToArrayConversion(source, destination))
            {
                return(ConversionType.EnumerableToArray);
            }
            else if (HasEnumerableToListConversion(source, destination))
            {
                return(ConversionType.EnumerableToList);
            }
            else
            {
                var userDefinedConversionType = GetUserDefinedConversionType(source, destination);

                if (userDefinedConversionType != ConversionType.Impossible)
                {
                    return(userDefinedConversionType);
                }
            }

            return(ConversionType.Impossible);
        }
예제 #2
0
 public TypeOptionTree(IEnumerable <Type> types) : this()
 {
     Ensure.That(nameof(types)).IsNotNull(types);
     this.types = types.ToHashSet();
 }
예제 #3
0
        public ValueInput(string key, Type type) : base(key)
        {
            Ensure.That(nameof(type)).IsNotNull(type);

            this.type = type;
        }
예제 #4
0
        public bool ValidateOption(IUnitOption option)
        {
            Ensure.That(nameof(option)).IsNotNull(option);

            if (!NoControlInput && option.controlInputCount == 0)
            {
                return(false);
            }
            if (!SingleControlInput && option.controlInputCount == 1)
            {
                return(false);
            }
            if (!MultipleControlInputs && option.controlInputCount > 1)
            {
                return(false);
            }

            if (!NoValueInput && option.valueInputTypes.Count == 0)
            {
                return(false);
            }
            if (!SingleValueInput && option.valueInputTypes.Count == 1)
            {
                return(false);
            }
            if (!MultipleValueInputs && option.valueInputTypes.Count > 1)
            {
                return(false);
            }

            if (!NoControlOutput && option.controlOutputCount == 0)
            {
                return(false);
            }
            if (!SingleControlOutput && option.controlOutputCount == 1)
            {
                return(false);
            }
            if (!MultipleControlOutputs && option.controlOutputCount > 1)
            {
                return(false);
            }

            if (!NoValueOutput && option.valueOutputTypes.Count == 0)
            {
                return(false);
            }
            if (!SingleValueOutput && option.valueOutputTypes.Count == 1)
            {
                return(false);
            }
            if (!MultipleValueOutputs && option.valueOutputTypes.Count > 1)
            {
                return(false);
            }

            var unitType = option.unitType;

            if (!Normals && !unitType.HasAttribute <SpecialUnitAttribute>())
            {
                return(false);
            }

            if (!Self && option.UnitIs <This>())
            {
                return(false);
            }

            if (!Events && option.UnitIs <IEventUnit>())
            {
                return(false);
            }

            if (!Literals && option.UnitIs <Literal>())
            {
                return(false);
            }

            if (!Variables && option.UnitIs <IUnifiedVariableUnit>())
            {
                return(false);
            }

            if (!Members && option.UnitIs <MemberUnit>())
            {
                return(false);
            }

            if (!Nesters && option.UnitIs <INesterUnit>())
            {
                return(false);
            }

            if (!Expose && option.UnitIs <Expose>())
            {
                return(false);
            }

            if (!Obsolete && unitType.HasAttribute <ObsoleteAttribute>())
            {
                return(false);
            }

            if (CompatibleInputType != null && !option.HasCompatibleValueInput(CompatibleInputType))
            {
                return(false);
            }

            if (CompatibleOutputType != null && !option.HasCompatibleValueOutput(CompatibleOutputType))
            {
                return(false);
            }

            if (!AllowSelfNestedGraph && option.UnitIs <SuperUnit>())
            {
                if (((SuperUnit)option.unit).nest.graph.GetHashCode() == GraphHashCode)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #5
0
        public static VariableDeclarations For(Scene?scene)
        {
            Ensure.That(nameof(scene)).IsNotNull(scene);

            return(Instance(scene.Value).variables.declarations);
        }
예제 #6
0
        public static string GetPluginRuntimeGUID(Plugin plugin)
        {
            Ensure.That(nameof(plugin)).IsNotNull(plugin);

            return(AssetDatabase.AssetPathToGUID(PathUtility.FromProject(plugin.runtimeAssembly.Location)));
        }
예제 #7
0
        protected override void SetItem(int index, T item)
        {
            Ensure.That(nameof(item)).IsNotNull(item);

            base.SetItem(index, item);
        }
예제 #8
0
        public static EditorTexture Member(MemberInfo member, ActionDirection direction)
        {
            Ensure.That(nameof(member)).IsNotNull(member);

            var method      = member as MethodInfo;
            var field       = member as FieldInfo;
            var property    = member as PropertyInfo;
            var constructor = member as ConstructorInfo;

            if (method != null)
            {
                if (method.IsExtension())
                {
                    return(Language.extensionMethod.@public);
                }

                if (method.IsPrivate)
                {
                    return(Language.method.@private);
                }

                if (method.IsFamily)
                {
                    return(Language.method.@protected);
                }

                if (method.IsAssembly)
                {
                    return(Language.method.@internal);
                }

                if (method.IsPublic)
                {
                    return(Language.method.@public);
                }
            }
            else if (constructor != null)
            {
                if (constructor.IsPrivate)
                {
                    return(Language.constructor.@private);
                }

                if (constructor.IsFamily)
                {
                    return(Language.constructor.@protected);
                }

                if (constructor.IsAssembly)
                {
                    return(Language.constructor.@internal);
                }

                if (constructor.IsPublic)
                {
                    return(Language.constructor.@public);
                }
            }
            else if (field != null)
            {
                if (field.IsLiteral)
                {
                    if (field.IsPrivate)
                    {
                        return(Language.method.@private);
                    }

                    if (field.IsFamily)
                    {
                        return(Language.method.@protected);
                    }

                    if (field.IsAssembly)
                    {
                        return(Language.method.@internal);
                    }

                    if (field.IsPublic)
                    {
                        return(Language.method.@public);
                    }
                }
                else
                {
                    if (field.IsPrivate)
                    {
                        return(Language.method.@private);
                    }

                    if (field.IsFamily)
                    {
                        return(Language.method.@protected);
                    }

                    if (field.IsAssembly)
                    {
                        return(Language.method.@internal);
                    }

                    if (field.IsPublic)
                    {
                        return(Language.method.@public);
                    }
                }
            }
            else if (property != null)
            {
                var accessors = property.GetAccessors(true);
                var getter    = accessors.FirstOrDefault(accessor => accessor.ReturnType != typeof(void));
                var setter    = accessors.FirstOrDefault(accessor => accessor.ReturnType == typeof(void));

                bool isPrivate, isProtected, isInternal, isPublic;

                if (direction == ActionDirection.Any)
                {
                    isPrivate = getter == null || getter.IsPrivate || setter == null || setter.IsPrivate;

                    if (isPrivate)
                    {
                        isProtected = false;
                        isInternal  = false;
                        isPublic    = false;
                    }
                    else
                    {
                        isProtected = getter.IsFamily || setter.IsFamily;
                        isInternal  = getter.IsAssembly || setter.IsAssembly;
                        isPublic    = getter.IsPublic && setter.IsPublic;
                    }
                }
                else if (direction == ActionDirection.Get && getter != null)
                {
                    isPrivate   = getter.IsPrivate;
                    isProtected = getter.IsFamily;
                    isInternal  = getter.IsAssembly;
                    isPublic    = getter.IsPublic;
                }
                else if (direction == ActionDirection.Set && setter != null)
                {
                    isPrivate   = setter.IsPrivate;
                    isProtected = setter.IsFamily;
                    isInternal  = setter.IsAssembly;
                    isPublic    = setter.IsPublic;
                }
                else
                {
                    return(null);
                }

                if (isPrivate)
                {
                    return(Language.property.@private);
                }

                if (isProtected)
                {
                    return(Language.property.@protected);
                }

                if (isInternal)
                {
                    return(Language.property.@internal);
                }

                if (isPublic)
                {
                    return(Language.property.@public);
                }
            }

            return(null);
        }
        public VariableNameInspector(Metadata metadata, Func <IEnumerable <string> > getSuggestions) : base(metadata)
        {
            Ensure.That(nameof(getSuggestions)).IsNotNull(getSuggestions);

            this.getSuggestions = getSuggestions;
        }
예제 #10
0
        private string NormalizeFileName(string fileName)
        {
            Ensure.That(nameof(fileName)).IsNotNull(fileName);

            return(fileName);
        }
예제 #11
0
        public static bool StartsWith(this string s, char c)
        {
            Ensure.That(nameof(s)).IsNotNull(s);

            return(s[0] == c);
        }
예제 #12
0
        // Faster equivalents for chars

        public static bool EndsWith(this string s, char c)
        {
            Ensure.That(nameof(s)).IsNotNull(s);

            return(s[s.Length - 1] == c);
        }
예제 #13
0
        public bool ValidateType(Type type)
        {
            Ensure.That(nameof(type)).IsNotNull(type);

            if (!Generic && type.IsGenericType)
            {
                return(false);
            }
            if (!OpenConstructedGeneric && type.ContainsGenericParameters)
            {
                return(false);
            }
            if (!Value && type.IsValueType)
            {
                return(false);
            }
            if (!Reference && !type.IsValueType)
            {
                return(false);
            }
            if (!Classes && type.IsClass)
            {
                return(false);
            }
            if (!Interfaces && type.IsInterface)
            {
                return(false);
            }
            if (!Structs && (type.IsValueType && !type.IsEnum && !type.IsPrimitive))
            {
                return(false);
            }
            if (!Enums && type.IsEnum)
            {
                return(false);
            }
            if (!Public && type.IsVisible)
            {
                return(false);
            }
            if (!NonPublic && !type.IsVisible)
            {
                return(false);
            }
            if (!Abstract && type.IsAbstract())
            {
                return(false);
            }
            if (!Static && type.IsStatic())
            {
                return(false);
            }
            if (!Sealed && type.IsSealed)
            {
                return(false);
            }
            if (!Nested && type.IsNested)
            {
                return(false);
            }
            if (!Primitives && type.IsPrimitive)
            {
                return(false);
            }
            if (!Object && type == typeof(object))
            {
                return(false);
            }
            if (!NonSerializable && !type.IsSerializable)
            {
                return(false);
            }
            if (type.IsSpecialName || type.HasAttribute <CompilerGeneratedAttribute>())
            {
                return(false);
            }
            if (!Obsolete && type.HasAttribute <ObsoleteAttribute>())
            {
                return(false);
            }

            var valid = true;

            if (Types.Count > 0)
            {
                valid = Matching == TypesMatching.AssignableToAll;

                foreach (var allowedType in Types)
                {
                    if (Matching == TypesMatching.Any)
                    {
                        if (type == allowedType)
                        {
                            valid = true;
                            break;
                        }
                    }
                    else if (Matching == TypesMatching.ConvertibleToAny)
                    {
                        if (type.IsConvertibleTo(allowedType, true))
                        {
                            valid = true;
                            break;
                        }
                    }
                    else if (Matching == TypesMatching.AssignableToAll)
                    {
                        valid &= allowedType.IsAssignableFrom(type);

                        if (!valid)
                        {
                            break;
                        }
                    }
                    else
                    {
                        throw new UnexpectedEnumValueException <TypesMatching>(Matching);
                    }
                }
            }

            return(valid);
        }
예제 #14
0
        public string NormalizePath(string path)
        {
            Ensure.That(nameof(path)).IsNotNull(path);

            return(Path.Combine(root, path));
        }
예제 #15
0
        protected VariableUnit(string defaultName)
        {
            Ensure.That(nameof(defaultName)).IsNotNull(defaultName);

            this.defaultName = defaultName;
        }
예제 #16
0
        public string DebugPath(string path)
        {
            Ensure.That(nameof(path)).IsNotNull(path);

            return(NormalizePath(path));
        }
예제 #17
0
        protected IList <T> GetListForItem(T item)
        {
            Ensure.That(nameof(item)).IsNotNull(item);

            return(GetListForType(item.GetType()));
        }
예제 #18
0
        private EditorTexture(Texture2D texture) : this()
        {
            Ensure.That(nameof(texture)).IsNotNull(texture);

            personal.Add(texture.width, texture);
        }
예제 #19
0
        public ObjectMetadata StaticObject(object @object)
        {
            Ensure.That(nameof(@object)).IsNotNull(@object);

            return(StaticObject(@object, @object.GetType()));
        }
예제 #20
0
        public static int GetFileID(Type type)
        {
            Ensure.That(nameof(type)).IsNotNull(type);

            return(GetFileID(type.Namespace, type.Name));
        }
예제 #21
0
        public CastMetadata Cast(Type type)
        {
            Ensure.That(nameof(type)).IsNotNull(type);

            return(Dig(type, digCast.Get(type), true));
        }
예제 #22
0
        public static string SerializeType(Type type)
        {
            Ensure.That(nameof(type)).IsNotNull(type);

            return(type?.FullName);
        }
예제 #23
0
        public EnumOptionTree(Type enumType) : base(new GUIContent(enumType.HumanName()))
        {
            Ensure.That(nameof(enumType)).IsNotNull(enumType);

            enums = Enum.GetValues(enumType).Cast <Enum>().ToList();
        }
예제 #24
0
        private void GenerateStubScript(string scriptPath, IEnumerable <AotStubWriter> stubWriters)
        {
            Ensure.That(nameof(stubWriters)).IsNotNull(stubWriters);

            var unit = new CodeCompileUnit();

            var @namespace = new CodeNamespace("Unity.VisualScripting.Generated.Aot");

            unit.Namespaces.Add(@namespace);

            var @class = new CodeTypeDeclaration("AotStubs")
            {
                IsClass = true
            };

            @class.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(PreserveAttribute))));

            @namespace.Types.Add(@class);

            var usedMethodNames = new HashSet <string>();

            foreach (var stubWriter in stubWriters.OrderBy(sw => sw.stubMethodComment))
            {
                if (stubWriter.skip)
                {
                    continue;
                }

                var methodName = stubWriter.stubMethodName;

                var i = 0;

                while (usedMethodNames.Contains(methodName))
                {
                    methodName = stubWriter.stubMethodName + "_" + i++;
                }

                usedMethodNames.Add(methodName);

                @class.Comments.Add(new CodeCommentStatement(stubWriter.stubMethodComment));

                var @method = new CodeMemberMethod
                {
                    Name       = methodName,
                    ReturnType = new CodeTypeReference(typeof(void)),
                    Attributes = MemberAttributes.Public | MemberAttributes.Static
                };

                @method.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(PreserveAttribute), CodeTypeReferenceOptions.GlobalReference)));

                @method.Comments.Add(new CodeCommentStatement(stubWriter.stubMethodComment));

                @method.Statements.AddRange(stubWriter.GetStubStatements().ToArray());

                @class.Members.Add(@method);
            }

            PathUtility.CreateDirectoryIfNeeded(BoltCore.Paths.transientGenerated);

            PathUtility.DeleteProjectFileIfExists(aotStubsPath, true);

            using (var provider = CodeDomProvider.CreateProvider("CSharp"))
            {
                var options = new CodeGeneratorOptions
                {
                    BracingStyle             = "C",
                    IndentString             = "\t",
                    BlankLinesBetweenMembers = true,
                    ElseOnClosing            = false,
                    VerbatimOrder            = true
                };

                using (var scriptWriter = new StreamWriter(scriptPath))
                {
                    provider.GenerateCodeFromCompileUnit(new CodeSnippetCompileUnit("#pragma warning disable 219"), scriptWriter, options); // Disable unused variable warning
                    provider.GenerateCodeFromCompileUnit(unit, scriptWriter, options);
                }
            }

            AssetDatabase.Refresh();
        }
예제 #25
0
        public UnitPortDescriptor(IUnitPort target)
        {
            Ensure.That(nameof(target)).IsNotNull(target);

            this.target = target;
        }
예제 #26
0
        internal static IEnumerable <Type> GetLinkedTypes(Type linkedType, string pluginId)
        {
            Ensure.That(nameof(linkedType)).IsNotNull(linkedType);

            return(Codebase.ludiqEditorTypes.Where(t => linkedType.IsAssignableFrom(t) && t.IsConcrete() && t.HasAttribute <PluginAttribute>() && t.GetAttribute <PluginAttribute>().id == pluginId));
        }
예제 #27
0
        protected static bool CompareNames(Flow flow, ValueInput namePort, string calledName)
        {
            Ensure.That(nameof(calledName)).IsNotNull(calledName);

            return(calledName.Trim().Equals(flow.GetValue <string>(namePort)?.Trim(), StringComparison.OrdinalIgnoreCase));
        }
예제 #28
0
        public static ConversionType GetRequiredConversion(object value, Type type)
        {
            Ensure.That(nameof(type)).IsNotNull(type);

            return(GetRequiredConversion(value?.GetType(), type));
        }
예제 #29
0
        public static IEnumerable <T> Catch <T>(this IEnumerable <T> source, ICollection <Exception> exceptions)
        {
            Ensure.That(nameof(exceptions)).IsNotNull(exceptions);

            return(source.Catch(exceptions.Add));
        }