I generated code using slsvcutil from a wcf service. It generated this snippet:
Guardian.EditObservation.DataContracts.PersonBase = public partial class(System.Object)
private
var IDField: System.Nullable<System.Guid>;
method get_ID: System.Nullable<System.Guid>;
method set_ID(value: System.Nullable<System.Guid>);
public
[System.Runtime.Serialization.DataMemberAttribute]
property ID: System.Nullable<System.Guid> read get_ID write set_ID;
Then I added this in another file:
PersonBase = public partial class( Object )
private
etc.
All of that was in one assembly. In that same assembly I had this code:
type
PersonBaseList = List<PersonBase>;
PersonList = PersonBaseList;
for each p in PersonList do begin
if p.ID.Equals( value ) then begin
var found : Boolean := false;
for each observer : PersonBase in ObserverChoicesList do begin
if p.ID.Value = observer.ID.Value then begin
found := true;
break;
end;
end;...
Note the p.ID.Value and Observer.ID.Value.
Then I had to refactor. So I made a new assembly that included the generated code and the additional partial class definitions.
Then I made the original assembly reference this new one.
Now, there are a couple of problems. First, the type doesn’t seem to be properly inferred when I put my cursor over the p. It just says it is an object. If I add the type of p in the for each as:
for each p : PersonBase in PersonList do begin
Then the debugger shows the right class. The second problem is that it says I can’t use Value anymore. Not sure why it was required before and now it isn’t.
And later in the code I was doing:
method PersonComparer.Compare( x: PersonBase; y: PersonBase ): Int32;
begin
if ( x = nil ) and ( y = nil ) then exit 0;
if x = nil then exit -1;
if y = nil then exit +1;
if ( x.ID.Value = Guid.Empty ) and
( y.ID.Value = Guid.Empty ) then exit 0;
if x.ID.GetValueOrDefault = Guid.Empty then exit -1;
But now it says that Value can’t be used and
error PE223: "System.Guid" does not contain a definition for "GetValueOrDefault" in expression "x.ID.Value.GetValueOrDefault"
First it shouldn’t be a system.guid, it should be a nullable system.guid. And second, why can’t I use the GetValueOrDefault anymore.
I suspect all of this has to do with the special way Oxygene treats system.nullable<system.guid>, but I didn’t expect things to change just because I refactored the code to another assembly.
Can someone explain what is going on here?