What does xmlns:dc mean in C# WPF? - c#

What does xmlns:dc mean in C# WPF XAML code? Can't find anything on it. Is it directory context? Domain controller?
Sorry for missing context.
I know xmlns is just xaml name space, but i want to know what dc stands for, like what does it mean?
xmlns:dc="clr-namespace:SomethingHere;assembly=SomethingHere"

"dc" is an arbitrary prefix - it is used to reference the namespace as a short hand way, but can be anything you like.
Here's the explanation by the guy who thought it up:
http://www.xml.com/pub/a/1999/01/namespaces.html

dc would just be the namespace of a control you're trying to use, so if you wanted to use a control called ThisControl that was inside the assembly "clr-namespace:SomethingHere;assembly=SomethingHere" you would need to use dc:ThisControl in the xaml.

Working with Cytoscape I have found that xmlns:dc refers to XLM Namespace(xlmns) and the Dublin Core(dc) metadata standard:
https://www.dublincore.org/specifications/dublin-core/dcmi-terms/
When exporting xgmml from cytoscape, part of the xml refers to http://purl.org/dc/elements/1.1/ which redirects to the url above.
Example:
<graph id="78" label="TAPBPL" directed="1" cy:documentVersion="3.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cy="http://www.cytoscape.org" xmlns="http://www.cs.rpi.edu/XGMML">

Related

xamarin android bindings changing a classes final int field to a c# enum

I've been writing a Xamaring Bindings Library for a third party Android JAR and become stumped at how to convert an int field in a class to an enum.
I've created a C# enum for the int fields using EnumFields.xml and have also got this successfully return out of methods using EnumMethods.xml but in one place a class is instead returned which exposes an int field which should be my enum.
I've tried:
<method jni-name="error" parameter="return" clr-enum-type=....
Within EnumMethods but couldnt get it to work, i then tried
<attr path=".......[#name='Result']/field[#name='error']"
name="managedType">
Within Metadata.xml but also couldn't get it to map. I can change its property name but not its return type.
Within the JavaDoc it says the following:
public final int error
And in my generated C# I get:
// Metadata.xml XPath field reference: path="/api/package[#name='cn.com.aratek.util']/class[#name='Result']/field[#name='error']"
Have I missed something obvious?
A year later I ended up stumbling across my own post after hitting the same issue again.
For reference my error was trying to use managedType as the name. You simply use type.
e.g within metadata.xml
<attr path=".......[#name='Result']/field[#name='error']" name="type">NewEnumName</attr>
References I used to help figure this out:
https://gist.github.com/JonDouglas/dda6d8ace7d071b0e8cb - great
resource with lots of examples
The updated Microsoft documentation
https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/customizing-bindings/java-bindings-metadata
Finally, simply looking at other peoples source on git hub. the
GTK# bindings particularly
https://github.com/mono/gtk-sharp/blob/master/gtk/Gtk.metadata

XAML (WPF) Namespace?

I have been trying to read up on XAML namespace and the use of xlmnr and it has been kind of fuzzy. Either it is too technical, or too simplistic.
My question is a little similar to a question asked here, but my question has more to do with the x part attached to it.
So:
Does the xmlns:x, mean a secondary namespace? i.e. the non-default one? Can I have more than one, and if so what order does the search for the right class go in? This of course assumes that xmlns is the default one.
What about the meaning of and difference of attaching x:name as opposed to name to a tag?
Edit:
Turns out, I think I completely misunderstood it. There is no search hiearchy like C# using statement, or java's import. The xmlns:<name> is more like a way to define a name that you can access a whole tree of classes. The x on the other hand is a conventional way to define XMAL related stuff, but is not a requirement.
Can anyone confirm?
The use of XML namespaces in XAML is necessary because of the underlying XML technology used.
xmlns:x indeed creates a second namespace named x. You can reference attributes, etc from it using x:....
If you had simply use name instead of x:name it would have referenced the default namespace.
You can have as much namespaces declared in your XAML as needed.
The standard x namespace exposes common XAML features - basically a mapping of various things that are implemented in code to give them meaning in the XAML context. In the case of x:Name (not x:name - case matters) the XAML compilation process creates a code-behind field based on the x:Name value. The non-x Name property is an attribute representing the Name property on the WPF FrameworkElement base class, which in most cases works the same way as setting the x:Name, and you can't assign both on the same element. See this question for more info.
To the first part of your question: you can change the x to whatever you want, but shouldn't to maintain consistency, and can also (and will in practice) add other xmlns: declarations, primarily to access additional feature implemented in code. For example, if you work in Blend you will often see a xmlns:d added which contains a bunch of designer specific properties. Any code that you need to reference, like data types, converters, etc. will generally use an xmlns: with clr-namespace and assembly specified to map to the .NET namespace in the code: i.e. xmlns:local="clr-namespace:WpfApplication1"

What are these namespace properties doing?

I know this is pretty silly but just wondered if anyone had a link or knows exactly what this code is doing on my page?
namespace com.gvinet.EblAdapter.ebl
{
[Serializable]
[DesignerCategory("code")]
[GeneratedCode("System.Xml", "4.0.30319.225")]
[DebuggerStepThrough]
[XmlType(Namespace = "http://addresshere")]
public class TSAPassenger
{
then here is all of the strings for the form like name, address and such
I am thinking it is trying to grab the XML file that was created from the Database but just want to make sure.
It is not. These are all just metadata attributes.
Serializeable - Use the standard XmlSerializer to take public properties and fields and convert to XML for transport using no customization to the format (like ISerializable would). It is usually only used when going out of process (remoting, Web Services, WCF, etc)
DesignerCategory - This can be used a number of ways. This one tends to be used by the property grid in visual studio as a way to organize sections.
GeneratedCode - The application generated it for you, utilizing the System.Xml namespace in version 4.0.
DebuggerStepThrough - If you are stepping through code (F11), by default, skip over anything here (don't step into a property getting for example).
XmlType - Part of the serializer that allows you to provide a specific namespace that is generated in the output.
The items here do not actually get anything, just describe certain aspects of how something may be loaded/handled.
Hope that makes sense.
The Serializable and XmlType attributes are instructing the XML serializer that the class can be serialized and the schema to use when doing so.
XmlType Attribute
Serializable Attribute
DesignerCategory("code") Attribute
DebuggerStepThrough Attribute
These are attributes - used for declarative programming - you can find more about declarative programming online. But here is the link to .net attribute hierarchy page to get you started: http://msdn.microsoft.com/en-us/library/aa311259(VS.71).aspx
Also, these pages may be helpful:
What are attributes: What are attributes in .NET?
Attributes in C#: http://www.codeproject.com/Articles/2933/Attributes-in-C

XSD file, where to get xmlns argument?

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="abc" targetNamespace="http://schemas.businessNameHere.com/SoftwareNameHere"
elementFormDefault="qualified"
xmlns="http://schemas.businessNameHere.com/SoftwareNameHere"
xmlns:mstns="http://schemas.businessNameHere.com/SoftwareNameHere"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="..." type="..." />
<xs:complexType name="...">
I am working on a project using XSD to generate .cs file. My question is concerning the string "http://schemas.businessNameHere.com/SoftwareNameHere" If I change it, it doesn't work. But the http:// is not a valid one... what is the logic behind and where can I can information about what to put there or how to change it?
XSD namespaces do not have to be valid URI's. Having a namespace string that is a URL doesn't mean anything is fetched from the URL, or anything to do with the web at all - it's simply a string like any other. So although the URL may be invalid from the sense that it doesn't actually point to anything, it's still a valid string as a namespace declaration.
You can read up on some of the reasoning behind namespace identifiers being in this format here.
There are several reasons for using URL's as a namespace identifier, but mainly it is for convenience - it's a unique identifier that generally has some meaning attached to it for the users, much like the way Java namespaces classically begin with "com", "org" or "net".
For the nitty gritty of why namespaces are in URI (technically, IRI) format, you can read the W3C's standards for XML namespaces. The specify that XML Namespaces are in IRI (International Resource Identifier) format, defined in RFC3986.
For more information on how to properly use namespaces, there are lots of great walkthroughs, like this one. What isn't working when you change the namespace?
The namespace does not have semantic meaning beyond having to be unique. People normally use a URI form as that may point to documentation, but this is not a requirement.
In this case, it is the default namespace and it is possible that the application that you are using to generate your .cs files is hardcoded to use it.
In a well written application, nothing should break if you simply change a namespace string.
xmlns="http://schemas.businessNameHere.com/SoftwareNameHere"
This is not a valid URL where some document has to exist - it's only a string that represents a XML namespace (like a namespace in your C# application called System.Data or whatever).
You can easily change that string - there's nothing being referenced here. (but that's a common misconception)
People often use the URL-syntax because the domain registered to you / your company is guaranteed to be unique worldwide -> thus the XML namespace you derive from it will also be unique worldwide.

Type.GetType(string) using "Generic<T>" syntax?

I'm building a generic ASP.NET server control that has an attribute used to specify a type name. I'm using a control builder to generate the generic version of my control by passing the attribute value to Type.GetType(string). This works great. However, if the type that I want to specify is generic, I have to use syntax like this:
<gwb:GenericControl runat="server"
TypeName="System.Collections.Generic.List`1[System.String]" />
I'd like to be able to type it like this:
<gwb:GenericControl runat="server"
TypeName="System.Collections.Generic.List<System.String>" />
I know I could manually parse the value for angle brackets and convert them to square brackets, and add in the appropriate backtick-numeric prefix, but I was wondering if there was any built-in way to do this conversion? I assume the Generic<T> syntax is specific to C# (or at least different in VB.NET) so I'm guessing I'd also have to parse any other language-specific syntax.
I've noticed that ASP.NET MVC does this in the Inherits attribute of the Page directive, but I'm not sure how.
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<MyModel>" %>
No, there is no built-in way of doing this. The reason why is that type names like Generic<T> are indeed specific to C#. They are actually written out differently in metadata.
The short version is that it will be the type name, followed by a ` and then a number corresponding with the count of generic parameters. Generic<T> for instance will be written out as Generic`1 and Generic<T1,T2> will be written out as Generic`2. Arrays add a bit of complication to the syntax but it's the general rule.
When you use Type.GetType you are actually doing a MetaData query vs. a C# query. So the type name must be provided as it appears in MetaData.
There's no built-in way of doing this. You need to parse it out. This is probably what the MVC framework is doing internally.
You won't actually be able to use that specific syntax. Your actual syntax would have to be the following due to the nature of xml:
<gwb:GenericControl runat="server"
TypeName="System.Collections.Generic.List<System.String>" />
You can't use the < character within the value of an attribute if its corresponding > is present. You must encode it with <, which kind of defeats the point of trying to make it work like that in the first place.
The first form is standard IL form (i.e. Namespace.GenericClass`1[[System.String]]) and should be somewhat familiar to any versed .NET language user, and common across the board, while the second is only valid for C#.

Categories