Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Unassigned: Property with modifier [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this._name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you
Comments: Hello! The issue with the private setter is indeed a ClearScript bug, and we'll use this report to track it. In the meantime, if you're the developer of `SomeObject`, you can use ClearScript's `ScriptMemberAttribute` to make properties read-only for scripting: ``` C# [ScriptMember(ScriptAccess.ReadOnly)] public string Name { get { return this._name; } private set { this._name = value; } } ``` About the interface issue, here's what you want to do: ``` C# IInterface obj = new SomeObject(); engine.AddRestrictedHostObject("O", obj); ``` Finally, the assembly loading issue you're seeing is probably related to a ClearScript feature that is optional. Are you by any chance exposing assemblies by specifying their short names? Here's how that might look in your code: ``` C# new HostTypeCollection("mscorlib") ``` If you can reproduce this issue, can you break in while it's happening and post a stack? Thanks!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images