Skip to content

Commit c6a1b1c

Browse files
committed
Add explicit GetField and SetField methods to make up for recent changes to behavior to GetProperty/SetProperty related operations that no longer retrieve fields. You can now use the explicit methods.
- Updated binary signing process using Azure Trusted Signing
1 parent b155769 commit c6a1b1c

File tree

15 files changed

+1506
-1290
lines changed

15 files changed

+1506
-1290
lines changed

ClrHost/ClrHost.rc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ END
5252
//
5353

5454
VS_VERSION_INFO VERSIONINFO
55-
FILEVERSION 8,1,2,0
55+
FILEVERSION 8,4,5,0
5656
PRODUCTVERSION 8,0,0,0
5757
FILEFLAGSMASK 0x17L
5858
#ifdef _DEBUG
@@ -70,9 +70,9 @@ BEGIN
7070
BEGIN
7171
VALUE "CompanyName", "West Wind Technologies"
7272
VALUE "FileDescription", "West Wind .NET Connector (Win32)"
73-
VALUE "FileVersion", "8.1.2.0"
73+
VALUE "FileVersion", "8.4.5.0"
7474
VALUE "InternalName", "wwDotNetBridge"
75-
VALUE "LegalCopyright", "© West Wind Technologies, 2010-2024"
75+
VALUE "LegalCopyright", "© West Wind Technologies, 2010-2025"
7676
VALUE "OriginalFilename", "ClrHost.dll"
7777
VALUE "ProductName", "wwDotnetBridge"
7878
VALUE "ProductVersion", "8.0.0.0"

Distribution/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sign*.*

Distribution/ClrHost.dll

8.99 KB
Binary file not shown.

Distribution/SignAndPack.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
~\Dropbox\utl\signtool.exe sign /v /n "West Wind Technologies" /sm /s MY /tr "http://timestamp.digicert.com" /td SHA256 /fd SHA256 ".\wwdotnetbridge.dll"
2-
~\Dropbox\utl\signtool.exe sign /v /n "West Wind Technologies" /sm /s MY /tr "http://timestamp.digicert.com" /td SHA256 /fd SHA256 ".\clrhost.dll"
3-
4-
~\Dropbox\utl\7z.exe a -tzip -r .\wwDotnetBridge-Oss.zip .\wwdotnetbridge.dll .\clrhost.dll .\wwDotnetBridge.prg
1+
.\signFile.ps1 -file "clrhost.dll" -file2 "wwDotnetBridge.dll"
2+
~\Dropbox\utl\7z.exe a -tzip -r .\wwDotnetBridge-Oss.zip .\wwdotnetbridge.dll .\clrhost.dll .\wwDotnetBridge.prg

Distribution/wwDotNetBridge.dll

23 KB
Binary file not shown.

Distribution/wwDotNetBridge.xml

Lines changed: 24 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
5.21 KB
Binary file not shown.

Distribution/wwDotnetBridge.PRG

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,19 @@ RETURN this.oDotNetBridge.GetProperty(loInstance, lcProperty)
682682
ENDFUNC
683683
* GetProperty
684684

685+
************************************************************************
686+
* GetField
687+
****************************************
688+
*** Function: Gets a value from a .NET field.
689+
*** Assume:
690+
*** Pass:
691+
*** Return:
692+
************************************************************************
693+
FUNCTION GetField(loInstance, lcField)
694+
RETURN this.oDotNetBridge.GetField(loInstance, lcField)
695+
ENDFUNC
696+
* GetField
697+
685698
************************************************************************
686699
* GetPropertyRaw
687700
****************************************
@@ -740,6 +753,18 @@ this.oDotNetBridge.SetProperty(loInstance, lcProperty, lvValue)
740753
ENDFUNC
741754
* SetProperty
742755

756+
************************************************************************
757+
* SetField
758+
****************************************
759+
*** Function: Sets a field on a .NET object
760+
*** Assume:
761+
*** Pass:
762+
*** Return:
763+
************************************************************************
764+
FUNCTION SetField(loInstance, lcField, lvValue)
765+
this.oDotNetBridge.SetField(loInstance, lcField, lvValue)
766+
ENDFUNC
767+
* SetField
743768

744769
************************************************************************
745770
* InvokeStaticMethod
@@ -1136,7 +1161,7 @@ ENDFUNC
11361161
*** Return: A subscription object. The subscription ends when this object goes out of scope.
11371162
************************************************************************
11381163
FUNCTION SubscribeToEvents(loSource, loHandler, lcPrefix)
1139-
IF EMPTY(lcPrefix)
1164+
IF VARTYPE(lcPrefix) # "C"
11401165
lcPrefix = "On"
11411166
ENDIF
11421167
LOCAL loSubscription
@@ -1355,6 +1380,12 @@ IF FILE(lcAssembly)
13551380
ENDIF
13561381

13571382
IF AT(":\",lcAssembly) > 0 OR AT("\\",lcAssembly) > 0
1383+
*** Clear zone information
1384+
TRY
1385+
DeleteFile(lcAssembly + ":Zone.Identifier")
1386+
CATCH
1387+
ENDTRY
1388+
13581389
*** It's a file based assembly path
13591390
IF !loBridge.LoadAssemblyFrom(lcAssembly)
13601391
this.SetError(lobridge.ErrorMessage)
@@ -1649,7 +1680,7 @@ ENDFUNC
16491680
****************************************
16501681
*** Function: Gets a property from a .NET object using .syntax for
16511682
*** for the property as well as supporting arrays
1652-
*** Assume: OBSOLETE - just use
1683+
*** Assume: OBSOLETE - just use GetProperty()
16531684
*** Pass:
16541685
*** Return:
16551686
************************************************************************

DotnetBridge/Utilities/FileUtils.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.IO.Compression;
45
using System.Runtime.InteropServices;
56
using System.Text;
7+
#if NETFULL
68
using System.Windows.Forms;
9+
#endif
710

811
namespace Westwind.WebConnection
912
{
@@ -181,7 +184,7 @@ public static string GetRelativePath(string fullPath, string basePath)
181184
return relativeUri.ToString().Replace(oldValue: "/", newValue: "\\");
182185
}
183186

184-
187+
#if NETFULL
185188
/// <summary>
186189
/// Returns a filename for a file to save
187190
/// </summary>
@@ -283,6 +286,7 @@ public static string OpenFolderDialog(string startFolder, string description)
283286

284287
return dialog.SelectedPath;
285288
}
289+
#endif
286290

287291
/// <summary>
288292
/// Deletes files based on a file spec and a given timeout.
@@ -313,17 +317,36 @@ public static void DeleteFiles(string filespec,int seconds)
313317
/// <param name="outputZipFile"></param>
314318
/// <param name="folder"></param>
315319
/// <returns></returns>
316-
public static bool ZipFolder(string outputZipFile, string folder, bool fast)
320+
public static bool ZipFolder(string outputZipFile, string folder, string fileSpec = "*.*", bool fast = false)
317321
{
318322
try
319323
{
320324
if (File.Exists(outputZipFile))
321325
File.Delete(outputZipFile);
322326

323-
ZipFile.CreateFromDirectory(folder,
324-
outputZipFile,
325-
fast ? CompressionLevel.Fastest :CompressionLevel.Optimal,
326-
false);
327+
var tokens = fileSpec.Split(new char[] { ';',',' }, StringSplitOptions.RemoveEmptyEntries);
328+
var files = new List<string>();
329+
foreach (var token in tokens)
330+
{
331+
var filesSub = Directory.GetFiles(folder, token, SearchOption.AllDirectories);
332+
files.AddRange(filesSub);
333+
}
334+
335+
using (var zipFileStream = new FileStream(outputZipFile, FileMode.Create))
336+
{
337+
using (var archive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
338+
{
339+
foreach(var file in files)
340+
{
341+
// filter some files before this, or ignore some files here
342+
343+
var fileName = file;
344+
var entryName = GetRelativePath(file, folder);
345+
346+
archive.CreateEntryFromFile(fileName, entryName, fast ? CompressionLevel.Fastest : CompressionLevel.Optimal );
347+
}
348+
}
349+
}
327350
}
328351
catch
329352
{
@@ -333,6 +356,7 @@ public static bool ZipFolder(string outputZipFile, string folder, bool fast)
333356
return true;
334357
}
335358

359+
336360
/// <summary>
337361
/// Unzips a zip file to a destination folder.
338362
/// </summary>
@@ -342,7 +366,7 @@ public static bool ZipFolder(string outputZipFile, string folder, bool fast)
342366
public static bool UnzipFolder(string zipFile, string folder)
343367
{
344368
try
345-
{
369+
{
346370
ZipFile.ExtractToDirectory(zipFile, folder);
347371
}
348372
catch

DotnetBridge/Utilities/ReflectionUtils.cs

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -524,49 +524,56 @@ public static void InvokeEvent(object instance, string eventName, params object[
524524
/// <returns>Object - cast to proper type</returns>
525525
public static object GetProperty(object instance, string property)
526526
{
527-
return instance.GetType().GetProperty(property, ReflectionUtils.MemberAccess).GetValue(instance, null);
527+
var prop = instance.GetType().GetProperty(property, ReflectionUtils.MemberAccess);
528+
if (prop == null)
529+
throw new InvalidOperationException("Could not find property " + property + " on object of type " + instance.GetType().FullName);
530+
531+
return prop.GetValue(instance, null);
528532
}
529533

530534
/// <summary>
531535
/// Parses Properties and Fields including Array and Collection references.
532536
/// Used internally for the 'Ex' Reflection methods.
533537
/// </summary>
534-
/// <param name="Parent"></param>
535-
/// <param name="Property"></param>
538+
/// <param name="parent"></param>
539+
/// <param name="property"></param>
536540
/// <returns></returns>
537-
private static object GetPropertyInternal(object Parent, string Property)
541+
private static object GetPropertyInternal(object parent, string property)
538542
{
539-
if (Property == "this" || Property == "me")
540-
return Parent;
543+
if (property == "this" || property == "me")
544+
return parent;
541545

542546
object result = null;
543-
string pureProperty = Property;
547+
string pureProperty = property;
544548
string indexes = null;
545549
bool isArrayOrCollection = false;
546550

547551
// Deal with Array Property
548-
if (Property.IndexOf("[") > -1)
552+
if (property.IndexOf("[") > -1)
549553
{
550-
pureProperty = Property.Substring(0, Property.IndexOf("["));
551-
indexes = Property.Substring(Property.IndexOf("["));
554+
pureProperty = property.Substring(0, property.IndexOf("["));
555+
indexes = property.Substring(property.IndexOf("["));
552556
isArrayOrCollection = true;
553557
}
554558

555-
var parentType = Parent.GetType();
559+
var parentType = parent.GetType();
556560

557561
if (string.IsNullOrEmpty(pureProperty))
558562
{
559563
// most likely an indexer
560-
result = Parent;
564+
result = parent;
561565
}
562566
else
563567
{
564568
// Get the member
565-
MemberInfo member = Parent.GetType().GetMember(pureProperty, ReflectionUtils.MemberAccess)[0];
569+
MemberInfo member = parent.GetType().GetMember(pureProperty, ReflectionUtils.MemberAccess)[0];
570+
if (member == null)
571+
throw new InvalidOperationException("Could not find property " + property + " on object of type " + parent.GetType().FullName);
572+
566573
if (member.MemberType == MemberTypes.Property)
567-
result = ((PropertyInfo) member).GetValue(Parent, null);
574+
result = ((PropertyInfo) member).GetValue(parent, null);
568575
else
569-
result = ((FieldInfo) member).GetValue(Parent);
576+
result = ((FieldInfo) member).GetValue(parent);
570577
}
571578

572579
if (isArrayOrCollection)
@@ -626,12 +633,15 @@ public static PropertyInfo GetPropertyInfoInternal(object Parent, string Propert
626633
/// Retrieve a field dynamically from an object. This is a simple implementation that's
627634
/// straight Reflection and doesn't support indexers.
628635
/// </summary>
629-
/// <param name="Object">Object to retreve Field from</param>
630-
/// <param name="Property">name of the field to retrieve</param>
636+
/// <param name="instance">Object to retreve Field from</param>
637+
/// <param name="property">name of the field to retrieve</param>
631638
/// <returns></returns>
632-
public static object GetField(object Object, string Property)
639+
public static object GetField(object instance, string property)
633640
{
634-
return Object.GetType().GetField(Property, ReflectionUtils.MemberAccess | BindingFlags.GetField).GetValue(Object);
641+
var field = instance.GetType().GetField(property, ReflectionUtils.MemberAccess | BindingFlags.GetField);
642+
if (field == null)
643+
throw new InvalidOperationException("Could not find public field " + property + " on object of type " + instance.GetType().FullName);
644+
return field.GetValue(instance);
635645
}
636646

637647

@@ -643,10 +653,12 @@ public static object GetField(object Object, string Property)
643653
/// <param name="property">Name of the property to set</param>
644654
/// <param name="value">value to set it to</param>
645655
public static void SetProperty(object obj, string property, object value)
646-
{
656+
{
647657
obj.GetType().GetProperty(property, ReflectionUtils.MemberAccess).SetValue(obj, value, null);
648658
}
649659

660+
661+
650662
/// <summary>
651663
/// Parses Properties and Fields including Array and Collection references.
652664
/// </summary>
@@ -735,11 +747,15 @@ private static object SetPropertyInternal(object Parent, string Property, object
735747
/// and doesn't support indexers.
736748
/// </summary>
737749
/// <param name="obj">Object to set property on</param>
738-
/// <param name="property">Name of the field to set</param>
750+
/// <param name="fieldName">Name of the field to set</param>
739751
/// <param name="value">value to set it to</param>
740-
public static void SetField(object obj, string property, object value)
752+
public static void SetField(object instance, string fieldName, object value)
741753
{
742-
obj.GetType().GetField(property, ReflectionUtils.MemberAccess).SetValue(obj, value);
754+
var field = instance.GetType().GetField(fieldName, ReflectionUtils.MemberAccess | BindingFlags.GetField | BindingFlags.SetField);
755+
if (field == null)
756+
throw new InvalidOperationException("Could not find public field " + fieldName + " on object of type " + instance.GetType().FullName);
757+
758+
field.SetValue(instance, value);
743759
}
744760

745761

@@ -1003,7 +1019,7 @@ public static object GetPropertyExCom(object parent, string property)
10031019
return parent;
10041020

10051021
// Get the member
1006-
return parent.GetType().InvokeMember(property, ReflectionUtils.MemberAccessCom | BindingFlags.GetProperty , null,
1022+
return parent.GetType().InvokeMember(property, ReflectionUtils.MemberAccessCom | BindingFlags.GetProperty | BindingFlags.GetField, null,
10071023
parent, null);
10081024
}
10091025

0 commit comments

Comments
 (0)