EscapeKeywords() private static method

private static EscapeKeywords ( string identifier ) : string
identifier string
return string
Ejemplo n.º 1
0
        void ExportRoot(StructMapping mapping)
        {
            if (!rootExported)
            {
                rootExported = true;
                ExportDerivedStructs(mapping);

                for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping)
                {
                    if (!derived.ReferencedByElement)
                    {
                        string fullTypeName = CodeIdentifier.EscapeKeywords(derived.TypeDesc.FullName);
                        CodeAttributeArgument[] arguments = new CodeAttributeArgument[] { new CodeAttributeArgument(new CodeTypeOfExpression(fullTypeName)) };
                        AddCustomAttribute(includeMetadata, typeof(XmlIncludeAttribute), arguments);
                    }
                }
                Hashtable typesIncluded = new Hashtable();
                foreach (TypeMapping m in scope.TypeMappings)
                {
                    if (m is ArrayMapping)
                    {
                        ArrayMapping arrayMapping = (ArrayMapping)m;
                        if (ShouldInclude(arrayMapping) && !typesIncluded.Contains(arrayMapping.TypeDesc.FullName))
                        {
                            string fullTypeName = CodeIdentifier.EscapeKeywords(arrayMapping.TypeDesc.FullName);
                            CodeAttributeArgument[] arguments = new CodeAttributeArgument[] { new CodeAttributeArgument(new CodeTypeOfExpression(fullTypeName)) };
                            AddCustomAttribute(includeMetadata, typeof(XmlIncludeAttribute), arguments);
                            typesIncluded.Add(arrayMapping.TypeDesc.FullName, "");
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 void AddIncludeMetadata(CodeAttributeDeclarationCollection metadata, StructMapping mapping)
 {
     for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping)
     {
         string fullTypeName = CodeIdentifier.EscapeKeywords(derived.TypeDesc.FullName);
         CodeAttributeArgument[] arguments = new CodeAttributeArgument[] { new CodeAttributeArgument(new CodeTypeOfExpression(fullTypeName)) };
         AddCustomAttribute(metadata, typeof(SoapIncludeAttribute), arguments);
         AddIncludeMetadata(metadata, derived);
     }
 }
Ejemplo n.º 3
0
        void ExportText(CodeAttributeDeclarationCollection metadata, TypeDesc typeDesc, string dataType)
        {
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(XmlTextAttribute).FullName);

            if (typeDesc != null)
            {
                string fullTypeName = CodeIdentifier.EscapeKeywords(typeDesc.FullName);
                attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(fullTypeName)));
            }
            if (dataType != null)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(dataType)));
            }
            metadata.Add(attribute);
        }
Ejemplo n.º 4
0
        void ExportRoot(StructMapping mapping)
        {
            if (!rootExported)
            {
                rootExported = true;
                ExportDerivedStructs(mapping);

                for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping)
                {
                    if (!derived.ReferencedByElement)
                    {
                        string fullTypeName = CodeIdentifier.EscapeKeywords(derived.TypeDesc.FullName);
                        CodeAttributeArgument[] arguments = new CodeAttributeArgument[] { new CodeAttributeArgument(new CodeTypeOfExpression(fullTypeName)) };
                        AddCustomAttribute(includeMetadata, typeof(SoapIncludeAttribute), arguments);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        void ExportMetadata(CodeAttributeDeclarationCollection metadata, Type attributeType, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, object isNullable, XmlSchemaForm form, int nestingLevel)
        {
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType.FullName);

            if (name != null)
            {
                attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(name)));
            }
            if (typeDesc != null)
            {
                string fullTypeName = CodeIdentifier.EscapeKeywords(typeDesc.FullName);
                attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(fullTypeName)));
            }
            if (form == XmlSchemaForm.Unqualified)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("Form", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(XmlSchemaForm).FullName), "Unqualified")));
            }
            if (ns != null)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns)));
            }
            if (dataTypeDesc != null && dataTypeDesc.IsAmbiguousDataType)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(dataTypeDesc.DataType.Name)));
            }
            if (isNullable != null)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression((bool)isNullable)));
            }
            if (nestingLevel > 0)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("NestingLevel", new CodePrimitiveExpression(nestingLevel)));
            }

            if (attribute.Arguments.Count == 0 && attributeType == typeof(XmlElementAttribute))
            {
                return;
            }
            metadata.Add(attribute);
        }
Ejemplo n.º 6
0
        void AddDefaultValueAttribute(CodeMemberField field, CodeAttributeDeclarationCollection metadata, object value, TypeMapping mapping)
        {
            #if DEBUG
            // use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
            if (!(mapping is PrimitiveMapping))
            {
                throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorDetails, "Default value is invalid for " + mapping.GetType().Name));
            }
            else if (mapping.IsList)
            {
                throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorDetails, "Default value is invalid for " + mapping.GetType().Name));
            }
            #endif

            if (value == null)
            {
                return;
            }

            CodeExpression          valueExpression = null;
            CodeExpression          initExpression  = null;
            CodeExpression          typeofValue     = null;
            string                  typeName        = mapping.TypeDesc.FullName;
            Type                    type            = value.GetType();
            CodeAttributeArgument[] arguments       = null;

            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 (value.GetType() != typeof(string))
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorDetails, "Invalid enumeration type " + value.GetType().Name));
                }
                #endif

                if (((EnumMapping)mapping).IsFlags)
                {
                    string[] values = ((string)value).Split(null);
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (values[i].Length == 0)
                        {
                            continue;
                        }
                        CodeExpression enumRef = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeName), values[i]);
                        if (valueExpression != null)
                        {
                            valueExpression = new CodeBinaryOperatorExpression(valueExpression, CodeBinaryOperatorType.BitwiseOr, enumRef);
                        }
                        else
                        {
                            valueExpression = enumRef;
                        }
                    }
                }
                else
                {
                    valueExpression = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeName), (string)value);
                }
                initExpression = valueExpression;
                arguments      = new CodeAttributeArgument[] { new CodeAttributeArgument(valueExpression) };
            }
            else if (type == typeof(bool) ||
                     type == typeof(Int32) ||
                     type == typeof(string) ||
                     type == typeof(double))
            {
                initExpression = valueExpression = new CodePrimitiveExpression(value);
                arguments      = new CodeAttributeArgument[] { new CodeAttributeArgument(valueExpression) };
            }
            else if (type == typeof(Int16) ||
                     type == typeof(Int64) ||
                     type == typeof(float) ||
                     type == typeof(byte) ||
                     type == typeof(decimal))
            {
                valueExpression = new CodePrimitiveExpression(value.ToString());
                typeofValue     = new CodeTypeOfExpression(CodeIdentifier.EscapeKeywords(type.FullName));
                arguments       = new CodeAttributeArgument[] { new CodeAttributeArgument(typeofValue), new CodeAttributeArgument(valueExpression) };
                initExpression  = new CodeCastExpression(type.FullName, new CodePrimitiveExpression(value));
            }
            else if (type == typeof(sbyte) ||
                     type == typeof(UInt16) ||
                     type == typeof(UInt32) ||
                     type == typeof(UInt64))
            {
                // need to promote the non-CLS complient types

                value = PromoteType(type, value);

                valueExpression = new CodePrimitiveExpression(value.ToString());
                typeofValue     = new CodeTypeOfExpression(CodeIdentifier.EscapeKeywords(type.FullName));
                arguments       = new CodeAttributeArgument[] { new CodeAttributeArgument(typeofValue), new CodeAttributeArgument(valueExpression) };
                initExpression  = new CodeCastExpression(type.FullName, new CodePrimitiveExpression(value));
            }
            else if (type == typeof(DateTime))
            {
                DateTime dt = (DateTime)value;
                string   dtString;
                long     ticks;
                if (mapping.TypeDesc.FormatterName == "Date")
                {
                    dtString = XmlCustomFormatter.FromDate(dt);
                    ticks    = (new DateTime(dt.Year, dt.Month, dt.Day)).Ticks;
                }
                else if (mapping.TypeDesc.FormatterName == "Time")
                {
                    dtString = XmlCustomFormatter.FromDateTime(dt);
                    ticks    = dt.Ticks;
                }
                else
                {
                    dtString = XmlCustomFormatter.FromDateTime(dt);
                    ticks    = dt.Ticks;
                }
                valueExpression = new CodePrimitiveExpression(dtString);
                typeofValue     = new CodeTypeOfExpression(CodeIdentifier.EscapeKeywords(type.FullName));
                arguments       = new CodeAttributeArgument[] { new CodeAttributeArgument(typeofValue), new CodeAttributeArgument(valueExpression) };
                initExpression  = new CodeObjectCreateExpression(new CodeTypeReference(typeof(DateTime)), new CodeExpression[] { new CodePrimitiveExpression(ticks) });
            }
            if (arguments != null)
            {
                if (field != null)
                {
                    field.InitExpression = initExpression;
                }
                AddCustomAttribute(metadata, typeof(DefaultValueAttribute), arguments);
            }
        }