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); }
public TypeOptionTree(IEnumerable <Type> types) : this() { Ensure.That(nameof(types)).IsNotNull(types); this.types = types.ToHashSet(); }
public ValueInput(string key, Type type) : base(key) { Ensure.That(nameof(type)).IsNotNull(type); this.type = type; }
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); }
public static VariableDeclarations For(Scene?scene) { Ensure.That(nameof(scene)).IsNotNull(scene); return(Instance(scene.Value).variables.declarations); }
public static string GetPluginRuntimeGUID(Plugin plugin) { Ensure.That(nameof(plugin)).IsNotNull(plugin); return(AssetDatabase.AssetPathToGUID(PathUtility.FromProject(plugin.runtimeAssembly.Location))); }
protected override void SetItem(int index, T item) { Ensure.That(nameof(item)).IsNotNull(item); base.SetItem(index, item); }
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; }
private string NormalizeFileName(string fileName) { Ensure.That(nameof(fileName)).IsNotNull(fileName); return(fileName); }
public static bool StartsWith(this string s, char c) { Ensure.That(nameof(s)).IsNotNull(s); return(s[0] == c); }
// 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); }
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); }
public string NormalizePath(string path) { Ensure.That(nameof(path)).IsNotNull(path); return(Path.Combine(root, path)); }
protected VariableUnit(string defaultName) { Ensure.That(nameof(defaultName)).IsNotNull(defaultName); this.defaultName = defaultName; }
public string DebugPath(string path) { Ensure.That(nameof(path)).IsNotNull(path); return(NormalizePath(path)); }
protected IList <T> GetListForItem(T item) { Ensure.That(nameof(item)).IsNotNull(item); return(GetListForType(item.GetType())); }
private EditorTexture(Texture2D texture) : this() { Ensure.That(nameof(texture)).IsNotNull(texture); personal.Add(texture.width, texture); }
public ObjectMetadata StaticObject(object @object) { Ensure.That(nameof(@object)).IsNotNull(@object); return(StaticObject(@object, @object.GetType())); }
public static int GetFileID(Type type) { Ensure.That(nameof(type)).IsNotNull(type); return(GetFileID(type.Namespace, type.Name)); }
public CastMetadata Cast(Type type) { Ensure.That(nameof(type)).IsNotNull(type); return(Dig(type, digCast.Get(type), true)); }
public static string SerializeType(Type type) { Ensure.That(nameof(type)).IsNotNull(type); return(type?.FullName); }
public EnumOptionTree(Type enumType) : base(new GUIContent(enumType.HumanName())) { Ensure.That(nameof(enumType)).IsNotNull(enumType); enums = Enum.GetValues(enumType).Cast <Enum>().ToList(); }
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(); }
public UnitPortDescriptor(IUnitPort target) { Ensure.That(nameof(target)).IsNotNull(target); this.target = target; }
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)); }
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)); }
public static ConversionType GetRequiredConversion(object value, Type type) { Ensure.That(nameof(type)).IsNotNull(type); return(GetRequiredConversion(value?.GetType(), type)); }
public static IEnumerable <T> Catch <T>(this IEnumerable <T> source, ICollection <Exception> exceptions) { Ensure.That(nameof(exceptions)).IsNotNull(exceptions); return(source.Catch(exceptions.Add)); }