Miscellaneous Debris

Avner Kashtan's Frustrations and Exultations

June 2007 - Posts

Retrieving all properties for a Sharepoint list

When we call the GetListItems or GetListItemChanges methods in Sharepoint's Lists Web Service, we pass an XmlNode parameter specifying which fields we want to return, in this format:

   <FieldRef Name="ows_ID"/>

Now, if we leave this field as null, we get a certain set of properties back - Name, Last Modified and so forth. Basic, commonly used properties. However, if we want to return ALL properties, and we don't want to explicitly state them, we need to pass an XmlNode with an empty-but-valid ViewFields XML:

XmlDocument doc = new XmlDocument();
XmlNode viewFields = doc.CreateElement("ViewFields");
XmlNode results = wsLists.GetListItemChanges(myListGuid, viewFields, since, null);

Now I get a whole handful of properties to read to my heart's delight.

All info via Karthikeyan's blog.

Yet ANOTHER C# language enhancement - this_method()

This one was suggested by a coworker leery of accidental recursion. Too many people aren't used to thinking in terms of recursion and will miss a recursive call inside a method and accidently start an infinite loop, or miss the meaning of a method thinking it's an overload call.

His idea - a language keyword that specifies a call to the CURRENT method, again. He originally suggested the recurse keyword to be totally explicit. I thought of this_method as another substitute that's similar to the existing this keyword.

Now, I know the C# language team don't want to burden the language with too many keywords since it's harder to parse, both by the compiler and the programmer. This certainly shouldn't be a top-priority on the feature list. However, considering C#'s design goal of explicitness, I figure it might make it in.

Any comments/ideas/opinions?

Posted: Jun 03 2007, 02:34 PM by Avner Kashtan | with 23 comment(s)
Filed under: ,
Another pointless operator for C#

I remember discovering C#'s null coalescing operator a while ago. I can't say I use it a lot, but it's useful to clean up my code when I do need it. However, there is another similar scenario that it doesn't cover:

SearchResult res = directorySearcher.FindOne();
return res != null ? res.GetDirectoryEntry() : null;

In this case I have my first object, res, and if it IS null, I want to return it - and if it isn't, I want to return a property of that object. In effect, it's the reverse of the ?? operator - return the first object if it is null, or the second object otherwise.

Can anyone think of a way of implementing such an operator without bothering the C# team over it? :)

EDIT: Here's a code sample of my proposed extension. Note the sneaky usage of the inverted question mark for the inverted operator.

SearchResult res = directorySearcher.FindOne();
return res ¿¿ res.GetDirectoryEntry();

This, in the beautiful world inside my head, would return res.GetDirectoryEntry() if res is not null, but return null if it is. It relates to the first code sample like the way the two code samples in my original link do.

More Posts