private string CreateFieldEqCaml(PropertyInfo property, object fieldvalue) { string fieldname = EntityHelper.GetInternalNameFromProperty(property); string fieldTypeName = EntityHelper.GetFieldType(property); return(WrapCamlQuery($"<Eq><FieldRef Name='{fieldname}' /><Value Type='{fieldTypeName}'>{fieldvalue}</Value></Eq>")); }
private string GetFieldCreationXml(PropertyInfo property, Dictionary <string, Guid> lookupTableIds) { Type propertyType = property.PropertyType; string internalName = EntityHelper.GetInternalNameFromProperty(property); string displayName = EntityHelper.GetDisplayNameFromProperty(property); string description = EntityHelper.GetDescriptionFromEntityType(propertyType); bool isRequired = PropertyIsRequired(property); bool isUnique = IsTrue(propertyType.GetCustomAttribute <UniqueAttribute>()?.IsUnique); string fieldTypeName = EntityHelper.GetFieldType(property); bool isMulti = IsMulti(propertyType); if (fieldTypeName == nameof(FieldType.Lookup)) { EntityHelper.RemoveLookupIdFromFieldName(isMulti, ref internalName, ref displayName); } GetFieldCreationAdditionalXmlForFieldType(fieldTypeName, property, lookupTableIds, out string fieldAttributes, out string fieldAdditional); string fieldTypeString = fieldTypeName.ToString(); if (fieldAttributes == null) { fieldAttributes = string.Empty; } if (fieldAttributes == null) { fieldAdditional = string.Empty; } if (isMulti) { if (fieldTypeName == nameof(FieldType.Choice)) { fieldTypeString = "Multi" + fieldTypeString; } else { fieldAttributes += " Mult='TRUE'"; fieldTypeString += "Multi"; } } var indexAttribute = property.GetCustomAttribute <IndexAttribute>(); if (indexAttribute != null) { fieldAttributes += " Indexed='TRUE'"; } string csomCreateCaml = $"<Field Type='{fieldTypeString}' Name='{internalName}' DisplayName='{displayName}' StaticName='{internalName}'"; if (isRequired) { csomCreateCaml += " Required='TRUE'"; } if (isUnique) { csomCreateCaml += " EnforceUniqueValues='TRUE'"; } csomCreateCaml += $" {fieldAttributes}"; if (string.IsNullOrWhiteSpace(fieldAdditional)) { csomCreateCaml += "/>"; } else { csomCreateCaml += ">"; csomCreateCaml += fieldAdditional; csomCreateCaml += "</Field>"; } return(csomCreateCaml); }