Casting Dynamic variable

Hello Team,
I have declared a property as dynamic data type and if I want to check it with string and if its date then <<[property]:”dd MMM yyyy”>> how can i check == if its string …

@RajKumar1234

Could you please provide more details about the context in which you are using the dynamic variable and the specific programming language you are working with?

public dynamic Property{get; set;}

I am declaring this way in C#

@RajKumar1234 You can try using the following syntax:

SomeClass tmp = new SomeClass();

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln(
    "<<if [Property.GetType().Name == \"DateTime\"]>><<[Property]:\"dd MMM yyyy\">>" +
    "<<else>><<[\"This is not a datetime: \" + Property]>><</if>>");

ReportingEngine engine = new ReportingEngine();
engine.KnownTypes.Add(typeof(Type));
engine.BuildReport(doc, tmp, "ds");

doc.Save(dir + "Dynamic.docx");
public class SomeClass
{
    public SomeClass()
    {
        Property = //"25.05.24";
            new DateTime(2024, 1, 25);
    }

    public dynamic Property { get; set; }
}
1 Like

I want to check in aspose syntax with a string variable…How can i do that for dynamic variable

<<if [Property.GetType().Name == \"DateTime\"]>>

this way using if i want to check whether it matches a string if spo some process

@RajKumar1234 Could you please provide your sample template data and expected output? We will check them on our side and provide you more information.

Sure

public dynamic Property{get; set;}
<<if [Property == “MockData”]>>Not available

<<else>><<[Property]>>

<</if>>

@RajKumar1234 You can use the following syntax:

<<if [data.Property.GetType().Name == “String” && data.Property.ToString() == “MockData”]>>Not available
<<else>><<[data.Property]>>
<</if>>