示例#1
0
        private static CompiledFacets GetFacets(XmlSchemaType type)
        {
            CompiledFacets      compiledFacets = new CompiledFacets(type.Datatype);
            XmlSchemaSimpleType simpleType     = type as XmlSchemaSimpleType;

            if (simpleType != null)
            {
                compiledFacets.compileFacets(simpleType);
            }
            return(compiledFacets);
        }
示例#2
0
 private static CompiledFacets GetFacets(XmlSchemaType type)
 {
     CompiledFacets compiledFacets = new CompiledFacets(type.Datatype);
     XmlSchemaSimpleType simpleType = type as XmlSchemaSimpleType;
     
     if(simpleType != null)
     {
         compiledFacets.compileFacets(simpleType);
     }
     return compiledFacets;
 }
示例#3
0
        public static CodeExpression CreateFacets(ClrSimpleTypeInfo type)
        {
            CompiledFacets facets = type.RestrictionFacets;

            CodeObjectCreateExpression createFacets = new CodeObjectCreateExpression();

            createFacets.CreateType = new CodeTypeReference(Constants.RestrictionFacets);

            RestrictionFlags flags = facets.Flags;

            if (flags == 0)
            {
                return(new CodePrimitiveExpression(null));
            }
            else
            {
                CodeCastExpression cast = new CodeCastExpression(new CodeTypeReference(Constants.RestrictionFlags),
                                                                 new CodePrimitiveExpression(
                                                                     System.Convert.ToInt32(flags, CultureInfo.InvariantCulture.NumberFormat)));
                createFacets.Parameters.Add(cast);
            }


            if ((flags & RestrictionFlags.Enumeration) != 0)
            {
                CodeArrayCreateExpression enums = new CodeArrayCreateExpression();
                enums.CreateType = new CodeTypeReference("System.Object");

                foreach (object o in facets.Enumeration)
                {
                    GetCreateValueExpression(o, type, enums.Initializers);
                }

                createFacets.Parameters.Add(enums);
            }
            else
            {
                createFacets.Parameters.Add(new CodePrimitiveExpression(null));
            }

            int fractionDigits = default(int);

            if ((flags & RestrictionFlags.FractionDigits) != 0)
            {
                fractionDigits = facets.FractionDigits;
            }

            createFacets.Parameters.Add(new CodePrimitiveExpression(fractionDigits));

            int length = default(int);

            if ((flags & RestrictionFlags.Length) != 0)
            {
                length = facets.Length;
            }

            createFacets.Parameters.Add(new CodePrimitiveExpression(length));

            object maxExclusive = default(object);

            if ((flags & RestrictionFlags.MaxExclusive) != 0)
            {
                maxExclusive = facets.MaxExclusive;
            }

            GetCreateValueExpression(maxExclusive, type, createFacets.Parameters);


            object maxInclusive = default(object);

            if ((flags & RestrictionFlags.MaxInclusive) != 0)
            {
                maxInclusive = facets.MaxInclusive;
            }

            GetCreateValueExpression(maxInclusive, type, createFacets.Parameters);


            int maxLength = default(int);

            if ((flags & RestrictionFlags.MaxLength) != 0)
            {
                maxLength = facets.MaxLength;
            }

            createFacets.Parameters.Add(new CodePrimitiveExpression(maxLength));

            object minExclusive = default(object);

            if ((flags & RestrictionFlags.MinExclusive) != 0)
            {
                minExclusive = facets.MinExclusive;
            }

            GetCreateValueExpression(minExclusive, type, createFacets.Parameters);


            object minInclusive = default(object);

            if ((flags & RestrictionFlags.MinInclusive) != 0)
            {
                minInclusive = facets.MinInclusive;
            }

            GetCreateValueExpression(minInclusive, type, createFacets.Parameters);


            int minLength = default(int);

            if ((flags & RestrictionFlags.MinLength) != 0)
            {
                minLength = facets.MinLength;
            }

            createFacets.Parameters.Add(new CodePrimitiveExpression(minLength));

            if ((flags & RestrictionFlags.Pattern) != 0)
            {
                CodeArrayCreateExpression patternStrs = new CodeArrayCreateExpression();
                patternStrs.CreateType = new CodeTypeReference(XTypedServices.typeOfString);

                foreach (object o in facets.Patterns)
                {
                    string str = o.ToString();
                    patternStrs.Initializers.Add(new CodePrimitiveExpression(str));
                }

                createFacets.Parameters.Add(patternStrs);
            }
            else
            {
                createFacets.Parameters.Add(new CodePrimitiveExpression(null));
            }

            int totalDigits = default(int);

            if ((flags & RestrictionFlags.TotalDigits) != 0)
            {
                totalDigits = facets.TotalDigits;
            }

            createFacets.Parameters.Add(new CodePrimitiveExpression(totalDigits));

            XmlSchemaWhiteSpace ws = facets.WhiteSpace;

            createFacets.Parameters.Add(
                CodeDomHelper.CreateFieldReference(Constants.XmlSchemaWhiteSpace, ws.ToString()));


            return(createFacets);
        }
        public static CodeExpression CreateFacets(ClrSimpleTypeInfo type)
        {
            //object o = null;
            CodeExpression             codePrimitiveExpression;
            CompiledFacets             facets       = type.RestrictionFacets;
            CodeObjectCreateExpression createFacets = new CodeObjectCreateExpression()
            {
                CreateType = new CodeTypeReference("Xml.Schema.Linq.RestrictionFacets")
            };

            Xml.Schema.Linq.RestrictionFlags flags = facets.Flags;
            if ((int)flags != 0)
            {
                CodeCastExpression cast = new CodeCastExpression(new CodeTypeReference("Xml.Schema.Linq.RestrictionFlags"), new CodePrimitiveExpression((object)Convert.ToInt32(flags, CultureInfo.InvariantCulture.NumberFormat)));
                createFacets.Parameters.Add(cast);
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Enumeration) == 0)
                {
                    createFacets.Parameters.Add(new CodePrimitiveExpression(null));
                }
                else
                {
                    CodeArrayCreateExpression enums = new CodeArrayCreateExpression()
                    {
                        CreateType = new CodeTypeReference("System.Object")
                    };
                    foreach (object o in facets.Enumeration)
                    {
                        SimpleTypeCodeDomHelper.GetCreateValueExpression(o, type, enums.Initializers);
                    }
                    createFacets.Parameters.Add(enums);
                }
                int fractionDigits = 0;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.FractionDigits) != 0)
                {
                    fractionDigits = facets.FractionDigits;
                }
                createFacets.Parameters.Add(new CodePrimitiveExpression((object)fractionDigits));
                int length = 0;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Length) != 0)
                {
                    length = facets.Length;
                }
                createFacets.Parameters.Add(new CodePrimitiveExpression((object)length));
                object maxExclusive = null;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxExclusive) != 0)
                {
                    maxExclusive = facets.MaxExclusive;
                }
                SimpleTypeCodeDomHelper.GetCreateValueExpression(maxExclusive, type, createFacets.Parameters);
                object maxInclusive = null;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxInclusive) != 0)
                {
                    maxInclusive = facets.MaxInclusive;
                }
                SimpleTypeCodeDomHelper.GetCreateValueExpression(maxInclusive, type, createFacets.Parameters);
                int maxLength = 0;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxLength) != 0)
                {
                    maxLength = facets.MaxLength;
                }
                createFacets.Parameters.Add(new CodePrimitiveExpression((object)maxLength));
                object minExclusive = null;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinExclusive) != 0)
                {
                    minExclusive = facets.MinExclusive;
                }
                SimpleTypeCodeDomHelper.GetCreateValueExpression(minExclusive, type, createFacets.Parameters);
                object minInclusive = null;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinInclusive) != 0)
                {
                    minInclusive = facets.MinInclusive;
                }
                SimpleTypeCodeDomHelper.GetCreateValueExpression(minInclusive, type, createFacets.Parameters);
                int minLength = 0;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinLength) != 0)
                {
                    minLength = facets.MinLength;
                }
                createFacets.Parameters.Add(new CodePrimitiveExpression((object)minLength));
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Pattern) == 0)
                {
                    createFacets.Parameters.Add(new CodePrimitiveExpression(null));
                }
                else
                {
                    CodeArrayCreateExpression patternStrs = new CodeArrayCreateExpression()
                    {
                        CreateType = new CodeTypeReference(XTypedServices.typeOfString)
                    };
                    foreach (object pattern in facets.Patterns)
                    {
                        string str = pattern.ToString();
                        patternStrs.Initializers.Add(new CodePrimitiveExpression(str));
                    }
                    createFacets.Parameters.Add(patternStrs);
                }
                int totalDigits = 0;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.TotalDigits) != 0)
                {
                    totalDigits = facets.TotalDigits;
                }
                createFacets.Parameters.Add(new CodePrimitiveExpression((object)totalDigits));
                Xml.Schema.Linq.XmlSchemaWhiteSpace ws = facets.WhiteSpace;
                createFacets.Parameters.Add(CodeDomHelper.CreateFieldReference("XmlSchemaWhiteSpace", ws.ToString()));
                codePrimitiveExpression = createFacets;
            }
            else
            {
                codePrimitiveExpression = new CodePrimitiveExpression(null);
            }
            return(codePrimitiveExpression);
        }