Click here to Skip to main content
15,915,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After using PropertyInfo of System.Reflection class to set values to the members of an interface that is ReadOnly.

C#
PropertyInfo propertyInfo = siginfo.GetType().GetProperty(
                    "ReadOnly",
                    BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public);
                if (null != propertyInfo)
                {
                    //
                    // Remove the readonly property
                    //
                    propertyInfo.SetValue(siginfo, false, null);

                    this.siginfo.CertificateVerificationResults = CertificateVerificationResults.certverresValid;

                    //
                    // Set the ReadOnly property
                    //
                    propertyInfo.SetValue(siginfo, true, null);
                }


Siginfo is set as ReadOnly, even after using this ReadOnly removal method, it is throwing error as " Property or indexer 'Microsoft.Office.Core.SignatureInfo.CertificateVerificationResults' cannot be assigned to -- it is read only".

Is there any other way to remove the Readonly property.
Posted
Comments
Tomas Takac 20-Oct-15 2:39am    
What are you trying to achieve? This looks very wrong. CertificateVerificationResults is a read-only property = it only has a getter and no setter = you cannot assign its value. This has nothing to do with the ReadOnly property = setting ReadOnly property will not allow you to set CertificateVerificationResults. Moreover ReadOnly is a read-only property in itself so you cannot set its value, <strinke>not even using reflection. (Actually you could set it using reflection if the class implementing the interface has setter implemented.)
Richard MacCutchan 20-Oct-15 3:01am    
No; that is why it is declared ReadOnly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900