本文整理汇总了C#中IBinder.NewBindingItemInstance方法的典型用法代码示例。如果您正苦于以下问题:C# IBinder.NewBindingItemInstance方法的具体用法?C# IBinder.NewBindingItemInstance怎么用?C# IBinder.NewBindingItemInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBinder
的用法示例。
在下文中一共展示了IBinder.NewBindingItemInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateControl
//.........这里部分代码省略.........
}
}
}
}
object defaultValue = null;
if (!string.IsNullOrEmpty(propertyName) && controlPropertyElement.Attributes.ContainsKey("value"))
{
defaultValue = controlPropertyElement.GetAttributeReference("value").Value;
if (null == expression || null == binder)
{
try
{
if (string.IsNullOrEmpty(cellControlName) ||
propertyName != this.KnownTypes[cellControlName].ReadOnlyProperty ||
(propertyName == this.KnownTypes[cellControlName].ReadOnlyProperty && defaultValue != null && !string.IsNullOrEmpty(defaultValue.ToString())))
{
if (propertyName == "Watermark")
{
if (null != defaultValue && !String.IsNullOrEmpty(defaultValue.ToString()))
ReflectionServices.SetValue(cellControl, propertyName, defaultValue);
}
else
ReflectionServices.SetValue(cellControl, propertyName, defaultValue);
}
}
catch (Exception ex)
{
this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("'{0}'.'{1}'='{2}' error", cellControlName, propertyName, controlPropertyElement.GetAttributeReference("value").Value), null, ex, EVENT_TYPE.Error));
}
}
else
{
IBindingItem bindingItem = binder.NewBindingItemInstance();
bindingItem.Source = new Dictionary<string, object>() { { "0", defaultValue} };
bindingItem.SourceProperty = "0";
bindingItem.Target = cellControl;
bindingItem.TargetProperty = propertyName;
bindingItem.Expression = expression;
bindingItem.ExpressionEvaluationResult = expressionResult;
binder.BindingItems.Add(bindingItem);
}
}
if (controlPropertyElement.Attributes.ContainsKey("isList") && (bool)controlPropertyElement.GetAttributeReference("isList").Value)
{
object list = null;
try
{
list = ReflectionServices.ExtractValue(cellControl, propertyName);
if (null == list) throw new InvalidOperationException(string.Format("Member '{0}' is empty", propertyName));
if (!(list is ListItemCollection) && !(list is IDictionary<string, object>)) throw new InvalidOperationException(String.Format("Unsupported list type '{0}'", list.GetType().Name));
}
catch (Exception ex)
{
this._monitor.Register(this, this._monitor.NewEventInstance("failed to retrive the list", null, ex, EVENT_TYPE.Error));
}
if (null != list)
{
if (controlPropertyElement.Attributes.ContainsKey("hasEmpty") && (bool)controlPropertyElement.GetAttributeReference("hasEmpty").Value)
{
if (list is ListItemCollection)
((ListItemCollection)list).Add("");
else if (list is Dictionary<string, object>)
((Dictionary<string, object>)list).Add("", "");
}
示例2: BuildItemTemplate
private Table BuildItemTemplate(IConfigurationSection section, IBinder binder, FormViewMode mode)
{
Table table = new Table();
table.ID = "table";
foreach (IConfigurationElement rowElement in section.Elements.Values)
{
string[] span = null;
if (rowElement.Attributes.ContainsKey("span"))
span = rowElement.GetAttributeReference("span").Value.ToString().Split(new char[] { ',' });
string[] rowspan = null;
if (rowElement.Attributes.ContainsKey("rowspan"))
rowspan = rowElement.GetAttributeReference("rowspan").Value.ToString().Split(new char[] { ',' });
TableRow tr = new TableRow();
tr.ID = "tr" + table.Rows.Count.ToString();
int count = 0;
foreach (IConfigurationElement controlElement in rowElement.Elements.Values)
{
TableCell tc = new TableCell();
tc.ID = tr.ID + "tc" + tr.Cells.Count;
if (span != null && span.Length > count)
{
int columnSpan = 1;
int.TryParse(span[count], out columnSpan);
tc.ColumnSpan = columnSpan;
if (rowspan != null && rowspan.Length > count)
{
int rowSpan = 1;
int.TryParse(rowspan[count], out rowSpan);
tc.RowSpan = rowSpan;
}
count++;
}
string type = null;
if (controlElement.Attributes.ContainsKey("type"))
type = controlElement.GetAttributeReference("type").Value.ToString();
if (!String.IsNullOrEmpty(type))
{
Control cellControl = this.CreateControl(type, mode);
cellControl.ID = tc.ID + controlElement.ConfigKey;
foreach (IConfigurationElement controlPropertyElement in controlElement.Elements.Values)
{
string propertyName = controlPropertyElement.GetAttributeReference("member").Value.ToString();
if (controlPropertyElement.Attributes.ContainsKey("value"))
{
ReflectionServices.SetValue(cellControl, propertyName, controlPropertyElement.GetAttributeReference("value").Value);
}
if (controlPropertyElement.Attributes.ContainsKey("isList") && (bool)controlPropertyElement.GetAttributeReference("isList").Value)
{
ListItemCollection list = ReflectionServices.ExtractValue(cellControl, propertyName) as ListItemCollection;
if (null == list)
{
throw new InvalidOperationException(string.Format("Member '{0}' is not a ListItemCollection", propertyName));
}
if (controlPropertyElement.Attributes.ContainsKey("hasEmpty") && (bool)controlPropertyElement.GetAttributeReference("hasEmpty").Value)
{
if (list is ListItemCollection)
((ListItemCollection)list).Add("");
}
foreach (IConfigurationElement listItemElement in controlPropertyElement.Elements.Values)
{
list.Add(new ListItem(listItemElement.GetAttributeReference("text").Value.ToString(), listItemElement.GetAttributeReference("value").Value.ToString()));
}
}
if (controlPropertyElement.Attributes.ContainsKey("pull"))
{
string pull = controlPropertyElement.GetAttributeReference("pull").Value.ToString();
IBindingItem bindingItem = binder.NewBindingItemInstance();
bindingItem.Source = null;
bindingItem.SourceProperty = pull;
bindingItem.Target = cellControl;
bindingItem.TargetProperty = propertyName;
binder.BindingItems.Add(bindingItem);
if (cellControl is BaseDataBoundControl)
{
this._boundControls.Add(pull, cellControl);
if (!this._dataSources.ContainsKey(pull))
{
this._dataSources.Add(pull, null);
}
}
}
}
tc.Controls.Add(cellControl);
}
tr.Cells.Add(tc);
}
table.Rows.Add(tr);
}
return table;
}
示例3: BuildCommand
private SqlCommand BuildCommand(IConfigurationElement commandElement, IBinder binder, WebPartManager manager)
{
SqlCommand command = new SqlCommand();
foreach (IConfigurationElementAttribute attribute in commandElement.Attributes.Values)
{
ReflectionServices.SetValue(command, attribute.ConfigKey, attribute.Value);
}
IBindingItemsCollection bindingParams = binder.NewBindingItemCollectionInstance();
binder.BindingSet.Add(commandElement.ConfigKey, bindingParams);
foreach (IConfigurationElement parameterElement in commandElement.Elements.Values)
{
SqlParameter parameter = new SqlParameter();
foreach (IConfigurationElementAttribute parameterAttribute in parameterElement.Attributes.Values)
{
if ("bind" == parameterAttribute.ConfigKey)
{
string bindstring = parameterAttribute.Value.ToString();
bool isOutput = parameterElement.Attributes.ContainsKey("Direction") &&
("Output" == parameterElement.GetAttributeReference("Direction").Value.ToString() ||
"InputOutput" == parameterElement.GetAttributeReference("Direction").Value.ToString());
if (bindstring.Contains("."))
{
string sourcestring = bindstring.Substring(0, bindstring.IndexOf("."));
IBindingItem bindingItem = binder.NewBindingItemInstance();
if (!isOutput)
{
bindingItem.Source = manager.FindControl(sourcestring);
bindingItem.SourceProperty = bindstring.Substring(sourcestring.Length + 1);
bindingItem.Target = parameter;
bindingItem.TargetProperty = "Value";
}
else
{
bindingItem.Target = manager.FindControl(sourcestring);
bindingItem.TargetProperty = bindstring.Substring(sourcestring.Length + 1);
bindingItem.Source = parameter;
bindingItem.SourceProperty = "Value";
}
bindingParams.Add(bindingItem);
}
}
else
{
ReflectionServices.SetValue(parameter, parameterAttribute.ConfigKey, parameterAttribute.Value);
}
}
if (null == parameter.Value)
{
parameter.Value = DBNull.Value;
}
command.Parameters.Add(parameter);
}
return command;
}