You want to return a string, just a string, from an HTTP POST call.
You code it like this:
Response.Write("Hello World")
The HTTP POST returns:
All you wanted was “Hello World”.
You should have coded it like this:
Response.Write("Hello World") ' The Response.End method causes the Web server to stop processing the script and return the current result. The remaining contents of the file are not processed. Response.End()
The Reflector class below generates an HTML document outlining the public API for a given assembly.
First, an XML document is emitted in memory (see Emit*()).
The document captures the relevant aspects of the assembly's metadata.
Next, an HTML document is extracted from the XML document (see Extract*()).
I love Linq.
Public Class Reflector Public document As XDocument Public Sub Reflect(ByVal assemblyFile As String) Dim Assembly As Assembly = Assembly.LoadFrom(assemblyFile) document = New XDocument(EmitAssembly(Assembly)) End Sub Public Sub Transform(ByVal writer As XmlWriter) If document Is Nothing Then Return Dim assembly As XElement = document.Element("assembly") Dim transform As New XDocument(ExtractAssembly(assembly)) transform.Save(writer) End Sub Public Function EmitAssembly(ByVal assembly As Assembly) As XElement Return End Function Public Function EmitNamespace(ByVal ns As String, ByVal types As IEnumerable(Of Type)) As XElement Return End Function Public Function EmitType(ByVal type As Type) As XElement Return < name=> > End Function Public Function EmitGenericArguments(ByVal args As IEnumerable(Of Type)) As IEnumerable(Of XElement) Return From arg In args _ Select End Function Public Function EmitModifiers(ByVal type As Type) As XElement Dim builder As StringBuilder = New StringBuilder() If type.IsPublic Then builder.Append("public") ElseIf type.IsNestedPublic Then builder.Append("public") ElseIf type.IsNestedFamily Then builder.Append("protected") ElseIf type.IsNestedFamANDAssem Then builder.Append("protected internal") End If If type.IsSealed Then builder.Append(" sealed") If type.IsAbstract Then builder.Append(" abstract") Return End Function Public Function EmitExtends(ByVal baseType As Type) As XElement If baseType Is Nothing Or baseType Is GetType(Object) Or baseType Is GetType(ValueType) Or baseType Is GetType(System.Enum) Then Return Nothing Return End Function Public Function EmitImplements(ByVal ifaces As IEnumerable(Of Type)) As IEnumerable(Of XElement) Return From iface In ifaces _ Select End Function Public Function EmitDeclaringType(ByVal declaringType As Type) As XElement If declaringType Is Nothing Then Return Nothing Return End Function Public Function EmitNestedTypes(ByVal ntypes As IEnumerable(Of Type)) As IEnumerable(Of XElement) Return From ntype In ntypes _ Where GetVisible(ntype) _ Select EmitType(ntype) End Function Public Function EmitMethods(ByVal metds As IEnumerable(Of MethodBase)) As IEnumerable(Of XElement) Return From metd In metds _ Where GetVisible(metd) _ Select End Function Public Function EmitProperties(ByVal props As IEnumerable(Of PropertyInfo)) As IEnumerable(Of XElement) Return From prop In props _ Where GetVisible(prop.GetGetMethod()) Or _ GetVisible(prop.GetSetMethod()) _ Select End Function Public Function EmitReference(ByVal type As Type) As IEnumerable(Of Object) If (Not type.IsGenericType) Then Return New Object() {New XAttribute("name", type.Name), _ New XAttribute("namespace", GetNamespace(type))} Else Return New Object() {New XAttribute("name", type.Name), _ New XAttribute("namespace", GetNamespace(type)), _ EmitGenericArguments(type.GetGenericArguments())} End If End Function Public Function EmitModifiers(ByVal metd As MethodBase) As XElement Dim builder As StringBuilder = New StringBuilder() If metd.IsPublic Then builder.Append("public") ElseIf metd.IsFamily Then builder.Append("protected") ElseIf metd.IsFamilyAndAssembly Then builder.Append("protected internal") End If If metd.IsAbstract Then builder.Append(" abstract") If metd.IsStatic Then builder.Append(" static") If metd.IsVirtual Then builder.Append(" virtual") Return New XElement("modifiers", builder.ToString()) End Function Public Function EmitReturnType(ByVal metd As MethodBase) As XElement Dim metdInfo As MethodInfo = TryCast(metd, MethodInfo) If metdInfo Is Nothing Then Return Nothing Return End Function Public Function EmitExtension(ByVal metd As MethodBase) As XElement Return End Function Public Function EmitParameters(ByVal parms As IEnumerable(Of ParameterInfo)) As IEnumerable(Of XElement) Return From parm In parms _ Select End Function Public Shared Function GetNamespace(ByVal type As Type) As String Dim ns As String = type.Namespace Return If(ns IsNot Nothing, ns, String.Empty) End Function Public Shared Function GetVisible(ByVal type As Type) As Boolean Return type.IsPublic Or type.IsNestedPublic Or type.IsNestedFamily Or type.IsNestedFamANDAssem End Function Public Shared Function GetVisible(ByVal metd As MethodBase) As Boolean Return metd IsNot Nothing AndAlso (metd.IsPublic Or metd.IsFamily Or metd.IsFamilyAndAssembly) End Function Public Function ExtractAssembly(ByVal assembly As XElement) As XElement Return Assembly: End Function Public Function ExtractNamespace(ByVal ns As XElement) As XElement Return Namespace: End Function Public Function ExtractType(ByVal type As XElement) As XElement Return End Function Public Function ExtractModifiers(ByVal element As XElement) As String Return element.Element("modifiers").Value End Function Public Function ExtractName(ByVal element As XElement) As String Dim name As String = element.Attribute("name").Value Dim i As Integer = name.LastIndexOf("`") If i > 0 Then name = name.Substring(0, i) ' fix generic name Return name End Function Public Function ExtractGenericArguments(ByVal element As XElement) As String If Not element.Elements("genericArgument").Any() Then Return String.Empty Dim builder As StringBuilder = New StringBuilder("<") For Each genericArgument As XElement In element.Elements("genericArgument") If builder.Length <> 1 Then builder.Append(", ") builder.Append(ExtractReference(genericArgument)) Next builder.Append(">") Return builder.ToString() End Function Public Function ExtractReference(ByVal element As XElement) As String Return ExtractName(element) + ExtractGenericArguments(element) End Function Public Function ExtractInherits(ByVal type As XElement) As String If Not type.Elements("extends").Concat(type.Elements("implements")).Any() Then Return String.Empty Dim builder As New StringBuilder() For Each [inherits] As XElement In type.Elements("extends").Concat(type.Elements("implements")) If builder.Length = 0 Then builder.Append(" : ") Else builder.Append(", ") End If builder.Append(ExtractReference([inherits])) Next Return builder.ToString() End Function Public Function ExtractConstructors(ByVal type As XElement) As XElement Dim ctors = From ctor In type.Elements("method") _ Where ExtractName(ctor) = ".ctor" _ Select
Have you checked out the Windows Store apps Dev Center lately?
It’s been filled with excellent resources for learning about and developing Windows Store apps. From code, to design guidelines, it’s chuck full of what you need to develop Windows Store Apps.
Feature guide
Product guide
Getting started
Support forums
Design downloads
Our design principles
Index UX guidelines
iPad to Windows Store app
iOS
Android
Windows 8
WPF/Silverlight
Samples
API reference
Downloads
Certification requirements
This post explains several ways well known names help my company build applications rapidly.
In my previous vRAD post I introduced ‘PostalCode’, a well known name I have used for application development since 1992.
In our development world, the well known word PostalCode is used where ever a zip code, post code, or postal code is represented or stored, for example:
1. as the column name of all database table columns that store a zip code, post code, or postal code 2. in data models where ever a zip code, post code, or postal code is used 3. as the property name in all classes that require a zip code, post code, or postal code 4. in programmer documentation 5. in code and other generators
1. as the column name of all database table columns that store a zip code, post code, or postal code
2. in data models where ever a zip code, post code, or postal code is used
3. as the property name in all classes that require a zip code, post code, or postal code
4. in programmer documentation
5. in code and other generators
PostalCode helps build applications rapidly because it reduces development and development project time.
How? Reuse. Reuse as in where the same thing is used again for the same function – again, and again, and again. Since 1992:
1. No design time has been spent coming up with what to name things that will represent or store zip codes, post codes, or postal codes.
2. Programmer documentation about PostalCode has not been changed since 1992.
3. Anyone who has worked for me for more than a couple of months can teach a new person to use PostalCode because it is – you guessed it – well known.
4. Code generators, which require postal codes, post codes, or zip codes - for schemas, models, code, and tests – used the well known name PostalCode. We never spend time modifying that part of our code generators.
Can you think of at least three more ways the well known word PostalCode helps us build applications rapidly?
Answers will be published in the next xRad blog post..
In my two previous vRAD posts I explained the concept of well known names and introduced ‘PostalCode’, a well known name I have used for application development since 1992.
At the end of my last xRAD post I asked: Can you think of at least three more ways the well known word PostalCode helps us build applications rapidly?
Here are a few of many correct answers:
In three posts I have explained the concept of well known names and how a single well known name can speed up application development by promoting re use over new development.
Since 1992 we have developed 1513 well known names. Examples are: PhoneNumber, EmailAddress, City, State, Country, Customer, FirstName, LastName, Contact, Url, Product, UnitOfMeasure.
Our well known names are used in schema scripts for databases, in models, in code, generators, in documentation, and much more. We have code snippets for every well known name.
When we start a new project an average of 88% of the names we need come from our well known names.
In future posts I will explain how the ‘well known’ concept applies to other things used for application development; things like ‘well known tables’, well known methods, well known constants, and more.
The VisualBasic 2012 Async feature makes it simpler to make code asynchronous.
With it you can call into asynchronous methods WITHOUT callbacks and WITHOUT splitting your code into different methods.
The following example shows a Visual Basic async method.
' Add an Imports statement and a reference for System.Net.Http
Imports System.Net.Http Class MainWindow ' Mark the event handler with async so you can use Await in it. Private Async Sub StartButton_Click(sender As Object, e As RoutedEventArgs) ' Call and await separately. 'Task<int> getLengthTask = AccessTheWebAsync(); '' You can do independent work here. 'int contentLength = await getLengthTask; Dim contentLength As Integer = Await AccessTheWebAsync() ResultsTextBox.Text &= String.Format(vbCrLf & "Length of the downloaded string: {0}." & vbCrLf, contentLength) End Sub ' Three things to note in the signature: ' - The method has an Async modifier. ' - The return type is Task or Task(Of T). (See "Return Types" section.) ' Here, it is Task(Of Integer) because the return statement returns an integer. ' - The method name ends in "Async." Async Function AccessTheWebAsync() As Task(Of Integer) ' You need to add a reference to System.Net.Http to declare client. Dim client As HttpClient = New HttpClient() ' GetStringAsync returns a Task(Of String). That means that when you await the ' task you'll get a string (urlContents). Dim getStringTask As Task(Of String) = client.GetStringAsync("http://msdn.microsoft.com") ' You can do work here that doesn't rely on the string from GetStringAsync. DoIndependentWork() ' The Await operator suspends AccessTheWebAsync. ' - AccessTheWebAsync can't continue until getStringTask is complete. ' - Meanwhile, control returns to the caller of AccessTheWebAsync. ' - Control resumes here when getStringTask is complete. ' - The Await operator then retrieves the string result from getStringTask. Dim urlContents As String = Await getStringTask ' The return statement specifies an integer result. ' Any methods that are awaiting AccessTheWebAsync retrieve the length value. Return urlContents.Length End Function Sub DoIndependentWork() ResultsTextBox.Text &= "Working . . . . . . ." & vbCrLf End Sub End Class ' Sample Output: ' Working . . . . . . . ' Length of the downloaded string: 41763.
Imports System.Net.Http
Class MainWindow
' Mark the event handler with async so you can use Await in it.
Private Async Sub StartButton_Click(sender As Object, e As RoutedEventArgs)
' Call and await separately.
'Task<int> getLengthTask = AccessTheWebAsync();
'' You can do independent work here.
'int contentLength = await getLengthTask;
Dim contentLength As Integer = Await AccessTheWebAsync()
ResultsTextBox.Text &=
String.Format(vbCrLf & "Length of the downloaded string: {0}." & vbCrLf, contentLength)
End Sub
' Three things to note in the signature:
' - The method has an Async modifier.
' - The return type is Task or Task(Of T). (See "Return Types" section.)
' Here, it is Task(Of Integer) because the return statement returns an integer.
' - The method name ends in "Async."
Async Function AccessTheWebAsync() As Task(Of Integer)
' You need to add a reference to System.Net.Http to declare client.
Dim client As HttpClient = New HttpClient()
' GetStringAsync returns a Task(Of String). That means that when you await the
' task you'll get a string (urlContents).
Dim getStringTask As Task(Of String) = client.GetStringAsync("http://msdn.microsoft.com")
' You can do work here that doesn't rely on the string from GetStringAsync.
DoIndependentWork()
' The Await operator suspends AccessTheWebAsync.
' - AccessTheWebAsync can't continue until getStringTask is complete.
' - Meanwhile, control returns to the caller of AccessTheWebAsync.
' - Control resumes here when getStringTask is complete.
' - The Await operator then retrieves the string result from getStringTask.
Dim urlContents As String = Await getStringTask
' The return statement specifies an integer result.
' Any methods that are awaiting AccessTheWebAsync retrieve the length value.
Return urlContents.Length
End Function
Sub DoIndependentWork()
ResultsTextBox.Text &= "Working . . . . . . ." & vbCrLf
End Class
' Sample Output:
' Working . . . . . . .
' Length of the downloaded string: 41763.
To learn more click: Asynchronous Programming with Async and Await
Below are some features that may be a part of C#.6 and VB.12. For current information visit Language feature implementation status for Dev14
Feature status as of 10/3/2014:
Feature
Example
C#
VB
Primary constructors
class Point(int x, int y) { … }
No
Auto-property initializers
public int X { get; set; } = x;
Done
Exists
Getter-only auto-properties
public int Y { get; } = y;
Ctor assignment to getter-only autoprops
Y = 15
Parameterless struct ctors
Structure S : Sub New() : End Sub : End Structure
Using static members
using System.Console; … Write(4);
Dictionary initializer
new JObject { ["x"] = 3, ["y"] = 7 }
Indexed member initializer
new JObject { $x = 3, $y = 7 }
Indexed member access
c.$name = c.$first + " " + c.$last;
Declaration expressions
int.TryParse(s, out var x);
Await in catch/finally
try … catch { await … } finally { await … }
Maybe
Exception filters
catch(E e) if (e.Count > 5) { … }
Typecase
Select Case o : Case s As String : …
Guarded cases
Select Case i : Case Is > 0 When i Mod 2 = 0
Partial modules
Partial Module M1
N/A
Partial interfaces
Partial Interface I1
Multiline string literals
"HelloWorld"
Year-first date literals
Dim d = #2014-04-03#
Binary literals
0b00000100
Digit separators
0xEF_FF_00_A0
Line continuation comments
Dim addrs = From c in Customers ' comment
TypeOf IsNot
If TypeOf x IsNot Customer Then …
Expression-bodied members
public double Dist => Sqrt(X * X + Y * Y);
Event initializers
new Customer { Notify += MyHandler };
Null propagation
customer?.Orders?[5]?.$price
Planned
Semicolon operator
(var x = Foo(); Write(x); x * x)
Private protected
private protected string GetId() { … }
Params IEnumerable
int Avg(params IEnumerable numbers) { … }
Constructor Inference
new Tuple(3, "three", true);
String interpolation
"\{p.First} \{p.Last} is \{p.Age} years old."
TryCast for nullable
Dim x = TryCast(u, Integer?)
Delegate combination with +
d1 += d2
Implicit implementation
Class C : Implicitly Implements I
nameof operator
string s = nameof(Console.Write);
Strict modules
Strict Module M
Faster CInt
Dim x = CInt(Math.Truncate(d)) |
#pragma
#Disable Warning BC40008
Checked and Unchecked blocks
Checked : x += 1 : End Checked
Field targets on autoprops
Serializable> Property p As Integer
If(b,e1,e2) uses type context
Dim x As Integer? = If(b,1,Nothing)