private object FileToJsonModel()

in src/Microsoft.IIS.Administration.Files/Files/FilesHelper.cs [195:304]


        private object FileToJsonModel(IFileInfo info, Fields fields = null, bool full = true, IFileInfo parent = null)
        {
            if (fields == null) {
                fields = Fields.All;
            }

            dynamic obj = new ExpandoObject();
            var fileId = FileId.FromPhysicalPath(info.Path);
            bool? exists = null;
            
            //
            // name
            if (fields.Exists("name")) {
                obj.name = info.Name;
            }

            //
            // id
            if (fields.Exists("id")) {
                obj.id = fileId.Uuid;
            }

            //
            // alias
            if (fields.Exists("alias")) {
                foreach (var location in _fileProvider.Options.Locations) {
                    if (location.Path.TrimEnd(PathUtil.SEPARATORS).Equals(info.Path.TrimEnd(PathUtil.SEPARATORS), StringComparison.OrdinalIgnoreCase)) {
                        obj.alias = location.Alias;
                        break;
                    }
                }
            }

            //
            // type
            if (fields.Exists("type")) {
                obj.type = Enum.GetName(typeof(FileType), FileType.File).ToLower();
            }

            //
            // physical_path
            if (fields.Exists("physical_path")) {
                obj.physical_path = info.Path;
            }

            //
            // exists
            if (fields.Exists("exists")) {
                exists = exists ?? info.Exists;
                obj.exists = exists.Value;
            }

            //
            // size
            if (fields.Exists("size")) {
                exists = exists ?? info.Exists;
                obj.size = exists.Value ? info.Size : 0;
            }

            //
            // created
            if (fields.Exists("created")) {
                exists = exists ?? info.Exists;
                obj.created = exists.Value ? (object)info.Created.ToUniversalTime() : null;
            }

            //
            // last_modified
            if (fields.Exists("last_modified")) {
                exists = exists ?? info.Exists;
                obj.last_modified = exists.Value ? (object)info.LastModified.ToUniversalTime() : null;
            }

            //
            // last_access
            if (fields.Exists("last_access")) {
                exists = exists ?? info.Exists;
                obj.last_access = exists.Value ? (object)info.LastAccessed.ToUniversalTime() : null;
            }

            //
            // mime_type
            if (fields.Exists("mime_type")) {
                string type = null;
                HttpFileHandler.MimeMaps.TryGetContentType(info.Path, out type);
                obj.mime_type = type;
            }

            //
            // e_tag
            if (fields.Exists("e_tag")) {
                exists = exists ?? info.Exists;
                obj.e_tag = exists.Value ? ETag.Create(info).Value : null;
            }

            //
            // parent
            if (fields.Exists("parent")) {
                obj.parent = parent != null ? DirectoryToJsonModelRef(parent, fields.Filter("parent")) : GetParentJsonModelRef(info.Path, fields.Filter("parent"));
            }

            //
            // claims
            if (fields.Exists("claims")) {
                obj.claims = info.Claims;
            }


            return Core.Environment.Hal.Apply(Defines.FilesResource.Guid, obj, full);
        }