本文整理汇总了C#中System.Xml.Serialization.TypeMapping类的典型用法代码示例。如果您正苦于以下问题:C# TypeMapping类的具体用法?C# TypeMapping怎么用?C# TypeMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeMapping类属于System.Xml.Serialization命名空间,在下文中一共展示了TypeMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteQualifiedNameElement
void WriteQualifiedNameElement(string name, string ns, object defaultValue, SourceInfo source, bool nullable, TypeMapping mapping) {
bool hasDefault = defaultValue != null && defaultValue != DBNull.Value;
if (hasDefault) {
throw CodeGenerator.NotSupported("XmlQualifiedName DefaultValue not supported. Fail in WriteValue()");
}
List<Type> argTypes = new List<Type>();
ilg.Ldarg(0);
ilg.Ldstr(name);
argTypes.Add(typeof(string));
if (ns != null) {
ilg.Ldstr(ns);
argTypes.Add(typeof(string));
}
source.Load(mapping.TypeDesc.Type);
argTypes.Add(mapping.TypeDesc.Type);
MethodInfo XmlSerializationWriter_WriteXXX = typeof(XmlSerializationWriter).GetMethod(
nullable ? ("WriteNullableQualifiedNameLiteral") : "WriteElementQualifiedName",
CodeGenerator.InstanceBindingFlags,
null,
argTypes.ToArray(),
null
);
ilg.Call(XmlSerializationWriter_WriteXXX);
if (hasDefault) {
throw CodeGenerator.NotSupported("XmlQualifiedName DefaultValue not supported. Fail in WriteValue()");
}
}
示例2: ExportType
void ExportType(TypeMapping mapping) {
if (mapping.IsReference)
return;
if (ExportedMappings[mapping] == null) {
CodeTypeDeclaration codeClass = null;
ExportedMappings.Add(mapping, mapping);
if (mapping is EnumMapping) {
codeClass = ExportEnum((EnumMapping)mapping, typeof(SoapEnumAttribute));
}
else if (mapping is StructMapping) {
codeClass = ExportStruct((StructMapping)mapping);
}
else if (mapping is ArrayMapping) {
EnsureTypesExported(((ArrayMapping)mapping).Elements, null);
}
if (codeClass != null) {
// Add [GeneratedCodeAttribute(Tool=.., Version=..)]
codeClass.CustomAttributes.Add(GeneratedCodeAttribute);
// Add [SerializableAttribute]
codeClass.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(SerializableAttribute).FullName));
if (!codeClass.IsEnum) {
// Add [DebuggerStepThrough]
codeClass.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(DebuggerStepThroughAttribute).FullName));
// Add [DesignerCategory("code")]
codeClass.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(DesignerCategoryAttribute).FullName, new CodeAttributeArgument[] {new CodeAttributeArgument(new CodePrimitiveExpression("code"))}));
}
AddTypeMetadata(codeClass.CustomAttributes, typeof(SoapTypeAttribute), mapping.TypeDesc.Name, Accessor.UnescapeName(mapping.TypeName), mapping.Namespace, mapping.IncludeInSchema);
ExportedClasses.Add(mapping, codeClass);
}
}
}
示例3: ReferenceMapping
internal string ReferenceMapping(TypeMapping mapping)
{
if (!mapping.IsSoap)
{
if (_generatedMethods[mapping] == null)
{
_referencedMethods = EnsureArrayIndex(_referencedMethods, _references);
_referencedMethods[_references++] = mapping;
}
}
return (string)_methodNames[mapping];
}
示例4: GenerateMethod
internal override void GenerateMethod(TypeMapping mapping) {
if (GeneratedMethods.Contains(mapping))
return;
GeneratedMethods[mapping] = mapping;
if (mapping is StructMapping) {
WriteStructMethod((StructMapping)mapping);
}
else if (mapping is EnumMapping) {
WriteEnumMethod((EnumMapping)mapping);
}
}
示例5: EnsureArrayIndex
private TypeMapping[] EnsureArrayIndex(TypeMapping[] a, int index)
{
if (a == null)
{
return new TypeMapping[0x20];
}
if (index < a.Length)
{
return a;
}
TypeMapping[] destinationArray = new TypeMapping[a.Length + 0x20];
Array.Copy(a, destinationArray, index);
return destinationArray;
}
示例6: GenerateMethod
internal override void GenerateMethod(TypeMapping mapping)
{
if (!GeneratedMethods.Add(mapping))
return;
if (mapping is StructMapping)
{
WriteStructMethod((StructMapping)mapping);
}
else if (mapping is EnumMapping)
{
WriteEnumMethod((EnumMapping)mapping);
}
}
示例7: WriteCreateMapping
void WriteCreateMapping(TypeMapping mapping, string local) {
string fullTypeName = mapping.TypeDesc.CSharpName;
bool useReflection = mapping.TypeDesc.UseReflection;
bool ctorInaccessible = mapping.TypeDesc.CannotNew;
Writer.Write(useReflection ? "object" : fullTypeName);
Writer.Write(" ");
Writer.Write(local);
Writer.WriteLine(";");
if (ctorInaccessible) {
Writer.WriteLine("try {");
Writer.Indent++;
}
Writer.Write(local);
Writer.Write(" = ");
Writer.Write(RaCodeGen.GetStringForCreateInstance(fullTypeName, useReflection, mapping.TypeDesc.CannotNew, true));
Writer.WriteLine(";");
if (ctorInaccessible) {
WriteCatchException(typeof(MissingMethodException));
Writer.Indent++;
Writer.Write("throw CreateInaccessibleConstructorException(");
WriteQuotedCSharpString(fullTypeName);
Writer.WriteLine(");");
WriteCatchException(typeof(SecurityException));
Writer.Indent++;
Writer.Write("throw CreateCtorHasSecurityException(");
WriteQuotedCSharpString(fullTypeName);
Writer.WriteLine(");");
Writer.Indent--;
Writer.WriteLine("}");
}
}
示例8: ReferenceMapping
internal string ReferenceMapping(TypeMapping mapping)
{
if (!_generatedMethods.Contains(mapping))
{
_referencedMethods = EnsureArrayIndex(_referencedMethods, _references);
_referencedMethods[_references++] = mapping;
}
string methodName;
_methodNames.TryGetValue(mapping, out methodName);
return methodName;
}
示例9: WritePrimitive
void WritePrimitive(TypeMapping mapping, string source) {
if (mapping is EnumMapping) {
string enumMethodName = ReferenceMapping(mapping);
if (enumMethodName == null) throw new InvalidOperationException(Res.GetString(Res.XmlMissingMethodEnum, mapping.TypeDesc.Name));
if (mapping.IsSoap) {
// SOAP methods are not strongly-typed (the return object), so we need to add a cast
Writer.Write("(");
Writer.Write(mapping.TypeDesc.CSharpName);
Writer.Write(")");
}
Writer.Write(enumMethodName);
Writer.Write("(");
if (!mapping.IsSoap) Writer.Write(source);
Writer.Write(")");
}
else if (mapping.TypeDesc == StringTypeDesc) {
Writer.Write(source);
}
else if (mapping.TypeDesc.FormatterName == "String") {
if (mapping.TypeDesc.CollapseWhitespace) {
Writer.Write("CollapseWhitespace(");
Writer.Write(source);
Writer.Write(")");
}
else {
Writer.Write(source);
}
}
else {
if (!mapping.TypeDesc.HasCustomFormatter) {
Writer.Write(typeof(XmlConvert).FullName);
Writer.Write(".");
}
Writer.Write("To");
Writer.Write(mapping.TypeDesc.FormatterName);
Writer.Write("(");
Writer.Write(source);
Writer.Write(")");
}
}
示例10: CreateElementAccessor
static ElementAccessor CreateElementAccessor(TypeMapping mapping, string ns) {
ElementAccessor element = new ElementAccessor();
if (mapping.TypeDesc.Kind == TypeKind.Node) {
element.Any = true;
}
else {
element.Name = Accessor.EscapeName(mapping.TypeName, false);
element.Namespace = ns;
}
element.Mapping = mapping;
return element;
}
示例11: ExportDefaultValue
internal static string ExportDefaultValue(TypeMapping mapping, object value)
{
if (!(mapping is PrimitiveMapping))
{
return null;
}
if ((value == null) || (value == DBNull.Value))
{
return null;
}
if (mapping is EnumMapping)
{
EnumMapping mapping2 = (EnumMapping) mapping;
ConstantMapping[] constants = mapping2.Constants;
if (mapping2.IsFlags)
{
string[] vals = new string[constants.Length];
long[] ids = new long[constants.Length];
Hashtable hashtable = new Hashtable();
for (int j = 0; j < constants.Length; j++)
{
vals[j] = constants[j].XmlName;
ids[j] = ((int) 1) << j;
hashtable.Add(constants[j].Name, ids[j]);
}
long val = XmlCustomFormatter.ToEnum((string) value, hashtable, mapping2.TypeName, false);
if (val == 0L)
{
return null;
}
return XmlCustomFormatter.FromEnum(val, vals, ids, mapping.TypeDesc.FullName);
}
for (int i = 0; i < constants.Length; i++)
{
if (constants[i].Name == ((string) value))
{
return constants[i].XmlName;
}
}
return null;
}
PrimitiveMapping mapping3 = (PrimitiveMapping) mapping;
if (!mapping3.TypeDesc.HasCustomFormatter)
{
if (mapping3.TypeDesc.FormatterName == "String")
{
return (string) value;
}
Type type = typeof(XmlConvert);
MethodInfo method = type.GetMethod("ToString", new Type[] { mapping3.TypeDesc.Type });
if (method != null)
{
return (string) method.Invoke(type, new object[] { value });
}
}
else
{
string str = XmlCustomFormatter.FromDefaultValue(value, mapping3.TypeDesc.FormatterName);
if (str == null)
{
throw new InvalidOperationException(Res.GetString("XmlInvalidDefaultValue", new object[] { value.ToString(), mapping3.TypeDesc.Name }));
}
return str;
}
throw new InvalidOperationException(Res.GetString("XmlInvalidDefaultValue", new object[] { value.ToString(), mapping3.TypeDesc.Name }));
}
示例12: CreateElementAccessor
static ElementAccessor CreateElementAccessor(TypeMapping mapping, string ns) {
ElementAccessor element = new ElementAccessor();
bool isAny = mapping.TypeDesc.Kind == TypeKind.Node;
if (!isAny && mapping is SerializableMapping) {
isAny = ((SerializableMapping)mapping).IsAny;
}
if (isAny) {
element.Any = true;
}
else {
element.Name = mapping.DefaultElementName;
element.Namespace = ns;
}
element.Mapping = mapping;
return element;
}
示例13: WritePrimitive
void WritePrimitive(string method, string name, string ns, object defaultValue, string source, TypeMapping mapping, bool writeXsiType, bool isElement, bool isNullable) {
TypeDesc typeDesc = mapping.TypeDesc;
bool hasDefault = defaultValue != null && defaultValue != DBNull.Value && mapping.TypeDesc.HasDefaultSupport;
if (hasDefault) {
if (mapping is EnumMapping) {
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (defaultValue.GetType() != typeof(string)) throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorDetails, name + " has invalid default type " + defaultValue.GetType().Name));
#endif
Writer.Write("if (");
if (mapping.TypeDesc.UseReflection)
Writer.Write(RaCodeGen.GetStringForEnumLongValue(source, mapping.TypeDesc.UseReflection));
else
Writer.Write(source);
Writer.Write(" != ");
if (((EnumMapping)mapping).IsFlags) {
Writer.Write("(");
string[] values = ((string)defaultValue).Split(null);
for (int i = 0; i < values.Length; i++) {
if (values[i] == null || values[i].Length == 0)
continue;
if (i > 0)
Writer.WriteLine(" | ");
Writer.Write(RaCodeGen.GetStringForEnumCompare((EnumMapping)mapping, values[i], mapping.TypeDesc.UseReflection));
}
Writer.Write(")");
}
else {
Writer.Write(RaCodeGen.GetStringForEnumCompare((EnumMapping)mapping, (string)defaultValue, mapping.TypeDesc.UseReflection));
}
Writer.Write(")");
}
else {
WriteCheckDefault(source, defaultValue, isNullable);
}
Writer.WriteLine(" {");
Writer.Indent++;
}
Writer.Write(method);
Writer.Write("(");
WriteQuotedCSharpString(name);
if (ns != null) {
Writer.Write(", ");
WriteQuotedCSharpString(ns);
}
Writer.Write(", ");
if (mapping is EnumMapping) {
WriteEnumValue((EnumMapping)mapping, source);
}
else {
WritePrimitiveValue(typeDesc, source, isElement);
}
if (writeXsiType) {
Writer.Write(", new System.Xml.XmlQualifiedName(");
WriteQuotedCSharpString(mapping.TypeName);
Writer.Write(", ");
WriteQuotedCSharpString(mapping.Namespace);
Writer.Write(")");
}
Writer.WriteLine(");");
if (hasDefault) {
Writer.Indent--;
Writer.WriteLine("}");
}
}
示例14: ReferenceMapping
internal string ReferenceMapping(TypeMapping mapping)
{
if (!mapping.IsSoap && (this.generatedMethods[mapping] == null))
{
this.referencedMethods = this.EnsureArrayIndex(this.referencedMethods, this.references);
this.referencedMethods[this.references++] = mapping;
}
return (string) this.methodNames[mapping];
}
示例15: GenerateMethod
internal virtual void GenerateMethod(TypeMapping mapping){}