本文整理汇总了C#中Jurassic.Library.ObjectInstance.HasProperty方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectInstance.HasProperty方法的具体用法?C# ObjectInstance.HasProperty怎么用?C# ObjectInstance.HasProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jurassic.Library.ObjectInstance
的用法示例。
在下文中一共展示了ObjectInstance.HasProperty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendEmail
public void SendEmail(ObjectInstance email)
{
if (email == null)
throw new ArgumentNullException("email");
foreach (var requiredProperty in new[] { "BodyText", "Subject", "Recipients" })
{
if (email.HasProperty(requiredProperty))
continue;
throw new ArgumentException(string.Format("Property {0} is mandatory", requiredProperty));
}
MailItem newMail = application.CreateItem(OlItemType.olMailItem);
newMail.Body = email.GetPropertyValue("BodyText").ToString();
newMail.Subject = email.GetPropertyValue("Subject").ToString();
var recipients = email.GetPropertyValue("Recipients").ToString().Split(',');
foreach (var rec in recipients.Select(recipient => newMail.Recipients.Add(recipient)))
rec.Resolve();
newMail.Send();
}
示例2: FromObject
// OBJECT SERIALIZATION AND DESERIALIZATION
//_________________________________________________________________________________________
/// <summary>
/// Creates a property descriptor from an object containing any of the following
/// properties: configurable, writable, enumerable, value, get, set.
/// </summary>
/// <param name="obj"> The object to get the property values from. </param>
/// <param name="defaults"> The values to use if the relevant value is not specified. </param>
/// <returns> A PropertyDescriptor that corresponds to the object. </returns>
public static PropertyDescriptor FromObject(ObjectInstance obj, PropertyDescriptor defaults)
{
if (obj == null)
return PropertyDescriptor.Undefined;
// Read configurable attribute.
bool configurable = defaults.IsConfigurable;
if (obj.HasProperty("configurable"))
configurable = TypeConverter.ToBoolean(obj["configurable"]);
// Read writable attribute.
bool writable = defaults.IsWritable;
if (obj.HasProperty("writable"))
writable = TypeConverter.ToBoolean(obj["writable"]);
// Read enumerable attribute.
bool enumerable = defaults.IsEnumerable;
if (obj.HasProperty("enumerable"))
enumerable = TypeConverter.ToBoolean(obj["enumerable"]);
// Read property value.
object value = defaults.Value;
if (obj.HasProperty("value"))
value = obj["value"];
// The descriptor is an accessor if get or set is present.
bool isAccessor = false;
// Read get accessor.
FunctionInstance getter = defaults.Getter;
if (obj.HasProperty("get"))
{
if (obj.HasProperty("value"))
throw new JavaScriptException(obj.Engine, "TypeError", "Property descriptors cannot have both 'get' and 'value' set");
if (obj.HasProperty("writable"))
throw new JavaScriptException(obj.Engine, "TypeError", "Property descriptors with 'get' or 'set' defined must not have 'writable' set");
if (obj["get"] is FunctionInstance)
getter = (FunctionInstance)obj["get"];
else if (TypeUtilities.IsUndefined(obj["get"]) == true)
getter = null;
else
throw new JavaScriptException(obj.Engine, "TypeError", "Property descriptor 'get' must be a function");
isAccessor = true;
}
// Read set accessor.
FunctionInstance setter = defaults.Setter;
if (obj.HasProperty("set"))
{
if (obj.HasProperty("value"))
throw new JavaScriptException(obj.Engine, "TypeError", "Property descriptors cannot have both 'set' and 'value' set");
if (obj.HasProperty("writable"))
throw new JavaScriptException(obj.Engine, "TypeError", "Property descriptors with 'get' or 'set' defined must not have 'writable' set");
if (obj["set"] is FunctionInstance)
setter = (FunctionInstance)obj["set"];
else if (TypeUtilities.IsUndefined(obj["set"]) == true)
setter = null;
else
throw new JavaScriptException(obj.Engine, "TypeError", "Property descriptor 'set' must be a function");
isAccessor = true;
}
// Build up the attributes enum.
PropertyAttributes attributes = PropertyAttributes.Sealed;
if (configurable == true)
attributes |= PropertyAttributes.Configurable;
if (writable == true)
attributes |= PropertyAttributes.Writable;
if (enumerable == true)
attributes |= PropertyAttributes.Enumerable;
// Either a value or an accessor is possible.
object descriptorValue = value;
if (isAccessor == true)
descriptorValue = new PropertyAccessorValue(getter, setter);
// Create the new property descriptor.
return new PropertyDescriptor(descriptorValue, attributes);
}
示例3: GetMailsForFolder
public ArrayInstance GetMailsForFolder(ObjectInstance parameters)
{
if (parameters.HasProperty("UniqueId"))
return GetMailsForFolderInternal(parameters.GetPropertyValue("UniqueId").ToString(), null);
if (parameters.HasProperty("FolderName"))
{
var folderPath = parameters.GetPropertyValue("FolderName").ToString().Split('/');
if (folderPath.Length != 2)
throw new NotSupportedException("At the moment only paths like 'Personal Folders/Foo' are supported");
var root = folderPath.First();
var folderName = folderPath.Last();
var children = GetChildrenFor(root);
foreach (FolderInstance child in children.ElementValues.Cast<FolderInstance>()
.Where(child => child.GetPropertyValue("Name").ToString() == folderName))
return GetMailsForFolderInternal(child.GetPropertyValue("UniqueId").ToString(), null);
return Engine.Array.New();
}
throw new NotSupportedException(string.Format("Requires an object with either 'UniqueId' or 'FolderName' as parameter"));
}