Exemplo n.º 1
0
        public static string GetAttributeFormatedValue(object attributeValue, string formatedValue = "")

        {
            switch (attributeValue.ToString())
            {
            case "Microsoft.Xrm.Sdk.EntityReference":



                return(((Microsoft.Xrm.Sdk.EntityReference)attributeValue).LogicalName + "\\" + ((Microsoft.Xrm.Sdk.EntityReference)attributeValue).Id.ToString() + "\\" + ((Microsoft.Xrm.Sdk.EntityReference)attributeValue).Name);



            case "Microsoft.Xrm.Sdk.OptionSetValue":

                return(((Microsoft.Xrm.Sdk.OptionSetValue)attributeValue).Value.ToString() + ((string.IsNullOrEmpty(formatedValue)) ? "" : "\\" + formatedValue));



            case "Microsoft.Xrm.Sdk.Money":

                return(((Microsoft.Xrm.Sdk.Money)attributeValue).Value.ToString());



            case "Microsoft.Xrm.Sdk.AliasedValue":
                return(GetAttributeValue(((Microsoft.Xrm.Sdk.AliasedValue)attributeValue).Value).ToString());

            case "Microsoft.Xrm.Sdk.Label":

                return(LabelFacade.GetLabelString((Microsoft.Xrm.Sdk.Label)attributeValue));

            case "Microsoft.Xrm.Sdk.BooleanManagedProperty":

                return(((Microsoft.Xrm.Sdk.BooleanManagedProperty)attributeValue).Value.ToString() + ((string.IsNullOrEmpty(formatedValue)) ? "" : "\\" + formatedValue));
            }

            Type attributeValueType = attributeValue.GetType();

            if (attributeValueType.IsEnum)

            {
                return($"{ (int)attributeValue}\\{attributeValue}");;
            }


            return(attributeValue.ToString());
        }
Exemplo n.º 2
0
        public static object GetAttributeValue(object attributeValue)
        {
            if (attributeValue.GetType() == typeof(Guid))

            {
                return(attributeValue);
            }

            else if (attributeValue.GetType() == typeof(int))

            {
                return(attributeValue);
            }
            else if (attributeValue.GetType() == typeof(Enum))

            {
                return(attributeValue.ToString());
            }



            switch (attributeValue.ToString())



            {
            case "Microsoft.Xrm.Sdk.EntityReference":



                return(((Microsoft.Xrm.Sdk.EntityReference)attributeValue).Id);



            case "Microsoft.Xrm.Sdk.OptionSetValue":

                return(((Microsoft.Xrm.Sdk.OptionSetValue)attributeValue).Value);



            case "Microsoft.Xrm.Sdk.Money":

                return(((Microsoft.Xrm.Sdk.Money)attributeValue).Value);



            case "Microsoft.Xrm.Sdk.AliasedValue":



                return(GetAttributeValue(((Microsoft.Xrm.Sdk.AliasedValue)attributeValue).Value));



            case "Microsoft.Xrm.Sdk.Label":

                return(LabelFacade.GetLabelString((Microsoft.Xrm.Sdk.Label)attributeValue));

            case "Microsoft.Xrm.Sdk.BooleanManagedProperty":

                return(((Microsoft.Xrm.Sdk.BooleanManagedProperty)attributeValue).Value);
            }
            //  Microsoft.Xrm.Sdk.Metadata.LookupAttributeMetadata



            return(attributeValue.ToString());
        }