private void AddEnumGet(EnumPropertyInfo info, CodeMemberProperty property) { CodeExpression returnExpression; if (info.IsMultSelect) { MultiSelectEnumCreated = true; // return EntityOptionSetEnum.GetMultiEnum<info.OptionSetType>(this, info.LogicalName); returnExpression = new CodeMethodInvokeExpression( new CodeMethodReferenceExpression( CreateBaseClasses ? new CodeTypeReferenceExpression(EntityBaseClassGenerator.BaseEntityName) : new CodeTypeReferenceExpression("EntityOptionSetEnum"), "GetMultiEnum", new CodeTypeReference(info.OptionSetType)), new CodeThisReferenceExpression(), new CodePrimitiveExpression(info.LogicalName)); } else { returnExpression = new CodeCastExpression( info.EnumType, new CodeMethodInvokeExpression( CreateBaseClasses ? new CodeTypeReferenceExpression(EntityBaseClassGenerator.BaseEntityName) : new CodeTypeReferenceExpression("EntityOptionSetEnum"), "GetEnum", new CodeThisReferenceExpression(), new CodePrimitiveExpression(info.LogicalName))); } property.GetStatements.Add(new CodeMethodReturnStatement(returnExpression)); }
private void AddEnumSet(CodeMemberProperty prop, EnumPropertyInfo info, CodeMemberProperty property) { if (prop.HasSet) { CodeExpression setExpression; if (info.IsMultSelect) { //EntityOptionSetEnum.GetMultiEnum(this, info.LogicalName, value) setExpression = new CodeMethodInvokeExpression( CreateBaseClasses ? new CodeTypeReferenceExpression(EntityBaseClassGenerator.BaseEntityName) : new CodeTypeReferenceExpression("EntityOptionSetEnum"), "GetMultiEnum", new CodeThisReferenceExpression(), new CodePrimitiveExpression(info.LogicalName), new CodePropertySetValueReferenceExpression()); } else { setExpression = new CodeSnippetExpression( IsNullableIntProperty(prop) ? "(int?)value" : "value.HasValue ? new Microsoft.Xrm.Sdk.OptionSetValue((int)value) : null"); } property.SetStatements.Add( new CodeAssignStatement( new CodeVariableReferenceExpression(prop.Name), setExpression)); } }
private void AddEnumSet(CodeMemberProperty prop, EnumPropertyInfo info, CodeMemberProperty property) { if (!prop.HasSet) { return; } // this.OnPropertyChanging("PropName"); property.SetStatements.Add(new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "OnPropertyChanging", new CodePrimitiveExpression(prop.Name) )); CodeExpression getValueToSetExpression; if (info.IsMultSelect) { //EntityOptionSetEnum.GetMultiEnum(this, info.LogicalName, value) getValueToSetExpression = new CodeMethodInvokeExpression( CreateBaseClasses ? new CodeTypeReferenceExpression(EntityBaseClassGenerator.BaseEntityName) : new CodeTypeReferenceExpression("EntityOptionSetEnum"), "GetMultiEnum", new CodeThisReferenceExpression(), new CodePrimitiveExpression(info.LogicalName), new CodePropertySetValueReferenceExpression()); } else { getValueToSetExpression = new CodeSnippetExpression( IsNullableIntProperty(prop) ? "(int?)value" : "value.HasValue ? new Microsoft.Xrm.Sdk.OptionSetValue((int)value) : null"); } // this.SetAttributeValue("logicalName", getValueExpression); property.SetStatements.Add( new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "SetAttributeValue", new CodePrimitiveExpression(prop.GetLogicalName()), getValueToSetExpression)); // this.OnPropertyChanged("PropName"); property.SetStatements.Add(new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "OnPropertyChanged", new CodePrimitiveExpression(prop.Name) )); }