public static GetCreateValueExpression ( object value, Xml.Schema.Linq.CodeGen.ClrSimpleTypeInfo typeDef, |
||
value | object | |
typeDef | Xml.Schema.Linq.CodeGen.ClrSimpleTypeInfo | |
collection | ||
리턴 | void |
public static void GetCreateUnionValueExpression(object value, UnionSimpleTypeInfo unionDef, CodeExpressionCollection collection) { Debug.Assert(unionDef != null); object typedValue = value.GetType().InvokeMember("TypedValue", BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty, null, value, null, CultureInfo.InvariantCulture); CodeExpressionCollection dummy = new CodeExpressionCollection(); ClrSimpleTypeInfo matchingType = null; ClrSimpleTypeInfo[] memberTypes = unionDef.MemberTypes; for (int i = 0; i < (int)memberTypes.Length; i++) { ClrSimpleTypeInfo type = memberTypes[i]; try { SimpleTypeCodeDomHelper.GetCreateValueExpression(typedValue, type, dummy); matchingType = type; break; } catch (Exception exception) { } } Debug.Assert(matchingType != null); SimpleTypeCodeDomHelper.GetCreateValueExpression(typedValue, matchingType, collection); }
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); }