Ejemplo n.º 1
0
        public override string GetMimeType(string path)
        {
            string extension             = NSUrl.FromString(path).PathExtension;
            string uniformTypeIdentifier = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, extension, null);

            return(UTType.GetPreferredTag(uniformTypeIdentifier, UTType.TagClassMIMEType));
        }
Ejemplo n.º 2
0
 public void Equals()
 {
     Assert.True(UTType.Equals(null, null), "null-null");
     Assert.False(UTType.Equals(null, UTType.PDF), "null-PDF");
     Assert.False(UTType.Equals(UTType.PDF, null), "PDF-null");
     Assert.True(UTType.Equals(UTType.PDF, UTType.PDF), "PDF-PDF");
 }
Ejemplo n.º 3
0
        public void GetDeclaration()
        {
            // This test may fail in the simulator, if the architecture of the simulator isn't the native one (say running x86_64 on an M1 machine),
            // so just skip this test for the simulator.
            TestRuntime.AssertIfSimulatorThenARM64();

            Assert.NotNull(UTType.GetDeclaration(UTType.PDF));
        }
Ejemplo n.º 4
0
 public override string ToString()
 {
     if (Id == "com.daoyehuo.photolibraryresources")
     {
         return(UIKitExtensions.Localize("Backup.FileType"));
     }
     return(UTType.GetDescription(Id));
 }
Ejemplo n.º 5
0
        public void GetPreferredTag()
        {
            // This test may fail in the simulator, if the architecture of the simulator isn't the native one (say running x86_64 on an M1 machine),
            // so just skip this test for the simulator.
            TestRuntime.AssertIfSimulatorThenARM64();

            Assert.NotNull(UTType.GetPreferredTag(UTType.PDF, UTType.TagClassFilenameExtension), "GetPreferredTag");
        }
Ejemplo n.º 6
0
        internal static string PlatformGetContentType(string extension)
        {
            // ios does not like the extensions
            extension = extension?.TrimStart('.');

            var id        = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, extension, null);
            var mimeTypes = UTType.CopyAllTags(id, UTType.TagClassMIMEType);

            return(mimeTypes.Length > 0 ? mimeTypes[0] : null);
        }
Ejemplo n.º 7
0
        public static Tuple <string, string, string> GetAvUtiConformance(this NSUrl filePath)
        {
            NSError error;

            NSObject typeValue;

            if (filePath.TryGetResource(NSUrl.TypeIdentifierKey, out typeValue, out error))
            {
                var typeValueString = typeValue as NSString;

                if (typeValueString != null)
                {
                    if (UTType.ConformsTo(typeValueString, UTType.Movie))
                    {
                        if (UTType.ConformsTo(typeValueString, UTType.MPEG4))
                        {
                            return(new Tuple <string, string, string> (UTType.Movie, UTType.MPEG4, filePath.LastPathComponent));
                        }

                        if (UTType.ConformsTo(typeValueString, UTType.QuickTimeMovie))
                        {
                            return(new Tuple <string, string, string> (UTType.Movie, UTType.QuickTimeMovie, filePath.LastPathComponent));
                        }

                        // alert that file is recognized as a movie, but we don't handle it (yet) log it
                        return(new Tuple <string, string, string> (UTType.Movie, UTType.Movie, filePath.LastPathComponent));
                    }

                    if (UTType.ConformsTo(typeValueString, UTType.Audio))
                    {
                        if (UTType.ConformsTo(typeValueString, UTType.MP3))
                        {
                            return(new Tuple <string, string, string> (UTType.Audio, UTType.MP3, filePath.LastPathComponent));
                        }

                        if (UTType.ConformsTo(typeValueString, UTType.WaveformAudio))
                        {
                            return(new Tuple <string, string, string> (UTType.Audio, UTType.WaveformAudio, filePath.LastPathComponent));
                        }

                        // alert that file is recognized as a audio, but we don't handle it (yet) log it
                        return(new Tuple <string, string, string> (UTType.Audio, UTType.Audio, filePath.LastPathComponent));
                    }
                }
            }
            else if (error != null)
            {
                //Log.Debug ($"Error trying to get resource identifier\n\t{error.Code}\n\t{error.Domain}\n\t{error.Description}");
                return(new Tuple <string, string, string> (UTType.PlainText, $"Error trying to get resource identifier\n\t{error.Code}\n\t{error.Domain}\n\t{error.Description}", filePath.LastPathComponent));
            }

            return(new Tuple <string, string, string> (UTType.PlainText, $"Unsupported file type or path", filePath.LastPathComponent));
        }
Ejemplo n.º 8
0
        private void OnEnable()
        {
            Predicate <Type> test = UTType.Test_Or(
                UTType.ETypeTest.ABSTRACT,
                UTType.ETypeTest.ANONYMOUS,
                UTType.ETypeTest.GENERIC,
                UTType.ETypeTest.SEALED
                );


            _list = new EETypeList(new Assembly[] { typeof(int).Assembly, typeof(UTArray).Assembly, typeof(AppManager).Assembly }, 2, test);
        }
Ejemplo n.º 9
0
 public void CreatePreferredIdentifier()
 {
     string[] extensions = new [] { ".html", ".css", ".jpg", ".js", ".otf" };
     // random failure reported in #36708 (on some iPad2 only)
     for (int i = 0; i < 100; i++)
     {
         foreach (var ext in extensions)
         {
             var result = UTType.CreatePreferredIdentifier(UTType.TagClassMIMEType, ext, null);
             Assert.NotNull(result, ext + i.ToString());
         }
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Exports the audio of a media item to storage.
        /// </summary>
        /// <returns><c>true</c> if audio started exporting, <c>false</c> if it is exporting another audio or the media item has DRM.</returns>
        /// <param name="mediaItem">Media item.</param>
        /// <param name="outputFolder">Absolute output folder or specify null to use Documents folder.</param>
        /// <param name="outputFile">Output file name or specify null to use <c>[artist] - [title].[extension]</c>.</param>
        /// <param name="overwrite">Whether to overwrite the output file.</param>
        public static bool ExportAudio(MPMediaItem mediaItem, string outputFolder = null, string outputFile = null, bool overwrite = false)
        {
            if (_exporter != null)
            {
                return(false);
            }
            if (mediaItem == null)
            {
                return(false);
            }

            if (outputFolder == null)
            {
                outputFolder = Application.persistentDataPath;
            }

            NSURL assetURL = mediaItem.Value(MPMediaItem.PropertyAssetURL) as NSURL;

            if (assetURL == null)
            {
                return(false);
            }

            if (outputFile == null)
            {
                string artist    = mediaItem.Value(MPMediaItem.PropertyArtist) as string;
                string title     = mediaItem.Value(MPMediaItem.PropertyTitle) as string;
                string extension = Path.GetExtension(assetURL.AbsoluteString().Split('?')[0]);
                outputFile = artist + " - " + title + extension;
            }

            _outputPath = outputFolder + "/" + outputFile;
            if (!overwrite && File.Exists(_outputPath))
            {
                return(false);
            }

            _avAsset  = AVURLAsset.Asset(assetURL);
            _exporter = new AVAssetExportSession(_avAsset, AVAssetExportSession.AVAssetExportPresetPassthrough);
            _exporter.outputFileType = "com.apple.quicktime-movie";
            _exporter.shouldOptimizeForNetworkUse = true;

            string tmpExt = UTType.CopyPreferredTag(_exporter.outputFileType, UTType.kUTTagClassFilenameExtension);

            _tmpPath            = Application.persistentDataPath + "/" + UUID.Generate() + "." + tmpExt;
            _exporter.outputURL = new NSURL(_tmpPath, false);

            _exporter.ExportAsynchronously(_OnExportDone);

            return(true);
        }
Ejemplo n.º 11
0
        public static NSString ToNsUti(this string mimeType)
        {
            var uuType = UTType.CreatePreferredIdentifier(UTType.TagClassMIMEType, mimeType.ToLower(), null);

            if (mimeType == "text/url")
            {
                if (mimeType.StartsWith("file://", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(UTType.FileURL);
                }
                return(UTType.URL);
            }
            //var uuType = UTType.CreatePreferredIdentifier(UTType.TagClassMIMEType, mimeType.ToLower(), null);
            return(new NSString(uuType));
        }
Ejemplo n.º 12
0
        public void CreatePreferredIdentifier()
        {
            // This test may fail in the simulator, if the architecture of the simulator isn't the native one (say running x86_64 on an M1 machine),
            // so just skip this test for the simulator.
            TestRuntime.AssertIfSimulatorThenARM64();

            string[] extensions = new [] { ".html", ".css", ".jpg", ".js", ".otf" };
            // random failure reported in #36708 (on some iPad2 only)
            for (int i = 0; i < 100; i++)
            {
                foreach (var ext in extensions)
                {
                    var result = UTType.CreatePreferredIdentifier(UTType.TagClassMIMEType, ext, null);
                    Assert.NotNull(result, ext + i.ToString());
                }
            }
        }
Ejemplo n.º 13
0
        private void OnEnable()
        {
            Predicate <Type> test = UTType.Test_Or(
                UTType.ETypeTest.ABSTRACT,
                UTType.ETypeTest.ANONYMOUS,
                UTType.ETypeTest.GENERIC,
                UTType.ETypeTest.SEALED
                );

            _button = new EESaveFileButton(
                new SLabel()
            {
                Id = "save", ReadableName = "Save The File", ToolTip = "This saves the file"
            }
                );

            _button.OnPathChosen += s => _pathChosen = s;
        }
Ejemplo n.º 14
0
        private void HandleImage(IEnumerable <PHObject> images)
        {
            foreach (PHAsset image in images)
            {
                if (image.MediaType == PHAssetMediaType.Image)
                {
                    PHImageRequestOptions options = new PHImageRequestOptions()
                    {
                        NetworkAccessAllowed = false,
                        ResizeMode           = PHImageRequestOptionsResizeMode.Exact,
                        Version = PHImageRequestOptionsVersion.Original
                    };

                    PHImageManager.DefaultManager.RequestImageData(image, options, async(d, t, o, i) =>
                    {
                        string path     = ((NSUrl)i["PHImageFileURLKey"])?.Path;
                        string mimeType = UTType.GetPreferredTag(t, UTType.TagClassMIMEType);

                        await _probe.CreateAndStoreDatumAsync(path, mimeType, (DateTime)image.CreationDate);
                    });
                }
                else if (image.MediaType == PHAssetMediaType.Video)
                {
                    PHVideoRequestOptions options = new PHVideoRequestOptions()
                    {
                        NetworkAccessAllowed = false,
                        Version = PHVideoRequestOptionsVersion.Original
                    };

                    PHImageManager.DefaultManager.RequestAvAsset(image, options, async(a, _, i) =>
                    {
                        if (a is AVUrlAsset urlAsset)
                        {
                            string path                  = urlAsset.Url.Path;
                            string extension             = urlAsset.Url.PathExtension;
                            string uniformTypeIdentifier = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, extension, null);
                            string mimeType              = UTType.GetPreferredTag(uniformTypeIdentifier, UTType.TagClassMIMEType);

                            await _probe.CreateAndStoreDatumAsync(path, mimeType, (DateTime)image.CreationDate);
                        }
                    });
                }
            }
        }
Ejemplo n.º 15
0
        public string GetMimeType(string fileUriOrExt)
        {
            if (String.IsNullOrWhiteSpace(fileUriOrExt))
            {
                return(null);
            }

            string extension = Path.GetExtension(fileUriOrExt);

            if (extension == null)
            {
                return(null);
            }

            var uti      = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, extension.Substring(1), null);
            var mimeType = UTType.GetPreferredTag(uti, UTType.TagClassMIMEType);

            return(mimeType);
        }
Ejemplo n.º 16
0
        public static string ToMime(this string uti)
        {
            var result = UTType.GetPreferredTag(uti, UTType.TagClassMIMEType);

            if (result == null)
            {
                if (uti == UTType.URL || uti == UTType.FileURL)
                {
                    return("text/url");
                }
                if (uti == UTType.UTF8PlainText || uti == UTType.Text || uti == UTType.PlainText)
                {
                    return("text/plain");
                }
                System.Console.WriteLine("Unknown UTI: " + uti);
                return(null);
            }
            return(result.ToLower());
        }
Ejemplo n.º 17
0
        public Tuple <byte[], string, string> ReadFile(string file)
        {
            Tuple <byte[], string, string> result = null;
            var asset = PHAsset.FetchAssets(new[] { new NSUrl(file) }, null).LastObject as PHAsset;

            if (asset != null)
            {
                var options = new PHImageRequestOptions {
                    Synchronous = true
                };
                PHImageManager.DefaultManager.RequestImageData(asset, options, (data, dataUti, orientation, info) => {
                    var extension = new NSUrl(dataUti).PathExtension;
                    var uti       = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, extension, null);
                    var mime      = UTType.GetPreferredTag(uti, UTType.TagClassMIMEType);
                    var dataBytes = new byte[data.Length];
                    Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));
                    result = new Tuple <byte[], string, string>(dataBytes, dataUti, mime);
                });
            }
            return(result);
        }
Ejemplo n.º 18
0
        public async Task <ToastImageSource> FromUriAsync(Uri uri, CancellationToken cancellationToken = default)
        {
            string contentType = "";
            var    fullFn      = await imageCacher.CacheAsync(uriToFileNameStrategy.Convert(uri), cancellationToken, async (stream, ct) =>
            {
                var hc = httpClientFactory.CreateClient(nameof(IToastImageSourceFactory));
                using (var response = await hc.GetAsync(uri))
                {
                    contentType = response.Content.Headers.ContentType.MediaType;
                    using (var src = await response.Content.ReadAsStreamAsync())
                        await src.CopyToAsync(stream, 1024 * 80, cancellationToken);
                }
            });

            if (string.IsNullOrEmpty(contentType))
            {
                using (var fs = File.OpenRead(fullFn))
                    contentType = await mimeDetector.DetectAsync(fs);
            }
            return(new SealedToastImageSource(CreateAttachment(uri.ToString(), NSUrl.FromFilename(fullFn),
                                                               UTType.CreatePreferredIdentifier(UTType.TagClassMIMEType, contentType, null))));
        }
Ejemplo n.º 19
0
        private void Initialize()
        {
            _selectedTypeList = new EETypeList(
                AppDomain.CurrentDomain.GetAssemblies(),
                1,
                UTType.Test_Or(
                    UTType.ETypeTest.CLASS,
                    UTType.ETypeTest.ENUM,
                    UTType.ETypeTest.INTERFACE,
                    UTType.ETypeTest.TOBIAS_VALUE_TYPE,
                    UTType.ETypeTest.STRUCT
                    )
                );

            _namespace = new EECustomString(
                new SLabel()
            {
                ReadableName = "Namespace", ToolTip = "Namespace to use"
            },
                () => _selectedTypeList.SelectedType?.Namespace
                );

            _menuPath = new EECustomString(
                new SLabel()
            {
                ReadableName = "Menu Name",
                ToolTip      = "Prefix in front of menu paths (Component and Asset). If this = MENU, then asset path is MENU/Events/EventName"
            },
                () => string.IsNullOrEmpty(_namespace?.String) ?
                "Unknown"
                        : _namespace.String.Split('.')[0] + (_namespace.String.Split('.').Length < 2 ? "" : $"/{_namespace.String.Split('.')[1]}")
                );

            if (_lastSavePath == null)
            {
                _lastSavePath = new PathString(Application.dataPath);
            }
        }
Ejemplo n.º 20
0
        private void LoadAssemblyTypes(Assembly ass, int namespaceLevels, Predicate <Type> filter)
        {
            Type[] types = UTAssembly.GetTypesFromAssemblies(ass);
            if (filter != null)
            {
                types = types.Where(e => filter(e)).ToArray();
            }

            string[] nsps = UTType.NamespacesFromTypes(types, namespaceLevels);

            List <NamespaceMap> maps = new List <NamespaceMap>();

            foreach (string s in nsps)
            {
                NamespaceMap map = new NamespaceMap(
                    s,
                    types.Where(t => t.Namespace == null ? s == "_NoNamespace" : t.Namespace.SeparatorLevelPrune('.', namespaceLevels) == s).ToArray()
                    );

                maps.Add(map);
            }

            _assemblyMap[ass] = new AssemblyContents(maps.ToArray());
        }
Ejemplo n.º 21
0
 public void GetPreferredTag()
 {
     Assert.NotNull(UTType.GetPreferredTag(UTType.PDF, UTType.TagClassFilenameExtension), "GetPreferredTag");
 }
Ejemplo n.º 22
0
        private bool CanConformsToImageUTI(NSString url)
        {
            var uti = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, url.PathExtension, null);

            return(UTType.ConformsTo(uti, UTType.Image));
        }
        /// <summary>
        /// File picking implementation
        /// </summary>
        /// <param name="allowedTypes">list of allowed file extention types; may be null</param>
        /// <returns>picked file data, or null when picking was cancelled</returns>
        private Task <FileData> PickMediaAsync(string[] allowedTypes)
        {
            var id = this.GetRequestId();

            var ntcs = new TaskCompletionSource <FileData>(id);

            if (Interlocked.CompareExchange(ref this.completionSource, ntcs, null) != null)
            {
                throw new InvalidOperationException("Only one operation can be active at a time");
            }

            var allowedUtis = new string[]
            {
                UTType.Content,
                UTType.Item,
                "public.data"
            };

            if (allowedTypes != null)
            {
                List <string> typeslist = new List <string>();
                foreach (var extension in allowedTypes)
                {
                    if (!string.IsNullOrEmpty(extension))
                    {
                        var fixed_Extension = extension?.TrimStart('.');


                        // get the UTI for an extension
                        //var uti = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, fixed_Extension, null);
                        // "public.jpeg"

                        // get the UTI for a MIME type
                        //var uti2 = UTType.CreatePreferredIdentifier(UTType.TagClassMIMEType, fixed_Extension, null);
                        // "com.adobe.pdf"

                        // get the MIME type for a UTI
                        //var mime = UTType.GetPreferredTag(uti, UTType.TagClassFilenameExtension);

                        var UTid = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, fixed_Extension, null);
                        typeslist.Add(UTid);
                    }
                }
                allowedUtis = typeslist.ToArray();
            }

            // NOTE: Importing (UIDocumentPickerMode.Import) makes a local copy of the document,
            // while opening (UIDocumentPickerMode.Open) opens the document directly. We do the
            // first, so the user has to read the file immediately.
            var documentPicker = new UIDocumentPickerViewController(allowedUtis, UIDocumentPickerMode.Import);

            documentPicker.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
            documentPicker.DidPickDocument       += this.DocumentPicker_DidPickDocument;
            documentPicker.WasCancelled          += this.DocumentPicker_WasCancelled;
            documentPicker.DidPickDocumentAtUrls += this.DocumentPicker_DidPickDocumentAtUrls;

            UIViewController viewController = GetActiveViewController();

            viewController.PresentViewController(documentPicker, true, null);

            this.Handler = (sender, args) =>
            {
                var tcs = Interlocked.Exchange(ref this.completionSource, null);

                tcs?.SetResult(new FileData(
                                   args.FilePath,
                                   args.FileName,
                                   () => GetStreamFromPath(args.FilePath).Result));
            };

            return(this.completionSource.Task);
        }
        /// <summary>
        /// Uses reflection to generically populate a ScritableObject that inherits AGameDataSo. It is expected that
        /// the keys in Properties and Collections correspond to fields on the given ScritableObject Type. This function
        /// looks up the field and, if it exists, analyzes the type. If the type is a string the value is added directly. If
        /// it is a primative, a parse is performed. If the type is an enum, then a parse is performed.
        /// If the field is AGameDataSo reference, then given string is interpreted as a key
        /// and the references array is searched for the reference. In any case, failure or error leads to skipping
        /// populating the field.
        /// </summary>
        /// <param name="populate"></param>
        /// <param name="references"></param>
        /// <param name="gamedataAssembly"></param>
        public OperationLog[] GenericPopulate(GameData data, ref AGameDataSo populate)
        {
            List <OperationLog> logs = new List <OperationLog>();

            AGameDataSo[] references = UTScriptableObject.GetAllInstances <AGameDataSo>();

            // Get the type and it's fields
            Type t = populate.GetType();

            FieldInfo[] fields = t.GetFields();

            // populate the key
            if (string.IsNullOrEmpty(data.Key))
            {
                logs.AddRange(Warning("Key field of GameData is not populated"));
            }
            populate.Key = data.Key;

            if (data.Properties != null)
            {
                // populate the properties
                foreach (KeyValuePair <string, string> kv in data.Properties)
                {
                    // get the field with the same key
                    FieldInfo f = fields.FirstOrDefault(e => e.Name == kv.Key);
                    if (f == default)
                    {
                        logs.AddRange(Warning($"key:{data.Key} So does not contain field {kv.Key}"));
                        continue;
                    }

                    // if the field exists, populate it based on it's type
                    if (f.FieldType == typeof(string))
                    {
                        f.SetValue(populate, kv.Value);
                    }
                    if (f.FieldType.IsPrimitive)
                    {
                        logs.AddRange(HandlePrimative(f, populate, kv.Value));                         // do convert
                    }
                    else if (UTType.GetTest(UTType.ETypeTest.ENUM)(f.FieldType))
                    {
                        logs.AddRange(HandleEnum(f, populate, kv.Value));                                                          // do enum
                    }
                    else if (f.FieldType.IsSubclassOf(typeof(AGameDataSo)))
                    {
                        logs.AddRange(HandleSo(f, populate, kv.Value, references));                                                    // do a refernece handle
                    }
                }
            }

            if (data.Collections != null)
            {
                // populate the collections
                foreach (KeyValuePair <string, string[]> kv in data.Collections)
                {
                    // get the field with the same key
                    FieldInfo f = fields.FirstOrDefault(e => e.Name == kv.Key);
                    if (f == default)
                    {
                        continue;
                    }

                    Type  elType = f.FieldType.GetElementType();
                    Array a      = Array.CreateInstance(elType, kv.Value.Length);

                    // if the field exists, populate it based on it's type
                    if (elType == typeof(string))
                    {
                        f.SetValue(populate, kv.Value);
                    }
                    if (elType.IsPrimitive)
                    {
                        logs.AddRange(HandlePrimativeArray(f, populate, kv.Value, a));                    // do convert
                    }
                    else if (UTType.GetTest(UTType.ETypeTest.ENUM)(elType))
                    {
                        logs.AddRange(HandleEnumArray(f, populate, kv.Value, a));                                                     // do enum
                    }
                    else if (elType.IsSubclassOf(typeof(AGameDataSo)))
                    {
                        logs.AddRange(HandleSoArray(f, populate, kv.Value, references, a));                                               // do a refernece handle
                    }
                }
            }

            return(logs.ToArray());

            // Singles
            OperationLog[] HandleSingle(FieldInfo fi, AGameDataSo obj, string value, Func <Type, string, object> converter)
            {
                try
                {
                    fi.SetValue(obj, converter(fi.FieldType, value));
                }
                catch (Exception)
                {
                    return(Error($"Failed to set {fi.Name} in key:{obj.Key} of value:{value}"));
                }

                return(new OperationLog[0]);
            }

            OperationLog[] HandlePrimative(FieldInfo fi, AGameDataSo obj, string value)
            => HandleSingle(fi, obj, value, (ty, v) => Convert.ChangeType(v, ty));

            OperationLog[] HandleEnum(FieldInfo fi, AGameDataSo obj, string value)
            => HandleSingle(fi, obj, value, (ty, v) => Enum.Parse(ty, v, true));


            // Array
            OperationLog[] HandleArray(FieldInfo fi, AGameDataSo obj, string[] value, Array pop, Func <Type, string, object> converter)
            {
                List <OperationLog> innerLogs = new List <OperationLog>();

                for (int i = 0; i < pop.Length; i++)
                {
                    try
                    {
                        pop.SetValue(converter(fi.FieldType, value[i]), i);
                    }
                    catch (Exception) {
                        innerLogs.AddRange(Error($"Failed to set {fi.Name} in key:{obj.Key} of value:{value}"));
                    }
                }

                fi.SetValue(obj, pop);
                return(logs.ToArray());
            }

            OperationLog[] HandlePrimativeArray(FieldInfo fi, AGameDataSo obj, string[] value, Array pop)
            => HandleArray(fi, obj, value, pop, (ty, v) => Convert.ChangeType(v, ty));

            OperationLog[] HandleEnumArray(FieldInfo fi, AGameDataSo obj, string[] value, Array pop)
            => HandleArray(fi, obj, value, pop, (ty, v) => Enum.Parse(ty, v, true));

            // Set an so generically
            OperationLog[] HandleSo(FieldInfo fi, AGameDataSo obj, string value, AGameDataSo[] refs)
            {
                AGameDataSo soRef = refs.FirstOrDefault(e => e.Key == value);

                if (soRef != default)
                {
                    fi.SetValue(obj, soRef);
                    return(Error($"Failed to set {fi.Name} in key:{obj.Key} of value:{value}"));
                }

                return(new OperationLog[0]);
            }

            // set an so array
            OperationLog[] HandleSoArray(FieldInfo fi, AGameDataSo obj, string[] value, AGameDataSo[] refs, Array pop)
            {
                List <OperationLog> innerLogs = new List <OperationLog>();

                for (int i = 0; i < pop.Length; i++)
                {
                    try
                    {
                        pop.SetValue(refs.FirstOrDefault(e => e.Key == value[i]), i);
                    }
                    catch (Exception)
                    {
                        innerLogs.AddRange(Error($"Failed to set {fi.Name} in key:{obj.Key} of value:{value}"));
                    }
                }

                fi.SetValue(obj, pop);
                return(logs.ToArray());
            }
        }
Ejemplo n.º 25
0
 public void GetDeclaration()
 {
     Assert.NotNull(UTType.GetDeclaration(UTType.PDF));
 }
Ejemplo n.º 26
0
 protected string CreateDynamicTypeFor(string type)
 {
     return(UTType.CreatePreferredIdentifier(UTType.kUTTagClassNSPboardType, Pasteboard.NSPasteboardTypeWebArchive, UTType.kUTTypeData));
 }
Ejemplo n.º 27
0
 public void GetDeclaringBundleURL()
 {
     Assert.NotNull(UTType.GetDeclaringBundleURL(UTType.PDF));
 }
Ejemplo n.º 28
0
 protected string GetExtension(string identifier)
 => UTType.CopyAllTags(identifier, UTType.TagClassFilenameExtension)?.FirstOrDefault();
Ejemplo n.º 29
0
 protected string GetMIMEType(string identifier)
 => UTType.CopyAllTags(identifier, UTType.TagClassMIMEType)?.FirstOrDefault();
Ejemplo n.º 30
0
 public string GetFileType(string extension)
 => UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, extension, null);