public void RichTextEvent() { // arrange var commonStepEdit = DataPortal.CreateChild<CommonStepEdit>(); var fieldTypeInfo = new FieldTypeInfo(); var fieldEdit = DataPortal.CreateChild<FieldEdit>(); fieldEdit.FieldType = fieldTypeInfo; var processFieldViewModel = new ProcessFieldViewModel(fieldEdit, null); var vm = new ProcessFieldCommonStepViewModel(commonStepEdit, new StepInfo(), processFieldViewModel); // act vm.HandleEvent(new IsRichTextAllowedChangedEvent(true)); // assert Assert.IsFalse(vm.IsEnabledWidth); Assert.AreEqual(8, vm.Data.RowSpan); Assert.IsTrue(vm.Data.IsRichTextAllowed); // act vm.HandleEvent(new IsRichTextAllowedChangedEvent(false)); // assert Assert.IsTrue(vm.IsEnabledWidth); Assert.AreEqual(1, vm.Data.RowSpan); Assert.IsFalse(vm.Data.IsRichTextAllowed); }
public void OnImportsSatisfied_PublishedProcessesLoadFailedTest() { var processFieldsVmMock = Mock.Create<ProcessFieldsViewModel>(); var processEditMock = Mock.Create<ProcessEdit>(); var vm = Mock.Create<GageRROptionsStepViewModel>(Constructor.Mocked, Behavior.CallOriginal); Mock.Arrange(() => vm.Model).Returns(processFieldsVmMock); Mock.Arrange(() => processFieldsVmMock.Model).Returns(processEditMock); Mock.NonPublic.Arrange(vm, "RaisePropertyChanged", "ProcessNumericFields").MustBeCalled(); var fieldType = new FieldTypeInfo(); Mock.Arrange(() => fieldType.ColumnType).Returns(ColumnTypes.Numeric); var fieldEditMock = Mock.Create<FieldEdit>(); Mock.Arrange(() => fieldEditMock.IsChild).Returns(true); Mock.Arrange(() => fieldEditMock.FieldType).Returns(fieldType); var sectionMock = Mock.Create<SectionEdit>(Constructor.Mocked, Behavior.Loose); Mock.Arrange(() => sectionMock.FieldList).Returns(new SectionFields { fieldEditMock }); Mock.Arrange(() => sectionMock.IsChild).Returns(true); Mock.Arrange(() => processEditMock.SectionList).Returns(new ProcessSections { sectionMock }); Mock.Arrange(() => PublishedProcesses.GetPublishedProcessesAsync()).Returns((Task<PublishedProcesses>)null); vm.OnImportsSatisfied(); Assert.IsNull(vm.AvailableProcesses); Mock.NonPublic.Assert(vm, "RaisePropertyChanged", Occurs.Never(), "AvailableProcesses"); }
// put these in FormBuilder private FieldControl getFieldControl(Field f, bool isDisplayControl) { FieldTypeInfo fti = FormBuilder.GetFieldTypeInfo(f.FieldTypeID); string s = (isDisplayControl) ? fti.DisplaySrc : fti.EditSrc; FieldControl fc = (FieldControl)Page.LoadControl("~/nodeTemplates/formBuilder/" + s); fc.FormField = f; fc.Mode = "Display"; //(Request.QueryString["action"] != null) ? Request.QueryString["action"] : ""; return(fc); }
public void MaskEvent() { // arrange var commonStepEdit = DataPortal.CreateChild<CommonStepEdit>(); var fieldTypeInfo = new FieldTypeInfo(); var fieldEdit = DataPortal.CreateChild<FieldEdit>(); fieldEdit.FieldType = fieldTypeInfo; var processFieldViewModel = new ProcessFieldViewModel(fieldEdit, null); var vm = new ProcessFieldCommonStepViewModel(commonStepEdit, new StepInfo(), processFieldViewModel); // act vm.HandleEvent(new MaskChangedEvent("00000", "Standart")); // assert Assert.AreEqual("00000", vm.Data.Mask); Assert.AreEqual("Standart", vm.Data.MaskType); }
public void OnImportsSatisfied() { // arrange var commonStepEdit = DataPortal.CreateChild<CommonStepEdit>(); var fieldTypeInfo = new FieldTypeInfo(); var fieldEdit = DataPortal.CreateChild<FieldEdit>(); fieldEdit.FieldType = fieldTypeInfo; var processFieldViewModel = new ProcessFieldViewModel(fieldEdit, null); var vm = new ProcessFieldCommonStepViewModel(commonStepEdit, new StepInfo(), processFieldViewModel) { EventAggregator = new EventAggregatorService(), Model = new ProcessFieldsViewModel { SelectedSection = new ProcessSectionViewModel(DataPortal.CreateChild<SectionEdit>()) } }; // act vm.OnImportsSatisfied(); // assert Assert.IsNotNull(vm.SelectedSection); }
private static Type GetType(FieldTypeInfo typeInfo) { switch (typeInfo.ColumnType) { case ColumnTypes.Numeric: case ColumnTypes.Result: return typeof(double); case ColumnTypes.Integer: return typeof(int); case ColumnTypes.DateTime: return typeof(DateTime); case ColumnTypes.Boolean: return typeof(bool); case ColumnTypes.Reference: return typeof(int); case ColumnTypes.MultiReference: case ColumnTypes.ReverseMultiReference: case ColumnTypes.TreeView: case ColumnTypes.Checklist: return typeof(IEnumerable<>); case ColumnTypes.SPCChart: return typeof(ISpcFieldType); case ColumnTypes.GageRR: return typeof(IGageRRFieldType); case ColumnTypes.FieldBackcolor: return typeof(long); default: return typeof(string); } }
/// <summary> /// Determines whether this instance can filter the specified type. /// </summary> /// <param name="type">The type.</param> /// <returns><c>true</c> if this instance can filter the specified type; otherwise, <c>false</c>.</returns> static bool CanFilter(FieldTypeInfo type) { switch (type.ColumnType) { case ColumnTypes.DateTime: return true; case ColumnTypes.String: return true; case ColumnTypes.Boolean: return true; case ColumnTypes.Integer: return true; case ColumnTypes.Numeric: return true; case ColumnTypes.Double: return true; case ColumnTypes.SampleType: return true; } return false; }
/// <summary> /// Gets the type. /// </summary> /// <param name="typeInfo">The type information.</param> /// <returns>Type.</returns> static Type GetType(FieldTypeInfo typeInfo) { return GetType(typeInfo.ColumnType); }
public void PropertyIsEnabledWidth() { // arrange var commonStepEdit = DataPortal.CreateChild<CommonStepEdit>(); var fieldTypeInfo = new FieldTypeInfo(); var fieldEdit = DataPortal.CreateChild<FieldEdit>(); fieldEdit.FieldType = fieldTypeInfo; var processFieldViewModel = new ProcessFieldViewModel(fieldEdit, null); var vm = new ProcessFieldCommonStepViewModel(commonStepEdit, new StepInfo(), processFieldViewModel); // act vm.IsEnabledWidth = false; // assert Assert.AreEqual(100, vm.Data.Width); // act vm.IsEnabledWidth = true; // assert Assert.AreEqual(50, vm.Data.Width); }
private static FieldTypeInfo getFieldTypeInfo(string mysqlFieldType) { FieldTypeInfo fieldInfo = new FieldTypeInfo(); int startIndex = 0; int endIndex = 0; if (mysqlFieldType.StartsWith("enum")) { fieldInfo.typeName = FieldType.ENUM; fieldInfo.typeSize = 0; fieldInfo.typePrecision = 0; startIndex = mysqlFieldType.IndexOf('(') + 1; endIndex = mysqlFieldType.IndexOf(')'); List<string> listaEnum = mysqlFieldType.Substring(startIndex, endIndex - startIndex).Split(',').ToList<string>(); fieldInfo.typeEnumList = listaEnum; } else if (mysqlFieldType.StartsWith("int")) { fieldInfo.typeName = FieldType.INT; startIndex = mysqlFieldType.IndexOf('(') + 1; endIndex = mysqlFieldType.IndexOf(')'); fieldInfo.typeSize = int.Parse(mysqlFieldType.Substring(startIndex, endIndex - startIndex)); } else if (mysqlFieldType.StartsWith("decimal")) { fieldInfo.typeName = FieldType.DECIMAL; startIndex = mysqlFieldType.IndexOf('(') + 1; endIndex = mysqlFieldType.IndexOf(')'); string characteristcs = mysqlFieldType.Substring(startIndex, endIndex - startIndex); if (characteristcs.Contains(',')) { fieldInfo.typeSize = int.Parse(characteristcs.Split(',').ToArray().ElementAt(0)); fieldInfo.typePrecision = int.Parse(characteristcs.Split(',').ToArray().ElementAt(1)); } else { fieldInfo.typeSize = int.Parse(characteristcs); fieldInfo.typePrecision = 0; } } else if (mysqlFieldType.StartsWith("double")) { fieldInfo.typeName = FieldType.DOUBLE; startIndex = mysqlFieldType.IndexOf('(') + 1; endIndex = mysqlFieldType.IndexOf(')'); string characteristcs = mysqlFieldType.Substring(startIndex, endIndex - startIndex); if (characteristcs.Contains(',')) { fieldInfo.typeSize = int.Parse(characteristcs.Split(',').ToArray().ElementAt(0)); fieldInfo.typePrecision = int.Parse(characteristcs.Split(',').ToArray().ElementAt(1)); } else { fieldInfo.typeSize = int.Parse(characteristcs); fieldInfo.typePrecision = 0; } } else if (mysqlFieldType.StartsWith("bit")) { fieldInfo.typeName = FieldType.BIT; } else if (mysqlFieldType.StartsWith("boolean")) { fieldInfo.typeName = FieldType.BOOLEAN; } else if (mysqlFieldType.StartsWith("datetime")) { fieldInfo.typeName = FieldType.DATETIME; } else if (mysqlFieldType.StartsWith("date")) { fieldInfo.typeName = FieldType.DATE; } else if (mysqlFieldType.StartsWith("time")) { fieldInfo.typeName = FieldType.TIME; } else if (mysqlFieldType.StartsWith("varchar")) { fieldInfo.typeName = FieldType.VARCHAR; startIndex = mysqlFieldType.IndexOf('(') + 1; endIndex = mysqlFieldType.IndexOf(')'); fieldInfo.typeSize = int.Parse(mysqlFieldType.Substring(startIndex, endIndex - startIndex)); } return fieldInfo; }
string GetSQLType(FieldTypeInfo field, bool ignoreIdentity) { string type = ""; if (field.Type == BuiltInTypes.Boolean) { type = "Bit"; } else if (field.Type == BuiltInTypes.Binary) { type = "Binary"; } else if (field.Type == BuiltInTypes.Byte) { type = "TinyInt"; } else if (field.Type == BuiltInTypes.DateTime) { type = "DateTime"; } else if (field.Type == BuiltInTypes.Decimal) { type = "Decimal"; } else if (field.Type == BuiltInTypes.Double) { type = "Float"; } else if (field.Type == BuiltInTypes.Guid) { type = "UniqueIdentifier"; } else if (field.Type == BuiltInTypes.Int16) { type = "SmallInt"; } else if (field.Type == BuiltInTypes.Int32) { type = "Int"; } else if (field.Type == BuiltInTypes.Int64) { type = "BigInt"; } else if (field.Type == BuiltInTypes.Single) { type = "Real"; } else if (field.Type == BuiltInTypes.String) { if (field.IsUnicode) { type = "N"; } if (field.MaxLength <= 0) { type += "Text"; } else { type += (field.IsFixedLength ? "Char" : "VarChar"); type = string.Format("{0}({1})", type, field.MaxLength); } } else if (field.Type == BuiltInTypes.Timestamp) { type = "Timestamp"; } else { throw new NotImplementedException("Mapping for SQL Type not implemented."); } if (!ignoreIdentity && field.IsIdentity) { type += " IDENTITY(1,1)"; } if (!field.Nullable) { type += " NOT NULL"; } return(type); }
public StringBuilder GenerateScripts() { var sb = new StringBuilder(); var models = diagram.Store.ElementDirectory.FindElements <ModelClass>().ToList(); var associations = diagram.Store.ElementDirectory.FindElements <Association>().ToList(); var inheritances = diagram.Store.ElementDirectory.FindElements <Inheritance>().ToList(); Func <ModelClass, string> getTableName = cls => CleanUpDbSchema ? cls.Name : cls.TableName; Func <ModelField, string> getColumnName = fld => CleanUpDbSchema ? fld.Name : fld.ColumnName; Func <string, string, NavigationProperty> getNavProp = (roleName, navPropName) => models.Find(c => c.Name == roleName).NavigationProperties.Find(np => np.Name == navPropName); Func <ModelField, Multiplicity, FieldTypeInfo> getForeignkeyField = (fld, multiplicity) => { var fldInfo = FieldTypeInfo.Parse(fld); fldInfo.IsIdentity = false; fldInfo.Nullable = (multiplicity == Multiplicity.ZeroOne); return(fldInfo); }; Func <string, ModelField> getSinglePrimarykeyField = className => GetRootBaseClass(models.Find(c => c.Name == className)).Fields.Single(f => f.IsPrimaryKey); Func <NavigationProperty, FieldTypeInfo> createForeignkeyField = navProp => { var assoc = associations.Find(a => a.Name == navProp.Association); var relatedEntity = (assoc.End1RoleName == navProp.ModelClass.Name) ? assoc.End2RoleName : assoc.End1RoleName; var relatedPrimaryKeyField = getSinglePrimarykeyField(relatedEntity); return(getForeignkeyField(relatedPrimaryKeyField, navProp.Multiplicity)); }; Func <ModelClass, string> getPrimaryKeyColumnName = model => (model.Baseclass != null) ? inheritances.Find(inh => inh.Subclass == model).DerivedClassPrimaryKeyColumn : getColumnName(model.Fields.Single(f => f.IsPrimaryKey)); var connectionString = (diagram.ModelElement as ModelRoot).ConnectionString; var databaseName = string.IsNullOrEmpty(connectionString) ? "Unnamed Database" : GetDatabaseName(connectionString); //Start with use database sb.AppendLine(string.Format("USE [{0}]", databaseName)); sb.AppendLine("GO"); sb.AppendLine(); //First.. Model Tables models.ForEach(cls => { sb.AppendLine(string.Format("CREATE TABLE [dbo].[{0}](", getTableName(cls))); if (cls.Baseclass != null) { sb.AppendLine(string.Format(" [{0}] {1},", inheritances.Find(inh => inh.Subclass == cls).DerivedClassPrimaryKeyColumn, GetSQLType(FieldTypeInfo.Parse(getSinglePrimarykeyField(cls.Name)), true))); } foreach (var field in GetFilteredNOrderedFields(cls)) { sb.AppendLine(string.Format(" [{0}] {1},", getColumnName(field), GetSQLType(FieldTypeInfo.Parse(field)))); } foreach (var np in cls.NavigationProperties) { var foreignKeyColumn = UseNavigationPropertyNameForFKeys ? np.Name : np.ForeignkeyColumn; if (np.IsForeignkey) { sb.AppendLine(string.Format(" [{0}] {1},", foreignKeyColumn, GetSQLType(createForeignkeyField(np)))); } } if (cls.Fields.Any(f => f.IsPrimaryKey) || cls.Baseclass != null) { sb.AppendLine(string.Format(" CONSTRAINT [PK_{0}] PRIMARY KEY CLUSTERED (", cls.Name)); if (cls.Baseclass != null) { sb.AppendLine(string.Format(" [{0}] ASC", inheritances.Find(inh => inh.Subclass == cls).DerivedClassPrimaryKeyColumn)); } else { sb.AppendLine(string.Join("\n", cls.Fields.Where(f => f.IsPrimaryKey).Select(f => string.Format(" [{0}] ASC", getColumnName(f))).ToArray())); } sb.AppendLine(") ON [PRIMARY]"); } sb.AppendLine(") ON [PRIMARY]"); sb.AppendLine(); sb.AppendLine("GO"); sb.AppendLine(); }); var manyToManyAssociations = associations.Where(a => a.End1Multiplicity == Multiplicity.ZeroMany && a.End2Multiplicity == Multiplicity.ZeroMany).ToList(); //Second... Mapping Tables manyToManyAssociations.ForEach(m2m => { sb.AppendLine(string.Format("CREATE TABLE [dbo].[{0}](", m2m.ManyToManyMappingTable)); sb.AppendLine(string.Format(" [{0}] {1},", m2m.End1ManyToManyMappingColumn, GetSQLType(getForeignkeyField(getSinglePrimarykeyField(m2m.End1RoleName), Multiplicity.ZeroMany)))); sb.AppendLine(string.Format(" [{0}] {1},", m2m.End2ManyToManyMappingColumn, GetSQLType(getForeignkeyField(getSinglePrimarykeyField(m2m.End2RoleName), Multiplicity.ZeroMany)))); //Primarykeys sb.AppendLine(string.Format(" CONSTRAINT [PK_{0}] PRIMARY KEY CLUSTERED (", m2m.ManyToManyMappingTable)); sb.AppendLine(string.Format(" [{0}] ASC,", m2m.End1ManyToManyMappingColumn)); sb.AppendLine(string.Format(" [{0}] ASC", m2m.End2ManyToManyMappingColumn)); sb.AppendLine(") ON [PRIMARY]"); sb.AppendLine(") ON [PRIMARY]"); sb.AppendLine(); sb.AppendLine("GO"); sb.AppendLine(); }); Func <string, string, ModelClass> getRelatedModel = (assoc, modelClass) => { var association = associations.Find(a => a.Name == assoc); return(models.Find(c => c.Name == ((association.End1RoleName == modelClass) ? association.End2RoleName : association.End1RoleName))); }; //Add relationships for inheritances inheritances.ForEach(inh => { var foreignKeyName = string.Format("FK_{0}_{1}_{2}_{3}", getTableName(inh.Subclass), inh.DerivedClassPrimaryKeyColumn, getTableName(inh.Superclass), getPrimaryKeyColumnName(inh.Superclass)); sb.AppendLine(string.Format("ALTER TABLE [dbo].[{0}] WITH CHECK ADD CONSTRAINT [{1}] FOREIGN KEY([{2}])", getTableName(inh.Subclass), foreignKeyName, inh.DerivedClassPrimaryKeyColumn)); sb.AppendLine(string.Format("REFERENCES [dbo].[{0}] ([{1}])", getTableName(inh.Superclass), getPrimaryKeyColumnName(inh.Superclass))); sb.AppendLine("ON DELETE CASCADE"); sb.AppendLine("GO"); sb.AppendLine(); sb.AppendLine(string.Format("ALTER TABLE [dbo].[{0}] CHECK CONSTRAINT [{1}]", getTableName(inh.Subclass), foreignKeyName)); sb.AppendLine("GO"); sb.AppendLine(); }); //Now all the relationships associations.ForEach(assoc => { if (assoc.End1Multiplicity == Multiplicity.ZeroMany && assoc.End2Multiplicity == Multiplicity.ZeroMany) { var end1Entity = models.Find(c => c.Name == assoc.End1RoleName); var end2Entity = models.Find(c => c.Name == assoc.End2RoleName); var end1ForeignKeyName = string.Format("FK_{0}_{1}_{2}_{3}", assoc.ManyToManyMappingTable, assoc.End1ManyToManyMappingColumn, getTableName(end1Entity), assoc.End1NavigationProperty); sb.AppendLine(string.Format("ALTER TABLE [dbo].[{0}] WITH CHECK ADD CONSTRAINT [{1}] FOREIGN KEY([{2}])", assoc.ManyToManyMappingTable, end1ForeignKeyName, assoc.End1ManyToManyMappingColumn)); sb.AppendLine(string.Format("REFERENCES [dbo].[{0}] ([{1}])", getTableName(end1Entity), getPrimaryKeyColumnName(end1Entity))); sb.AppendLine("ON DELETE CASCADE"); sb.AppendLine("GO"); sb.AppendLine(); sb.AppendLine(string.Format("ALTER TABLE [dbo].[{0}] CHECK CONSTRAINT [{1}]", assoc.ManyToManyMappingTable, end1ForeignKeyName)); sb.AppendLine("GO"); sb.AppendLine(); var end2ForeignKeyName = string.Format("FK_{0}_{1}_{2}_{3}", assoc.ManyToManyMappingTable, assoc.End2ManyToManyMappingColumn, getTableName(end2Entity), assoc.End2NavigationProperty); sb.AppendLine(string.Format("ALTER TABLE [dbo].[{0}] WITH CHECK ADD CONSTRAINT [{1}] FOREIGN KEY([{2}])", assoc.ManyToManyMappingTable, end2ForeignKeyName, assoc.End2ManyToManyMappingColumn)); sb.AppendLine(string.Format("REFERENCES [dbo].[{0}] ([{1}])", getTableName(end2Entity), getPrimaryKeyColumnName(end2Entity))); sb.AppendLine("ON DELETE CASCADE"); sb.AppendLine("GO"); sb.AppendLine(); sb.AppendLine(string.Format("ALTER TABLE [dbo].[{0}] CHECK CONSTRAINT [{1}]", assoc.ManyToManyMappingTable, end2ForeignKeyName)); sb.AppendLine("GO"); sb.AppendLine(); } else { var end1NavProp = getNavProp(assoc.End1RoleName, assoc.End1NavigationProperty); var end2NavProp = getNavProp(assoc.End2RoleName, assoc.End2NavigationProperty); if (end1NavProp.IsForeignkey) { var foreignKeyColumn = UseNavigationPropertyNameForFKeys ? end1NavProp.Name : (string.IsNullOrEmpty(end1NavProp.ForeignkeyColumn) ? end1NavProp.Name : end1NavProp.ForeignkeyColumn); var foreignkeyName = CleanUpDbSchema ? string.Format("FK_{0}_{1}_{2}_{3}", getTableName(end1NavProp.ModelClass), end1NavProp.Name, getTableName(end2NavProp.ModelClass), end2NavProp.Name) : assoc.Name; if (end2NavProp.Multiplicity != Multiplicity.ZeroMany) { foreignkeyName += string.Format("_{0}To{1}", end2NavProp.Multiplicity, end1NavProp.Multiplicity); } sb.AppendLine(string.Format("ALTER TABLE [dbo].[{0}] WITH CHECK ADD CONSTRAINT [{1}] FOREIGN KEY([{2}])", getTableName(end1NavProp.ModelClass), foreignkeyName, foreignKeyColumn)); sb.AppendLine(string.Format("REFERENCES [dbo].[{0}] ([{1}])", getTableName(end2NavProp.ModelClass), getPrimaryKeyColumnName(end2NavProp.ModelClass))); sb.AppendLine("GO"); sb.AppendLine(); sb.AppendLine(string.Format("ALTER TABLE [dbo].[{0}] CHECK CONSTRAINT [{1}]", getTableName(end1NavProp.ModelClass), foreignkeyName)); sb.AppendLine("GO"); sb.AppendLine(); } else if (end2NavProp.IsForeignkey) { var foreignKeyColumn = UseNavigationPropertyNameForFKeys ? end2NavProp.Name : (string.IsNullOrEmpty(end2NavProp.ForeignkeyColumn) ? end2NavProp.Name : end2NavProp.ForeignkeyColumn); var foreignkeyName = CleanUpDbSchema ? string.Format("FK_{0}_{1}_{2}_{3}", getTableName(end2NavProp.ModelClass), end2NavProp.Name, getTableName(end1NavProp.ModelClass), end1NavProp.Name) : assoc.Name; if (end1NavProp.Multiplicity != Multiplicity.ZeroMany) { foreignkeyName += string.Format("_{0}To{1}", end1NavProp.Multiplicity, end2NavProp.Multiplicity); } sb.AppendLine(string.Format("ALTER TABLE [dbo].[{0}] WITH CHECK ADD CONSTRAINT [{1}] FOREIGN KEY([{2}])", getTableName(end2NavProp.ModelClass), foreignkeyName, foreignKeyColumn)); sb.AppendLine(string.Format("REFERENCES [dbo].[{0}] ([{1}])", getTableName(end1NavProp.ModelClass), getPrimaryKeyColumnName(end1NavProp.ModelClass))); sb.AppendLine("GO"); sb.AppendLine(); sb.AppendLine(string.Format("ALTER TABLE [dbo].[{0}] CHECK CONSTRAINT [{1}]", getTableName(end2NavProp.ModelClass), foreignkeyName)); sb.AppendLine("GO"); sb.AppendLine(); } } }); return(sb); }
string GetSQLType(FieldTypeInfo field) { return(GetSQLType(field, false)); }
public UnityFieldDetails(FieldDefinitionRaw rawFieldDefinition, bool isBlittable, HashSet <string> enumSet) { PascalCaseName = Formatting.SnakeCaseToCapitalisedCamelCase(rawFieldDefinition.name); CamelCaseName = Formatting.SnakeCaseToCamelCase(rawFieldDefinition.name); var packagePrefix = UnityTypeMappings.PackagePrefix; RawFieldDefinition = rawFieldDefinition; FieldNumber = rawFieldDefinition.Number; IsBlittable = isBlittable; if (rawFieldDefinition.IsOption()) { var valueType = rawFieldDefinition.optionType.valueType; var containedType = GetTypeFromTypeReference(valueType, packagePrefix); var isBuiltInRefType = valueType.TypeName == BuiltInTypeConstants.builtInBytes || valueType.TypeName == BuiltInTypeConstants.builtInString; Type = isBuiltInRefType ? string.Format("global::Improbable.Gdk.Core.Option<{0}>", containedType) : string.Format("global::System.Nullable<{0}>", containedType); SchemaTypeInfo = new FieldTypeInfo { OptionTypeInfo = new TypeInfo { IsPrimitive = SchemaFunctionMappings.BuiltInTypeToAddSchemaFunction.ContainsKey(valueType.TypeName), IsEnum = enumSet.Contains(valueType.TypeName), Type = containedType, SerializationFunctions = new SerializationFunctionStrings { Serialize = GetSerializationFunctionFromType(valueType, packagePrefix), Deserialize = GetDeserializationFunctionFromType(valueType, packagePrefix), GetCount = GetSchemaCountFunctionFromType(valueType), DeserializeIndex = GetDeserializeIndexFunctionFromType(valueType) } } }; } else if (rawFieldDefinition.IsList()) { var valueType = rawFieldDefinition.listType.valueType; var containedType = GetTypeFromTypeReference(valueType, packagePrefix); Type = string.Format("global::System.Collections.Generic.List<{0}>", containedType); SchemaTypeInfo = new FieldTypeInfo { ListTypeInfo = new TypeInfo { IsPrimitive = SchemaFunctionMappings.BuiltInTypeToAddSchemaFunction.ContainsKey(valueType.TypeName), IsEnum = enumSet.Contains(valueType.TypeName), Type = containedType, SerializationFunctions = new SerializationFunctionStrings { Serialize = GetSerializationFunctionFromType(valueType, packagePrefix), Deserialize = GetDeserializationFunctionFromType(valueType, packagePrefix), GetCount = GetSchemaCountFunctionFromType(valueType), DeserializeIndex = GetDeserializeIndexFunctionFromType(valueType) } } }; } else if (rawFieldDefinition.IsMap()) { var keyType = rawFieldDefinition.mapType.keyType; var valueType = rawFieldDefinition.mapType.valueType; var containedKeyType = GetTypeFromTypeReference(keyType, packagePrefix); var containedValueType = GetTypeFromTypeReference(valueType, packagePrefix); Type = string.Format("global::System.Collections.Generic.Dictionary<{0}, {1}>", containedKeyType, containedValueType); SchemaTypeInfo = new FieldTypeInfo { MapTypeInfo = new KeyValuePair <TypeInfo, TypeInfo>( new TypeInfo { IsPrimitive = SchemaFunctionMappings.BuiltInTypeToAddSchemaFunction.ContainsKey(keyType.TypeName), IsEnum = enumSet.Contains(keyType.TypeName), Type = containedKeyType, SerializationFunctions = new SerializationFunctionStrings { Serialize = GetSerializationFunctionFromType(keyType, packagePrefix), Deserialize = GetDeserializationFunctionFromType(keyType, packagePrefix), GetCount = GetSchemaCountFunctionFromType(keyType), DeserializeIndex = GetDeserializeIndexFunctionFromType(keyType) } }, new TypeInfo { IsPrimitive = SchemaFunctionMappings.BuiltInTypeToAddSchemaFunction.ContainsKey(valueType.TypeName), IsEnum = enumSet.Contains(valueType.TypeName), Type = containedValueType, SerializationFunctions = new SerializationFunctionStrings { Serialize = GetSerializationFunctionFromType(valueType, packagePrefix), Deserialize = GetDeserializationFunctionFromType(valueType, packagePrefix), GetCount = GetSchemaCountFunctionFromType(valueType), DeserializeIndex = GetDeserializeIndexFunctionFromType(valueType) } } ) }; } else { Type = GetTypeFromTypeReference(rawFieldDefinition.singularType, packagePrefix); SchemaTypeInfo = new FieldTypeInfo { SingularTypeInfo = new TypeInfo { IsPrimitive = SchemaFunctionMappings.BuiltInTypeToAddSchemaFunction.ContainsKey(rawFieldDefinition .singularType.TypeName), IsEnum = enumSet.Contains(rawFieldDefinition.singularType.TypeName), Type = Type, SerializationFunctions = new SerializationFunctionStrings { Serialize = GetSerializationFunctionFromType(rawFieldDefinition.singularType, packagePrefix), Deserialize = GetDeserializationFunctionFromType(rawFieldDefinition.singularType, packagePrefix), GetCount = GetSchemaCountFunctionFromType(rawFieldDefinition.singularType), DeserializeIndex = GetDeserializeIndexFunctionFromType(rawFieldDefinition.singularType) } } }; } }
/// <summary> /// Initializes a new instance of the <see cref="FieldEditMock"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="systemName">Name of the system.</param> /// <param name="type">The type.</param> public FieldEditMock(string name, string systemName, FieldTypeInfo type) { LoadProperty(NameProperty, name); LoadProperty(SystemNameProperty, systemName); FieldType = type; MarkAsChild(); }