本文整理汇总了C#中System.Xml.Serialization.TypeDesc类的典型用法代码示例。如果您正苦于以下问题:C# TypeDesc类的具体用法?C# TypeDesc怎么用?C# TypeDesc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeDesc类属于System.Xml.Serialization命名空间,在下文中一共展示了TypeDesc类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TypeDesc
internal TypeDesc(string name, string fullName, XmlSchemaType dataType, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags, string formatterName)
{
this.name = name.Replace('+', '.');
this.fullName = fullName.Replace('+', '.');
this.kind = kind;
this.baseTypeDesc = baseTypeDesc;
this.flags = flags;
this.isXsdType = kind == TypeKind.Primitive;
if (this.isXsdType)
{
this.weight = 1;
}
else if (kind == TypeKind.Enum)
{
this.weight = 2;
}
else if (this.kind == TypeKind.Root)
{
this.weight = -1;
}
else
{
this.weight = (baseTypeDesc == null) ? 0 : (baseTypeDesc.Weight + 1);
}
this.dataType = dataType;
this.formatterName = formatterName;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:TypeDesc.cs
示例2: FieldModel
internal FieldModel(string name, Type fieldType, TypeDesc fieldTypeDesc, bool checkSpecified, bool checkShouldPersist, bool readOnly)
{
this.fieldTypeDesc = fieldTypeDesc;
this.name = name;
this.fieldType = fieldType;
this.checkSpecified = checkSpecified ? SpecifiedAccessor.ReadWrite : SpecifiedAccessor.None;
this.checkShouldPersist = checkShouldPersist;
this.readOnly = readOnly;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:FieldModel.cs
示例3: TypeDesc
public TypeDesc(string name, string fullName, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags) {
this.name = name.Replace('+', '.');
this.fullName = fullName.Replace('+', '.');
this.kind = kind;
if (baseTypeDesc != null) {
this.baseTypeDesc = baseTypeDesc;
}
this.flags = flags;
this.isXsdType = kind == TypeKind.Primitive;
}
开发者ID:ArildF,项目名称:masters,代码行数:10,代码来源:types.cs
示例4: GetStringForArrayMember
internal string GetStringForArrayMember(string arrayName, string subscript, TypeDesc arrayTypeDesc)
{
if (!arrayTypeDesc.UseReflection)
{
return (arrayName + "[" + subscript + "]");
}
string typeFullName = arrayTypeDesc.IsCollection ? arrayTypeDesc.CSharpName : typeof(Array).FullName;
string reflectionVariable = this.GetReflectionVariable(typeFullName, "0");
return (reflectionVariable + "[" + arrayName + ", " + subscript + "]");
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:10,代码来源:ReflectionAwareCodeGen.cs
示例5: XmlSerializationCodeGen
internal XmlSerializationCodeGen(IndentedWriter writer, TypeScope[] scopes, string access, string className) {
this.writer = writer;
this.scopes = scopes;
if (scopes.Length > 0) {
stringTypeDesc = scopes[0].GetTypeDesc(typeof(string));
qnameTypeDesc = scopes[0].GetTypeDesc(typeof(XmlQualifiedName));
}
this.raCodeGen = new ReflectionAwareCodeGen(writer);
this.className = className;
this.access = access;
}
开发者ID:uQr,项目名称:referencesource,代码行数:11,代码来源:XmlSerializationGeneratedCode.cs
示例6: XmlSerializationILGen
internal XmlSerializationILGen(TypeScope[] scopes, string access, string className) {
this.scopes = scopes;
if (scopes.Length > 0) {
stringTypeDesc = scopes[0].GetTypeDesc(typeof(string));
qnameTypeDesc = scopes[0].GetTypeDesc(typeof(XmlQualifiedName));
}
this.raCodeGen = new ReflectionAwareILGen();
this.className = className;
System.Diagnostics.Debug.Assert(access == "public");
this.typeAttributes = TypeAttributes.Public;
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:11,代码来源:XmlSerializationILGen.cs
示例7: GetNullableType
private string GetNullableType(TypeDesc td)
{
if (td.IsMappedType || (!td.IsValueType && (base.Elements[0].IsSoap || (td.ArrayElementTypeDesc == null))))
{
return td.FullName;
}
if (td.ArrayElementTypeDesc != null)
{
return (this.GetNullableType(td.ArrayElementTypeDesc) + "[]");
}
return ("System.Nullable`1[" + td.FullName + "]");
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:12,代码来源:MemberMapping.cs
示例8: AddElementMetadata
private void AddElementMetadata(CodeAttributeDeclarationCollection metadata, string elementName, TypeDesc typeDesc, bool isNullable)
{
CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(typeof(SoapElementAttribute).FullName);
if (elementName != null)
{
declaration.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(elementName)));
}
if ((typeDesc != null) && typeDesc.IsAmbiguousDataType)
{
declaration.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(typeDesc.DataType.Name)));
}
if (isNullable)
{
declaration.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression(true)));
}
metadata.Add(declaration);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:SoapCodeExporter.cs
示例9: AddNonXsdPrimitive
private static void AddNonXsdPrimitive(Type type, string dataTypeName, string ns, string formatterName, XmlQualifiedName baseTypeName, XmlSchemaFacet[] facets, TypeFlags flags)
{
XmlSchemaSimpleType dataType = new XmlSchemaSimpleType {
Name = dataTypeName
};
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction {
BaseTypeName = baseTypeName
};
foreach (XmlSchemaFacet facet in facets)
{
restriction.Facets.Add(facet);
}
dataType.Content = restriction;
TypeDesc desc = new TypeDesc(type, false, dataType, formatterName, flags);
if (primitiveTypes[type] == null)
{
primitiveTypes.Add(type, desc);
}
primitiveDataTypes.Add(dataType, desc);
primitiveNames.Add(dataTypeName, ns, desc);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:21,代码来源:TypeScope.cs
示例10: WriteArrayLocalDecl
void WriteArrayLocalDecl(string typeName, string variableName, string initValue, TypeDesc arrayTypeDesc) {
RaCodeGen.WriteArrayLocalDecl(typeName, variableName, initValue, arrayTypeDesc);
}
开发者ID:uQr,项目名称:referencesource,代码行数:3,代码来源:XmlSerializationWriter.cs
示例11: WriteArrayItems
void WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, string arrayName, string choiceName) {
TypeDesc arrayElementTypeDesc = arrayTypeDesc.ArrayElementTypeDesc;
if (arrayTypeDesc.IsEnumerable) {
Writer.Write(typeof(IEnumerator).FullName);
Writer.Write(" e = ");
if (arrayTypeDesc.IsPrivateImplementation) {
Writer.Write("((");
Writer.Write(typeof(IEnumerable).FullName);
Writer.Write(")");
Writer.Write(arrayName);
Writer.WriteLine(").GetEnumerator();");
}
else if(arrayTypeDesc.IsGenericInterface) {
if (arrayTypeDesc.UseReflection) {
// we use wildcard method name for generic GetEnumerator method, so we cannot use GetStringForMethodInvoke call here
Writer.Write("(");
Writer.Write(typeof(IEnumerator).FullName);
Writer.Write(")");
Writer.Write(RaCodeGen.GetReflectionVariable(arrayTypeDesc.CSharpName, "System.Collections.Generic.IEnumerable*"));
Writer.Write(".Invoke(");
Writer.Write(arrayName);
Writer.WriteLine(", new object[0]);");
}
else {
Writer.Write("((System.Collections.Generic.IEnumerable<");
Writer.Write(arrayElementTypeDesc.CSharpName);
Writer.Write(">)");
Writer.Write(arrayName);
Writer.WriteLine(").GetEnumerator();");
}
}
else {
if (arrayTypeDesc.UseReflection) {
Writer.Write("(");
Writer.Write(typeof(IEnumerator).FullName);
Writer.Write(")");
}
Writer.Write(RaCodeGen.GetStringForMethodInvoke(arrayName, arrayTypeDesc.CSharpName, "GetEnumerator", arrayTypeDesc.UseReflection));
Writer.WriteLine(";");
}
Writer.WriteLine("if (e != null)");
Writer.WriteLine("while (e.MoveNext()) {");
Writer.Indent++;
string arrayTypeFullName = arrayElementTypeDesc.CSharpName;
WriteLocalDecl(arrayTypeFullName, arrayName+"i", "e.Current", arrayElementTypeDesc.UseReflection);
WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, true);
}
else {
Writer.Write("for (int i");
Writer.Write(arrayName);
Writer.Write(" = 0; i");
Writer.Write(arrayName);
Writer.Write(" < ");
if (arrayTypeDesc.IsArray) {
Writer.Write(arrayName);
Writer.Write(".Length");
}
else {
Writer.Write("((");
Writer.Write(typeof(ICollection).FullName);
Writer.Write(")");
Writer.Write(arrayName);
Writer.Write(").Count");
}
Writer.Write("; i");
Writer.Write(arrayName);
Writer.WriteLine("++) {");
Writer.Indent++;
int count = elements.Length + (text == null ? 0 : 1);
if (count > 1) {
string arrayTypeFullName = arrayElementTypeDesc.CSharpName;
WriteLocalDecl(arrayTypeFullName, arrayName+"i", RaCodeGen.GetStringForArrayMember(arrayName, "i"+arrayName, arrayTypeDesc), arrayElementTypeDesc.UseReflection);
if (choice != null) {
string choiceFullName = choice.Mapping.TypeDesc.CSharpName;
WriteLocalDecl(choiceFullName, choiceName+"i", RaCodeGen.GetStringForArrayMember(choiceName, "i"+arrayName, choice.Mapping.TypeDesc), choice.Mapping.TypeDesc.UseReflection);
}
WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable);
}
else {
WriteElements(RaCodeGen.GetStringForArrayMember(arrayName , "i" + arrayName, arrayTypeDesc), elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable);
}
}
Writer.Indent--;
Writer.WriteLine("}");
}
开发者ID:uQr,项目名称:referencesource,代码行数:86,代码来源:XmlSerializationWriter.cs
示例12: WriteChoiceTypeCheck
void WriteChoiceTypeCheck(string source, string fullTypeName, bool useReflection, ChoiceIdentifierAccessor choice, string enumName, TypeDesc typeDesc) {
Writer.Write("if (((object)");
Writer.Write(source);
Writer.Write(") != null && !(");
WriteInstanceOf(source, fullTypeName, useReflection);
Writer.Write(")) throw CreateMismatchChoiceException(");
WriteQuotedCSharpString(typeDesc.FullName);
Writer.Write(", ");
WriteQuotedCSharpString(choice.MemberName);
Writer.Write(", ");
WriteQuotedCSharpString(enumName);
Writer.WriteLine(");");
}
开发者ID:uQr,项目名称:referencesource,代码行数:14,代码来源:XmlSerializationWriter.cs
示例13: WriteMember
void WriteMember(string source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, bool writeAccessors) {
if (memberTypeDesc.IsArrayLike &&
!(elements.Length == 1 && elements[0].Mapping is ArrayMapping))
WriteArray(source, choiceSource, elements, text, choice, memberTypeDesc);
else
WriteElements(source, choiceSource, elements, text, choice, "a", writeAccessors, memberTypeDesc.IsNullable);
}
开发者ID:uQr,项目名称:referencesource,代码行数:7,代码来源:XmlSerializationWriter.cs
示例14: WriteArray
void WriteArray(string source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc) {
if (elements.Length == 0 && text == null) return;
Writer.WriteLine("{");
Writer.Indent++;
string arrayTypeName = arrayTypeDesc.CSharpName;
WriteArrayLocalDecl(arrayTypeName, "a", source, arrayTypeDesc);
if (arrayTypeDesc.IsNullable) {
Writer.WriteLine("if (a != null) {");
Writer.Indent++;
}
if (choice != null) {
bool choiceUseReflection = choice.Mapping.TypeDesc.UseReflection;
string choiceFullName = choice.Mapping.TypeDesc.CSharpName;
WriteArrayLocalDecl(choiceFullName+"[]", "c", choiceSource, choice.Mapping.TypeDesc);
// write check for the choice identifier array
Writer.WriteLine("if (c == null || c.Length < a.Length) {");
Writer.Indent++;
Writer.Write("throw CreateInvalidChoiceIdentifierValueException(");
WriteQuotedCSharpString(choice.Mapping.TypeDesc.FullName);
Writer.Write(", ");
WriteQuotedCSharpString(choice.MemberName);
Writer.Write(");");
Writer.Indent--;
Writer.WriteLine("}");
}
WriteArrayItems(elements, text, choice, arrayTypeDesc, "a", "c");
if (arrayTypeDesc.IsNullable) {
Writer.Indent--;
Writer.WriteLine("}");
}
Writer.Indent--;
Writer.WriteLine("}");
}
开发者ID:uQr,项目名称:referencesource,代码行数:35,代码来源:XmlSerializationWriter.cs
示例15: CanOptimizeWriteListSequence
bool CanOptimizeWriteListSequence(TypeDesc listElementTypeDesc) {
// check to see if we can write values of the attribute sequentially
// currently we have only one data type (XmlQualifiedName) that we can not write "inline",
// because we need to output xmlns:qx="..." for each of the qnames
return (listElementTypeDesc != null && listElementTypeDesc != QnameTypeDesc);
}
开发者ID:uQr,项目名称:referencesource,代码行数:8,代码来源:XmlSerializationWriter.cs
示例16: GetDefaultValue
object GetDefaultValue(TypeDesc fieldTypeDesc, SoapAttributes a) {
if (a.SoapDefaultValue == null || a.SoapDefaultValue == DBNull.Value) return null;
if (!(fieldTypeDesc.Kind == TypeKind.Primitive || fieldTypeDesc.Kind == TypeKind.Enum)) {
a.SoapDefaultValue = null;
return a.SoapDefaultValue;
}
// for enums validate and return a string representation
if (fieldTypeDesc.Kind == TypeKind.Enum) {
if (fieldTypeDesc != typeScope.GetTypeDesc(a.SoapDefaultValue.GetType()))
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidDefaultEnumValue, a.SoapDefaultValue.GetType().FullName, fieldTypeDesc.FullName));
string strValue = Enum.Format(a.SoapDefaultValue.GetType(), a.SoapDefaultValue, "G").Replace(",", " ");
string numValue = Enum.Format(a.SoapDefaultValue.GetType(), a.SoapDefaultValue, "D");
if (strValue == numValue) // means enum value wasn't recognized
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidDefaultValue, strValue, a.SoapDefaultValue.GetType().FullName));
return strValue;
}
return a.SoapDefaultValue;
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:18,代码来源:soapreflectionimporter.cs
示例17: WritePrimitiveValue
void WritePrimitiveValue(TypeDesc typeDesc, string source, bool isElement) {
if (typeDesc == StringTypeDesc || typeDesc.FormatterName == "String") {
Writer.Write(source);
}
else {
if (!typeDesc.HasCustomFormatter) {
Writer.Write(typeof(XmlConvert).FullName);
Writer.Write(".ToString((");
Writer.Write(typeDesc.CSharpName);
Writer.Write(")");
Writer.Write(source);
Writer.Write(")");
}
else {
Writer.Write("From");
Writer.Write(typeDesc.FormatterName);
Writer.Write("(");
Writer.Write(source);
Writer.Write(")");
}
}
}
开发者ID:uQr,项目名称:referencesource,代码行数:22,代码来源:XmlSerializationWriter.cs
示例18: WriteTypeInfo
string WriteTypeInfo(TypeScope scope, TypeDesc typeDesc, Type type){
InitTheFirstTime();
string typeFullName = typeDesc.CSharpName;
string typeVariable = (string)reflectionVariables[typeFullName];
if (typeVariable != null)
return typeVariable;
if (type.IsArray)
{
typeVariable = GenerateVariableName("array", typeDesc.CSharpName);
TypeDesc elementTypeDesc = typeDesc.ArrayElementTypeDesc;
if (elementTypeDesc.UseReflection)
{
string elementTypeVariable = WriteTypeInfo(scope, elementTypeDesc, scope.GetTypeFromTypeDesc(elementTypeDesc));
writer.WriteLine("static "+typeof(Type).FullName+" "+typeVariable +" = " + elementTypeVariable + ".MakeArrayType();");
}
else
{
string assemblyVariable = WriteAssemblyInfo(type);
writer.Write("static "+typeof(Type).FullName+" "+typeVariable +" = "+assemblyVariable+".GetType(");
WriteQuotedCSharpString(type.FullName);
writer.WriteLine(");");
}
}
else
{
typeVariable = GenerateVariableName("type", typeDesc.CSharpName);
Type parameterType = Nullable.GetUnderlyingType(type);
if (parameterType != null)
{
string parameterTypeVariable = WriteTypeInfo(scope, scope.GetTypeDesc(parameterType), parameterType);
writer.WriteLine("static "+typeof(Type).FullName+" "+typeVariable +" = typeof(System.Nullable<>).MakeGenericType(new " + typeof(Type).FullName + "[] {"+parameterTypeVariable+"});");
}
else
{
string assemblyVariable = WriteAssemblyInfo(type);
writer.Write("static "+typeof(Type).FullName+" "+typeVariable +" = "+assemblyVariable+".GetType(");
WriteQuotedCSharpString(type.FullName);
writer.WriteLine(");");
}
}
reflectionVariables.Add(typeFullName, typeVariable);
TypeMapping mapping = scope.GetTypeMappingFromTypeDesc(typeDesc);
if (mapping != null)
WriteMappingInfo(mapping, typeVariable, type);
if (typeDesc.IsCollection || typeDesc.IsEnumerable){// Arrays use the generic item_Array
TypeDesc elementTypeDesc = typeDesc.ArrayElementTypeDesc;
if (elementTypeDesc.UseReflection)
WriteTypeInfo(scope, elementTypeDesc, scope.GetTypeFromTypeDesc(elementTypeDesc));
WriteCollectionInfo(typeVariable, typeDesc, type);
}
return typeVariable;
}
开发者ID:uQr,项目名称:referencesource,代码行数:56,代码来源:XmlSerializationWriter.cs
示例19: AddPrimitive
private static void AddPrimitive(Type type, string dataTypeName, string formatterName, TypeFlags flags)
{
XmlSchemaSimpleType dataType = new XmlSchemaSimpleType();
dataType.Name = dataTypeName;
TypeDesc typeDesc = new TypeDesc(type, true, dataType, formatterName, flags);
if (s_primitiveTypes[type] == null)
s_primitiveTypes.Add(type, typeDesc);
s_primitiveDataTypes.Add(dataType, typeDesc);
s_primitiveNames.Add(dataTypeName, XmlSchema.Namespace, typeDesc);
}
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:Types.cs
示例20: GetStringForMember
internal string GetStringForMember(string obj, string memberName, TypeDesc typeDesc){
if (!typeDesc.UseReflection)
return obj+"[email protected]"+memberName;
TypeDesc saveTypeDesc = typeDesc;
while(typeDesc!=null){
string typeFullName = typeDesc.CSharpName;
string memberInfoName = GetReflectionVariable(typeFullName, memberName);
if(memberInfoName != null)
return memberInfoName+"["+obj+"]";
// member may be part of the basetype
typeDesc = typeDesc.BaseTypeDesc;
if (typeDesc != null && !typeDesc.UseReflection)
return "(("+typeDesc.CSharpName+")"+obj+")[email protected]"+memberName;
}
//throw GetReflectionVariableException(saveTypeDesc.CSharpName,memberName);
// NOTE, Microsoft:Must never happen. If it does let the code
// gen continue to help debugging what's gone wrong.
// Eventually the compilation will fail.
return "["+obj+"]";
}
开发者ID:uQr,项目名称:referencesource,代码行数:21,代码来源:XmlSerializationWriter.cs
注:本文中的System.Xml.Serialization.TypeDesc类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论