Nazwa resource

0

Zakladajac ze w resources mam 1 element, jak pobrac jego nazwe automatycznie?

File.WriteAllBytes(".\\plik.exe", Properties.Resources.plik);
            System.Diagnostics.Process.Start(".\\plik.exe");
0

Że takie coś?

var firstDictionaryEntry = Resources.ResourceManager
   .GetResourceSet(CultureInfo.CurrentCulture, true, true)
   .Cast<DictionaryEntry>()
   .First();
Debug.WriteLine("Key(Name): {0}, Value: {1}", firstDictionaryEntry.Key, firstDictionaryEntry.Value);
0

Mam z tym 2 bledy:

The name 'Resources' does not exist in the current context

Helper.Properities.Resources' does not contain a definition for 'firstDictionaryEntry'

?

0

Okej w twoim przypadku: Resources.ResourceManager zamień na Properties.Resources.ResourceManager.
Odnośnie drugiego pokaż kod gdzie to się wywala.

0

Moj program wyglada tak:

 var firstDictionaryEntry = Properties.Resources.ResourceManager
   .GetResourceSet(CultureInfo.CurrentCulture, true, true)
   .Cast<DictionaryEntry>()
   .First();
            Debug.WriteLine("Key(Name): {0}, Value: {1}", firstDictionaryEntry.Key, firstDictionaryEntry.Value);
            File.WriteAllBytes(".\\program.exe", Properties.Resources.firstDictionaryEntry);
            System.Diagnostics.Process.Start(".\\program.exe"); 

a bledy wywala takie:
'System.Resources.ResourceSet' does not contain a definition for 'Cast' and no extension method 'Cast' accepting a first argument of type 'System.Resources.ResourceSet' could be found (are you missing a using directive or an assembly reference?) - dotyczy

.Cast<DictionaryEntry>()

i drugi:
'Helper.Properties.Resources' does not contain a definition for 'firstDictionaryEntry' dotyczy Properties.Resources.firstDictionaryEntry

0
  1. Dodaj: using System.Linq;
  2. Properties.Resources.firstDictionaryEntry powinno być firstDictionaryEntry.Key.
  3. Teraz wywali Ci się na:
File.WriteAllBytes(".\\program.exe", firstDictionaryEntry.Key);

Więc powinieneś wpisać tam:

File.WriteAllBytes(".\\program.exe", Encoding.Unicode.GetBytes((string)firstDictionaryEntry.Key));

Gdzie klasa Encoding znajduje się w using System.Text;
4. Ale to wciąż nie ma sensu bo jakoś nie chce mi się wierzyć że to teraz zadziała:

System.Diagnostics.Process.Start(".\\program.exe"); 
0

Problem jest taki ze Linq odpada bo ma to dzialac pod net fram. 2
Czy da sie to zrobic?

0

Da się:

var dictionaryEnumerator = Properties.Resources.ResourceManager
                           .GetResourceSet(CultureInfo.CurrentCulture, true, true).GetEnumerator();

DictionaryEntry? firstDictionaryEntry = null;
if (dictionaryEnumerator.MoveNext())
{
   firstDictionaryEntry = (DictionaryEntry) dictionaryEnumerator.Current;
            
}
if (firstDictionaryEntry.HasValue)
{
   Debug.WriteLine(string.Format("Key(Name): {0}, Value: {1}", firstDictionaryEntry.Value.Key,
                                 firstDictionaryEntry.Value));
   File.WriteAllBytes(".\\program.exe", Encoding.Unicode.GetBytes((string) firstDictionaryEntry.Value.Key));
   Process.Start(".\\program.exe");
}
0

Wywalalo blad dot. Resources.ResourceManager wiec dodalem Properities, zniknal ale podczas kompilacji wyskakuje okienko z "16 bit MS-DOS subsystem" "C:\DoCUME~1... The NTVDM CPU has encountered an illegal instruction. CS:053e IP:0100 ..."

1 użytkowników online, w tym zalogowanych: 0, gości: 1