public override string EvaluateFunction(string prefix, string function, string[] args)
        {
            switch (prefix)
            {
            case "fileVersion":
                // Make sure there actually is a file name
                if (args.Length == 0 || args[0].Length == 0)
                {
                    throw new ArgumentException("File name not specified");
                }

                // Make sure the file exists
                if (!File.Exists(args[0]))
                {
                    throw new ArgumentException(string.Format("File name {0} does not exist", args[0]));
                }

                // Get the file version information for the given file
                FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(args[0]);

                // Get the property that matches the name of the function
                PropertyInfo propertyInfo = fileVersionInfo.GetType().GetProperty(function);

                // Make sure the property exists
                if (propertyInfo == null)
                {
                    throw new ArgumentException(string.Format("Unable to find property {0} in FileVersionInfo", function));
                }

                // Return the value of the property as a string
                return(propertyInfo.GetValue(fileVersionInfo, null).ToString());
            }

            return(null);
        }
コード例 #2
0
ファイル: AssemblyInfo.cs プロジェクト: pimboden/csbooster
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Settings.ContainsKey("File"))
     {
         FileVersionInfo fileInfo = FileVersionInfo.GetVersionInfo(Settings["File"].ToString());
         this.FileName        = fileInfo.FileName;
         this.FileDescription = fileInfo.FileDescription;
         this.Type            = fileInfo.GetType().ToString();
         this.FileVersion     = fileInfo.FileVersion;
         this.ProductVersion  = fileInfo.ProductVersion;
         this.ProductName     = fileInfo.ProductName;
         this.Copyright       = fileInfo.LegalCopyright;
         FileInfo info = new FileInfo(Settings["File"].ToString());
         this.DateModified = info.LastWriteTime;
         this.CreationTime = info.CreationTime;
         this.Size         = info.Length;
         this.FileNameOnly = info.Name;
     }
 }